java实现快速打字游戏

网友投稿 273 2022-12-02


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

int num=(int)(Math.random()*(7));

switch(num) {

case 1:

a.append(">");

break;

case 2:

a.append("<");

break;

case 3:

a.append("+");

break;

case 4:

a.append("-");

break;

case 5:

a.append("*");

break;

case 6:

a.append("/");

break;

case 0:

a.append("=");

break;

}

}

String str=a.toString();

System.out.println(str);

return str;

}

public void printResult(Player player) {

String num1=this.printStr(player);

Scanner input=new Scanner(System.in);

player.setStartTime();

String num2=input.next();

long currentTime=System.currentTimeMillis();

player.setElapsedTime(currentTime,player.getStartTime());

if (num1.equals(num2)) {

if ((currentTime-player.getStartTime())/1000>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<6;j++) {

for(int i=0;i

one.printResult(player);

}

player.setLevelNo();

player.setCurScore(0);

player.setElapsedTime(0);

}

}

}

public class Test {

public static void main(String[] args) {

Player p=new Player();

p.plahttp://y(p);

}

}

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

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

java经典小游戏汇总

javascript经典小游戏汇总

int num=(int)(Math.random()*(7));

switch(num) {

case 1:

a.append(">");

break;

case 2:

a.append("<");

break;

case 3:

a.append("+");

break;

case 4:

a.append("-");

break;

case 5:

a.append("*");

break;

case 6:

a.append("/");

break;

case 0:

a.append("=");

break;

}

}

String str=a.toString();

System.out.println(str);

return str;

}

public void printResult(Player player) {

String num1=this.printStr(player);

Scanner input=new Scanner(System.in);

player.setStartTime();

String num2=input.next();

long currentTime=System.currentTimeMillis();

player.setElapsedTime(currentTime,player.getStartTime());

if (num1.equals(num2)) {

if ((currentTime-player.getStartTime())/1000>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<6;j++) {

for(int i=0;i

one.printResult(player);

}

player.setLevelNo();

player.setCurScore(0);

player.setElapsedTime(0);

}

}

}

public class Test {

public static void main(String[] args) {

Player p=new Player();

p.plahttp://y(p);

}

}

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

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

java经典小游戏汇总

javascript经典小游戏汇总

one.printResult(player);

}

player.setLevelNo();

player.setCurScore(0);

player.setElapsedTime(0);

}

}

}

public class Test {

public static void main(String[] args) {

Player p=new Player();

p.plahttp://y(p);

}

}

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

C++经典小游戏汇总

python经典小游戏汇总

python俄罗斯方块游戏集合

javascript经典游戏 玩不停

java经典小游戏汇总

javascript经典小游戏汇总


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:java实现幸运抽奖系统
下一篇:Java实现快速并查集
相关文章

 发表评论

暂时没有评论,来抢沙发吧~