一个简单的JAVA做的小游戏
答案:2 悬赏:70 手机版
解决时间 2021-04-02 21:50
- 提问者网友:流星是天使的眼泪
- 2021-04-02 14:24
一个简单的JAVA做的小游戏
最佳答案
- 五星知识达人网友:猎心人
- 2021-04-02 15:45
我也不知道你要什么样的游戏
我随便贴了一个
第一个Java文件:
import java.util.Scanner;
public class GameA_B {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int area;
System.out.println("Game Start…………Please enter the area:(1-9)" +
'\n'+"1,2,3 means easy"+'\n'+"4,5,6 means middle"+'\n'+
"7,8,9 means hard"+'\n'+"Please choose:");
area=reader.nextInt();
switch((area-1)/3)
{
case 0:System.out.println("You choose easy! ");break;
case 1:System.out.println("You choose middle! ");break;
case 2:System.out.println("You choose hard! ");break;
}
System.out.println("Good Luck!");
GameProcess game1=new GameProcess(area);
game1.process();
}
}
第二个Java文件:
import java.util.Random;
import java.util.Scanner;
public class GameProcess {
int area,i,arrcount,right,midright,t;
int base[]=new int[arrcount],userNum[]=new int[area],sysNum[]=new int[area];
Random random=new Random();
Scanner reader=new Scanner(System.in);
GameProcess(int a)
{
area=a;
arrcount=10;
right=0;
midright=0;
t=0;
base=new int[arrcount];
userNum=new int[area];
sysNum=new int[area];
for(int i=0;i {
base[i]=i;
//System.out.println(base[i]);
}
}
void process()
{
rand();
while(right!=area)
{
scanf();
compare();
print();
check();
}
}
void rand()
{
for(i=0;i {
t=random.nextInt(arrcount);
//System.out.println(t);
sysNum[i]=base[t];
System.out.println(base[t]);
delarr(t);
}
}
void delarr(int t)
{
for(int j=t;j base[j]=base[j+1];
arrcount--;
}
void scanf()
{
System.out.println("The system number has created!"+"\n"+"Please enter "+area+" Numbers");
for(int i=0;i {
userNum[i]=reader.nextShort();
}
}
void check()
{
if(right==area)
System.out.println("You win…………!");
}
boolean check(int i)
{
return true;
}
void compare()
{
int i=0,j=0;
right=midright=0;
for(i=0;i {
for(j=0;j {
if(userNum[i]==sysNum[j])
{
if(i==j)
right++;
else
midright++;
}
}
}
}
void print()
{
System.out.println(" A "+right+" B "+midright);
}
}
希望能帮到你
忘采纳
我随便贴了一个
第一个Java文件:
import java.util.Scanner;
public class GameA_B {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int area;
System.out.println("Game Start…………Please enter the area:(1-9)" +
'\n'+"1,2,3 means easy"+'\n'+"4,5,6 means middle"+'\n'+
"7,8,9 means hard"+'\n'+"Please choose:");
area=reader.nextInt();
switch((area-1)/3)
{
case 0:System.out.println("You choose easy! ");break;
case 1:System.out.println("You choose middle! ");break;
case 2:System.out.println("You choose hard! ");break;
}
System.out.println("Good Luck!");
GameProcess game1=new GameProcess(area);
game1.process();
}
}
第二个Java文件:
import java.util.Random;
import java.util.Scanner;
public class GameProcess {
int area,i,arrcount,right,midright,t;
int base[]=new int[arrcount],userNum[]=new int[area],sysNum[]=new int[area];
Random random=new Random();
Scanner reader=new Scanner(System.in);
GameProcess(int a)
{
area=a;
arrcount=10;
right=0;
midright=0;
t=0;
base=new int[arrcount];
userNum=new int[area];
sysNum=new int[area];
for(int i=0;i {
base[i]=i;
//System.out.println(base[i]);
}
}
void process()
{
rand();
while(right!=area)
{
scanf();
compare();
print();
check();
}
}
void rand()
{
for(i=0;i {
t=random.nextInt(arrcount);
//System.out.println(t);
sysNum[i]=base[t];
System.out.println(base[t]);
delarr(t);
}
}
void delarr(int t)
{
for(int j=t;j base[j]=base[j+1];
arrcount--;
}
void scanf()
{
System.out.println("The system number has created!"+"\n"+"Please enter "+area+" Numbers");
for(int i=0;i {
userNum[i]=reader.nextShort();
}
}
void check()
{
if(right==area)
System.out.println("You win…………!");
}
boolean check(int i)
{
return true;
}
void compare()
{
int i=0,j=0;
right=midright=0;
for(i=0;i {
for(j=0;j {
if(userNum[i]==sysNum[j])
{
if(i==j)
right++;
else
midright++;
}
}
}
}
void print()
{
System.out.println(" A "+right+" B "+midright);
}
}
希望能帮到你
忘采纳
全部回答
- 1楼网友:笑迎怀羞
- 2021-04-02 16:20
1
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯