赞
踩
1.可以熟悉下java的可视化界面编程,整个项目并没有使用封装、多台的相关知识,继承性和重写用到了。
2.整个项目只用到了JavaSE的基础知识,更多的是对JFrame类中pain方法的重写。
3.我对着视频手敲一遍用了6个小时左右,视频在的部分章节存在问题,我在评论区留言了,没有时间的不建议,对于学习Java意义不大,但是可能会增加学习Java的兴趣。
- package GoldMiner.com.ALi;
-
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Toolkit;
-
- /**
- * @author :ALi
- * @date :Created in 2021/10/31 9:36
- * @description:背景图片加载类
- * @modified By:
- * @version: $
- */
- public class BackGroundImgs {
- /**
- * 获取图片
- * @param backGround为加载的背景图片
- */
- private Image backGround = Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
- private Image backGround_sky = Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
- private Image backGround_person = Toolkit.getDefaultToolkit().getImage("imgs/peo.png");
- private Image backGround_water = Toolkit.getDefaultToolkit().getImage("imgs/water.png");
- //总分
- protected static int count = 0;
- //药水数量:初始值为3
- protected static int WaterNamber = 3;
- //药水状态 false为未使用
- protected static boolean WaterFlag = false;
- //关卡数
- protected static int level = 1;
- //关卡目标得分
- protected static int goal = level*15;
- //开始时间
- protected static long startTime;
- //关闭时间
- protected static long endTime;
- //药水价格
- protected int price = (int)(Math.random()*10);
- //是否进入商店
- protected boolean shop = false;
- /**
- * 将图片画在窗口上
- * @param graphics 画笔
- */
- void painImgs(Graphics graphics){
-
- //绘制背景图片(人,天空,地下)
- graphics.drawImage(backGround,0,200,null);
- graphics.drawImage(backGround_sky,0,0,null);
- switch (GameWin.state){
- case 0:
- drawWord(graphics,70,"右键进入游戏",170,400,Color.BLACK);
- break;
- case 1:
- graphics.drawImage(backGround_person,310,50,null);
- //药水
- graphics.drawImage(backGround_water,450,40,null);
- drawWord(graphics,30,"*"+WaterNamber,510,70,Color.BLACK);
-
- drawWord(graphics,30,"积分:"+count,30,150,Color.BLACK);
-
- //绘制关卡数
- drawWord(graphics,20,"第:"+level+" 关",30,60,Color.BLACK);
- //显示积分
- drawWord(graphics,30,"目标:"+goal,30,110,Color.BLACK);
- //实时赋值
- endTime = System.currentTimeMillis();
- long tim = 20 - (endTime - startTime)/1000;
- drawWord(graphics,30,"时间:"+(tim>0?tim:0),520,150,Color.BLACK);
-
- break;
- case 2:
- graphics.drawImage(backGround_water,300,400,null);
- //显示积分
- drawWord(graphics,30,"价格:"+price,300,500,Color.BLACK);
- drawWord(graphics,30,"是否购买:",300,550,Color.BLACK);
- if(shop){
- count = count - price;
- WaterNamber++;
- shop = false;
- GameWin.state = 1;
- startTime = System.currentTimeMillis();
- }
- break;
- case 3:
- drawWord(graphics,80,"失败",250,350,Color.red);
- drawWord(graphics,80,"积分:"+count,200,450,Color.red);
- break;
- case 4:
- drawWord(graphics,80,"成功",250,350,Color.green);
- drawWord(graphics,80,"积分:"+count,200,450,Color.green);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。