当前位置:   article > 正文

黄金矿工java实现_java黄金矿工设计报告

java黄金矿工设计报告

项目价值:

1.可以熟悉下java的可视化界面编程,整个项目并没有使用封装、多台的相关知识,继承性和重写用到了。

2.整个项目只用到了JavaSE的基础知识,更多的是对JFrame类中pain方法的重写。

3.我对着视频手敲一遍用了6个小时左右,视频在的部分章节存在问题,我在评论区留言了,没有时间的不建议,对于学习Java意义不大,但是可能会增加学习Java的兴趣。


项目用到的图片

imags文件下的图片


项目代码:

背景类BackGroundImgs:

  1. package GoldMiner.com.ALi;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.Toolkit;
  7. /**
  8. * @author :ALi
  9. * @date :Created in 2021/10/31 9:36
  10. * @description:背景图片加载类
  11. * @modified By:
  12. * @version: $
  13. */
  14. public class BackGroundImgs {
  15. /**
  16. * 获取图片
  17. * @param backGround为加载的背景图片
  18. */
  19. private Image backGround = Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
  20. private Image backGround_sky = Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
  21. private Image backGround_person = Toolkit.getDefaultToolkit().getImage("imgs/peo.png");
  22. private Image backGround_water = Toolkit.getDefaultToolkit().getImage("imgs/water.png");
  23. //总分
  24. protected static int count = 0;
  25. //药水数量:初始值为3
  26. protected static int WaterNamber = 3;
  27. //药水状态 false为未使用
  28. protected static boolean WaterFlag = false;
  29. //关卡数
  30. protected static int level = 1;
  31. //关卡目标得分
  32. protected static int goal = level*15;
  33. //开始时间
  34. protected static long startTime;
  35. //关闭时间
  36. protected static long endTime;
  37. //药水价格
  38. protected int price = (int)(Math.random()*10);
  39. //是否进入商店
  40. protected boolean shop = false;
  41. /**
  42. * 将图片画在窗口上
  43. * @param graphics 画笔
  44. */
  45. void painImgs(Graphics graphics){
  46. //绘制背景图片(人,天空,地下)
  47. graphics.drawImage(backGround,0,200,null);
  48. graphics.drawImage(backGround_sky,0,0,null);
  49. switch (GameWin.state){
  50. case 0:
  51. drawWord(graphics,70,"右键进入游戏",170,400,Color.BLACK);
  52. break;
  53. case 1:
  54. graphics.drawImage(backGround_person,310,50,null);
  55. //药水
  56. graphics.drawImage(backGround_water,450,40,null);
  57. drawWord(graphics,30,"*"+WaterNamber,510,70,Color.BLACK);
  58. drawWord(graphics,30,"积分:"+count,30,150,Color.BLACK);
  59. //绘制关卡数
  60. drawWord(graphics,20,"第:"+level+" 关",30,60,Color.BLACK);
  61. //显示积分
  62. drawWord(graphics,30,"目标:"+goal,30,110,Color.BLACK);
  63. //实时赋值
  64. endTime = System.currentTimeMillis();
  65. long tim = 20 - (endTime - startTime)/1000;
  66. drawWord(graphics,30,"时间:"+(tim>0?tim:0),520,150,Color.BLACK);
  67. break;
  68. case 2:
  69. graphics.drawImage(backGround_water,300,400,null);
  70. //显示积分
  71. drawWord(graphics,30,"价格:"+price,300,500,Color.BLACK);
  72. drawWord(graphics,30,"是否购买:",300,550,Color.BLACK);
  73. if(shop){
  74. count = count - price;
  75. WaterNamber++;
  76. shop = false;
  77. GameWin.state = 1;
  78. startTime = System.currentTimeMillis();
  79. }
  80. break;
  81. case 3:
  82. drawWord(graphics,80,"失败",250,350,Color.red);
  83. drawWord(graphics,80,"积分:"+count,200,450,Color.red);
  84. break;
  85. case 4:
  86. drawWord(graphics,80,"成功",250,350,Color.green);
  87. drawWord(graphics,80,"积分:"+count,200,450,Color.green);
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/127502
推荐阅读
相关标签
  

闽ICP备14008679号