public class Game {
static int abc=0;
private player Wanjia=new player();
private Computer com1=new Computer();
private Computer com2=new Computer();
static helper Gamehelper=new helper();
public void setupGame(){
Wanjia.StickOrGiveUp=true;
Wanjia.truepoints=Gamehelper.givecard(Wanjia.StickOrGiveUp);
Wanjia.totalpoints=0;
System.out.println("your first card is "+Wanjia.truepoints);
com1.GetOrFall=true;
com1.Truetotal=Gamehelper.givecard(com1.GetOrFall);
com1.Total=0;
com2.GetOrFall=true;
com2.Truetotal=Gamehelper.givecard(com2.GetOrFall);
com2.Total=0;
}
public void playingGame(){
String PlayerInput=new String();
while(Wanjia.StickOrGiveUp==true||com1.GetOrFall==true||com2.GetOrFall==true){
if(Wanjia.StickOrGiveUp==true){
PlayerInput=Gamehelper.getUserInput("Yes or No to get next card?Please put in yes or no");
System.out.println(PlayerInput);
if(PlayerInput.equals( "yes")==true){
Wanjia.StickOrGiveUp=true;
}
if(PlayerInput.equals("no")){
Wanjia.StickOrGiveUp=false;
}
abc=Gamehelper.givecard(Wanjia.StickOrGiveUp);
System.out.println("the player's next card is "+ abc);
Wanjia.truepoints=Wanjia.truepoints+abc;
Wanjia.totalpoints=Wanjia.totalpoints+abc;
System.out.println("player's total points is "+Wanjia.totalpoints);
System.out.println("player's true points is "+Wanjia.truepoints);
Wanjia.StickOrGiveUp=Gamehelper.bomp(Wanjia.truepoints);
if(PlayerInput.equals("no")){
Wanjia.StickOrGiveUp=false;
}
//获得玩家的输入以及得到玩家的点数
}
if(com1.GetOrFall==true){
com1.GetOrFall=com1.winORlose(com1.Truetotal,Wanjia.totalpoints,Wanjia.truepoints);
if(com1.GetOrFall==true){
System.out.println("the comuter1 chooses to get next card");
abc=Gamehelper.givecard(com1.GetOrFall);
System.out.println("the computer1's next card is "+ abc);
com1.Truetotal=com1.Truetotal+abc;
com1.Total=com1.Total+abc;
System.out.println("Computer1's total points is "+com1.Total);
com1.GetOrFall=Gamehelper.bomp(com1.Truetotal);
//获取电脑1的牌,以及得到电脑1的点数
}
}
if(com2.GetOrFall==true){
com2.GetOrFall=com2.winORlose(com2.Truetotal,Wanjia.totalpoints,Wanjia.truepoints);
if(com2.GetOrFall==true){
System.out.println("the comuter2 chooses to get next card");
com2.GetOrFall=com2.winORlose(com2.Truetotal,Wanjia.totalpoints,Wanjia.truepoints);
abc=Gamehelper.givecard(com2.GetOrFall);
System.out.println("the computer2's next card is"+ abc);
com2.Truetotal=com2.Truetotal+abc;
com2.Total=com2.Total+abc;
System.out.println("Computer2's total points is"+com2.Total);
com2.GetOrFall=Gamehelper.bomp(com2.Truetotal);
//获取电脑2的牌,以及得到电脑2的点数
}
}
}
finishGame();
}
public void finishGame(){
System.out.println("Player's true points is"+Wanjia.truepoints);
System.out.println("Computer1's true points is"+com1.Truetotal);
System.out.println("Computer2's true points is"+com2.Truetotal);
Gamehelper.result(Wanjia.truepoints,com1.Truetotal,com2.Truetotal);
}
/**
* @param args
*/
public static void main(String[] args) {
Game goodstart=new Game();
goodstart.setupGame();
goodstart.playingGame();
}// TODO 自动生成方法存根
}
java 21点游戏 命令行代码
需积分: 9 29 浏览量
2011-06-08
12:48:56
上传
评论 2
收藏 8KB ZIP 举报
wangcansun
- 粉丝: 3
- 资源: 2