java实现快速打字游戏

这篇文章主要为大家详细介绍了java实现快速打字游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了java实现打字游戏的具体代码,供大家参考,具体内容如下

import java.util.Random; import java.util.Scanner; public class Game { public Game(Player player) { } public Game() { } public String printStr(Player player) { StringBuffer a=new StringBuffer(); for(int i=0;i"); break; case 2: a.append("LevelParam.levels[player.getLevelNo()-1].getTimeLimit()) { System.out.println("你输入太慢了,输入超时,退出。"); System.exit(1); } else { player.setCurscore(player); System.out.println("输入正确,您的级别"+player.getLevelNo()+",您的积分"+player.getCurscore()+",已用时"+player.getelapsedtime()+"秒。"); } }else{ System.out.println("输入错误退出!"); System.exit(1); } } } public class Level { private int levelNo;//各级别编号 private int strLength;//各级别一次输出字符串的长度 private int strTimes;//各级别输出字符串的次数 private int timeLimit;//各级别闯关的时间限制 private int perscore;//各级别正确输入一次的得分 public int getLevelNo() { return levelNo; } public int getStrLength() { return strLength; } public int getStrTimes() { return strTimes; } public int getTimeLimit() { return timeLimit; } public int getPerscore() { return perscore; } public Level(int levelNo,int strLength,int strTimes,int timeLimit,int perscore) { this.levelNo=levelNo; this.strLength=strLength; this.strTimes=strTimes; this.timeLimit=timeLimit; this.perscore=perscore; } } public class LevelParam { public static final Level levels[]=new Level[6]; static{ levels[0]=new Level(1,2,10,30,1);//编号、字符串长度、字符串次数、关卡时间、正确得分 levels[1]=new Level(2,3,9,26,2); levels[2]=new Level(3,4,8,22,5); levels[3]=new Level(4,5,7,18,8); levels[4]=new Level(5,6,6,15,10); levels[5]=new Level(6,7,5,12,15); } }

import java.util.Scanner; public class Player { private int levelNo=1;//玩家当前级别 private int curscore;//当前级别积分 private long startTime;//当前级别开始时间 private long elapsedtime;//当前级别已用时间 public int getLevelNo() { return levelNo; } public void setLevelNo() { this.levelNo++; } public int getCurscore() { return curscore; } public void setCurscore(Player player) { this.curscore = curscore+LevelParam.levels[player.getLevelNo()-1].getPerscore();; } public void setCurscore(int a) { this.curscore=a; } public long getStartTime() { return startTime; } public void setStartTime() { this.startTime =System.currentTimeMillis();; } public long getelapsedtime() { return elapsedtime; } public void setelapsedtime(long a,long b) { this.elapsedtime=(a-b)/1000+elapsedtime; } public void setelapsedtime(int a) { this.elapsedtime=a; } public void play(Player player) { Game one=new Game(); for(int j=0;j

更多有趣的经典小游戏实现专题,分享给大家:

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

JavaScript经典游戏 玩不停

java经典小游戏汇总

javascript经典小游戏汇总

相关文章

HashMap是Java中最常用的集合类框架,也是Java语言中非常典型...
在EffectiveJava中的第 36条中建议 用 EnumSet 替代位字段,...
介绍 注解是JDK1.5版本开始引入的一个特性,用于对代码进行说...
介绍 LinkedList同时实现了List接口和Deque接口,也就是说它...
介绍 TreeSet和TreeMap在Java里有着相同的实现,前者仅仅是对...
HashMap为什么线程不安全 put的不安全 由于多线程对HashMap进...