Java黄金矿工 21.计时效果
package com.sxt;
import java.awt.*;
public class Bg { //构造背景类
//设置积分
static int count=0;
//定义关卡数
static int level=1;
//定义目标得分
int goal=level*5;
//定义药水状态
static boolean waterFlag=false;
//定义开始时间和结束时间
long stareTime;
long endTime;
//定义药水数量
static int waterNum=3;
Image bg=Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg"); //存入图片进bg
Image bg1=Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg"); //存入图片进bg1
Image peo=Toolkit.getDefaultToolkit().getImage("imgs/peo.png"); //存入图片进peo
//添加药水
Image water=Toolkit.getDefaultToolkit().getImage("imgs/water.png");
void panintSelf(Graphics g) //构造paintSelf方法来实现图片的显示,Graphics是画笔,
{
g.drawImage(bg,0,200,null); //绘画出bg
g.drawImage(bg1,0,0,null); //绘画出bg1
if (GameWin.state==1)
{
switch (GameWin.state)
{
case 0:
drawWord(g,80,Color.black,"准备开始",100,100);
break;
case 1:
g.drawImage(peo,310,50,null); //绘画出peo
//绘制药水图片
g.drawImage(water,450,40,null);
//打印积分
drawWord(g,30,Color.black,"积分"+count,30,150);
drawWord(g,30,Color.black,"*"+waterNum,510,70);
//绘制关卡数和目标得分
drawWord(g,30,Color.black,"第"+level+"关",30,60);
drawWord(g,30,Color.black,"目标得分",30,110);
//设置结束时间
endTime=System.currentTimeMillis();
//计算时间
long tim=20-(endTime-stareTime)/1000;
drawWord(g,30,Color.black,"倒计时"+(tim>0?tim:0),520,150);
break;
case 2:break;
case 3:break;
case 4:break;
default:
}
}
}
//创建打印字符串的方法
public static void drawWord(Graphics g,int size,Color color,String str,int x,int y)
{
g.setColor(Color.BLACK);
g.setFont(new Font("仿宋",Font.BOLD,30));
g.drawString(str,x,y);
}
}
package com.sxt;
import javax.swing.*; //导出Jframe类的方法,在继承Jframe类时会自己生成。
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
public class GameWin extends Jframe //创建GameWin类继承Jframe类,Jframe类本身包含鼠标事件,可以实现点击鼠标按键来不同 *** 作。
{
//定义游戏状态 0未开始 1运行中 2商店 3失败 4胜利
static int state;
//创建数组来存储金块
List
评论列表(0条)