📄 game.java
字号:
import java.util.Random;
public class Game{
int i;
boolean b;
String[] card=new String[52];
public Game(){
Card c = new Card();
int q=0,w=0,e=0;
while(q<=51){
card[q]=(char)c.type[w]+c.number[e];
w=e<12?w:w+1;
e=e>11?0:e+1;
q++;
}
play();
}
public boolean play(){
System.out.print("Game is created\n");
System.out.print("Game is starting\n");
boolean duplicate = false;
String tmp,tmp1;
do{
duplicate = false;
tmp=card[(int)(Math.random()*52)];
tmp1=card[(int)(Math.random()*52)];
if(tmp==tmp1)
duplicate = true;
}while(duplicate);
System.out.printf("The Computer is: %s\n",tmp);
System.out.printf("The player is: %s\n",tmp1);
char Csuit = tmp.charAt(0);
char Cnum = tmp.charAt(1);
char Psuit = tmp1.charAt(0);
char Pnum = tmp1.charAt(1);
if((int)Cnum==(int)Pnum||Csuit==Psuit){
b=true;
System.out.println("You win!!\n");}
else{
b=false;
System.out.println("You Lose!!\n");}
return b;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -