午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

java實現快速打字游戲

瀏覽:24日期:2022-08-29 17:14:19

本文實例為大家分享了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<LevelParam.levels[player.getLevelNo()-1].getStrLength();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<LevelParam.levels[player.getLevelNo()-1].getStrTimes();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.play(p); }}

更多有趣的經典小游戲實現專題,分享給大家:

C++經典小游戲匯總

python經典小游戲匯總

python俄羅斯方塊游戲集合

JavaScript經典游戲 玩不停

java經典小游戲匯總

javascript經典小游戲匯總

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 91香蕉国产在线观看软件 | 91亚洲国产成人精品性色 | 天天摸天天操天天干 | 午夜国产 | 私人毛片 | 久久97视频 | 99精品色 | 爱色成人网 | 久久99精品久久久 | av首页在线 | 成人3d动漫一区二区三区91 | 伊人春色视频 | 亚洲成熟少妇视频在线观看 | 亚洲天堂网站 | 欧美刺激脚交jootjob | 国产精品精品久久久久久 | 欧美精品另类 | 日日摸日日添日日躁av | 午夜一级大片 | 黄色在线免费观看网站 | 黄色片免费视频 | 蜜桃传媒av| 欧美男人的天堂 | 一区二区三区久久 | 久久久精品久久久久 | 亚洲最大成人在线 | 久久久久久久成人 | 波多野结衣一区二区三区高清 | 日韩一区二区视频在线观看 | 精品久久久中文字幕 | 奇米色888| 亚洲专区第一页 | 国产成人在线精品 | 久久理论片 | 久久激情五月 | 亚洲欧美视频在线观看 | 国外精品网站 | 伊人免费视频 | 91成人在线观看喷潮蘑菇 | 成人国产精品久久 | 欧美,日韩,国产精品免费观看 |