谁能写一个java打字游戏 超级简单的源码
随机出现很多字母然后就打还要算速度的(多少个字母一分钟)打完后还会问要不要再来一次下面我局个例子(1)playanotherround(问要不要再来一次)(2)exitt...
随机出现很多字母 然后就打
还要算速度的(多少个字母一分钟)
打完后还会问要不要再来一次
下面我局个例子
(1) play another round(问要不要再来一次)
(2) exit the game(退出)
Selection: p(选择要 1 还是 2)
Text to Match: jomtqaaqnvnbyjzolihfifohfnpykr(随机出来的字母)
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj(我打的字母)
INCORRECTLY TYPED, YOU GET A SPEED OF 0!(速度)
PS 不想要字母从天而降 谢谢 展开
还要算速度的(多少个字母一分钟)
打完后还会问要不要再来一次
下面我局个例子
(1) play another round(问要不要再来一次)
(2) exit the game(退出)
Selection: p(选择要 1 还是 2)
Text to Match: jomtqaaqnvnbyjzolihfifohfnpykr(随机出来的字母)
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj(我打的字母)
INCORRECTLY TYPED, YOU GET A SPEED OF 0!(速度)
PS 不想要字母从天而降 谢谢 展开
1个回答
展开全部
编好了,你自己运行下:
import java.util.Random;
import java.util.Scanner;
public class Test
{
public static Random r = new Random();
public static void printMenu()
{
System.out.println("(1) play another round");
System.out.println("(2) exit the game");
System.out.print("Selection:");
}
public static void main(String[] args) throws Exception
{
String content = null;
Scanner scan = new Scanner(System.in);
while(true)
{
printMenu();
content = scan.nextLine();
System.out.println();
//输入内容是2,则退出程序
if(content.equals("2")) break;
if(content.equals("1"))
{
System.out.print("Text to Match: ");
int count = r.nextInt(50) + 1;
char[] letters = new char[count];
for(int i=0;i<count;i++)
{
letters[i] = (char)(r.nextInt(26) + 97);
System.out.print(letters[i]);
}
System.out.print("\n ");
long startTime = System.currentTimeMillis();
int correctCount = 0;
content = scan.nextLine();
for(int i=0;i<count;i++)
{
if(content.charAt(i) == letters[i])
correctCount++;
}
long endTime = System.currentTimeMillis();
int time = (int)((endTime - startTime) / 1000);
if(correctCount == 0)
System.out.println("INCORRECTLY TYPED, YOU GET A SPEED OF 0!");
else
{
System.out.println("共花了" + time + "秒,正确率为:" + ((int)(((double)correctCount/count))*100) + "%");
}
}
System.out.println();
}
}
}
import java.util.Random;
import java.util.Scanner;
public class Test
{
public static Random r = new Random();
public static void printMenu()
{
System.out.println("(1) play another round");
System.out.println("(2) exit the game");
System.out.print("Selection:");
}
public static void main(String[] args) throws Exception
{
String content = null;
Scanner scan = new Scanner(System.in);
while(true)
{
printMenu();
content = scan.nextLine();
System.out.println();
//输入内容是2,则退出程序
if(content.equals("2")) break;
if(content.equals("1"))
{
System.out.print("Text to Match: ");
int count = r.nextInt(50) + 1;
char[] letters = new char[count];
for(int i=0;i<count;i++)
{
letters[i] = (char)(r.nextInt(26) + 97);
System.out.print(letters[i]);
}
System.out.print("\n ");
long startTime = System.currentTimeMillis();
int correctCount = 0;
content = scan.nextLine();
for(int i=0;i<count;i++)
{
if(content.charAt(i) == letters[i])
correctCount++;
}
long endTime = System.currentTimeMillis();
int time = (int)((endTime - startTime) / 1000);
if(correctCount == 0)
System.out.println("INCORRECTLY TYPED, YOU GET A SPEED OF 0!");
else
{
System.out.println("共花了" + time + "秒,正确率为:" + ((int)(((double)correctCount/count))*100) + "%");
}
}
System.out.println();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询