《JAVA打字游戏源码.pdf》由会员分享,可在线阅读,更多相关《JAVA打字游戏源码.pdf(7页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、package com.xt.game.entrty;import java.util.Random;public class Game Player player;public Game(Player player)this.player=player;/*输出字符*param strLength*return*/public String printStr()int strLength=player.getLevelNo();Level level=LevelParam.levelsstrLength-1;StringBuffer buffer=new StringBuffer();Ran
2、dom random=new Random();for(int i=0;i LevelParam.levelsplayer.getLevelNo()-1.getTimeLimit()System.out.println(游戏超时,闯关失败!);System.exit(1);else player.setCurScore(player.getCurScore()+LevelParam.levelsplayer.getLevelNo()-1.getPerScore();System.out.println(输入正确,您的积分是+player.getCurScore()+分,您的级别是+player
3、.getLevelNo()+级,您所用时间+(currentTime-player.getStartTime()/1000+秒);if(player.getLevelNo()=6)int score=LevelParam.levelsplayer.getLevelNo()-1.getPerScore()*LevelParam.levelsplayer.getLevelNo()-1.getStrTimes();/计算闯关分数if(player.getCurScore()=score)System.out.println(闯关成功!);System.exit(0);else System.out.
4、println(输入错误,闯关失败!);System.exit(1);package com.xt.game.entrty;public class Level private int levelno;private int strLength;private int strTimes;private int timeLimit;private int perScore;public int getLevelno()return levelno;public void setLevelno(int levelno)this.levelno=levelno;public int getStrLe
5、ngth()return strLength;public void setStrLength(int strLength)this.strLength=strLength;public int getStrTimes()return strTimes;public void setStrTimes(int strTimes)this.strTimes=strTimes;public int getTimeLimit()return timeLimit;public void setTimeLimit(int timeLimit)this.timeLimit=timeLimit;public
6、int getPerScore()return perScore;public void setPerScore(int perScore)this.perScore=perScore;/*Level 构造方法*param levelno*param strLength*param strTimes*param timeLimit*param perScore*/public Level(int levelno,int strLength,int strTimes,int timeLimit,int perScore)super();this.levelno=levelno;this.strL
7、ength=strLength;this.strTimes=strTimes;this.timeLimit=timeLimit;this.perScore=perScore;package com.xt.game.entrty;/*数组*author Administrator*/public class LevelParam public final static Level levels=new Level9;static levels0=new Level(1,2,10,30,1);levels1=new Level(2,3,9,28,2);levels2=new Level(3,4,8
8、,26,5);levels3=new Level(4,5,7,24,8);levels4=new Level(5,6,6,22,10);levels5=new Level(6,7,5,20,15);levels6=new Level(7,8,4,18,20);levels7=new Level(8,9,3,16,25);levels8=new Level(9,10,2,14,30);package com.xt.game.entrty;import java.util.*;public class Player private int levelNo;private int curScore;
9、private long startTime;private int elapsedTime;public int getLevelNo()return levelNo;public void setLevelNo(int levelNo)this.levelNo=levelNo;public int getCurScore()return curScore;public void setCurScore(int curScore)this.curScore=curScore;public long getStartTime()return startTime;public void setS
10、tartTime(long startTime)this.startTime=startTime;public int getElapsedTime()return elapsedTime;public void setElapsedTime(int elapsedTime)this.elapsedTime=elapsedTime;/*游戏*/public void play()Scanner input=new Scanner(System.in);Game game=new Game(this);System.out.println(t 九九数字打字速度测试);for(int i=0;i
11、LevelParam.levels.length;i+)System.out.println(t-);System.out.println(t|t第+(i+1)+关t|);System.out.println(t-);this.setLevelNo(getLevelNo()+1);this.setStartTime(System.currentTimeMillis();this.setCurScore(0);for(int j=0;j LevelParam.levelslevelNo-1.getStrTimes();j+)String out=game.printStr();System.out.println(out);String in=input.next();game.printResult(out,in);package com.xt.game.test;import com.xt.game.entrty.*;public class Test /*param args*/public static void main(String args)Player player=new Player();player.play();