模拟谁最厉害小游戏

来源:互联网 发布:淘宝一键复制有违规吗 编辑:程序博客网 时间:2024/04/30 14:54
import java.util.*;
import java.io.*;


class Game {
Scanner scanner = new Scanner(System.in);
LinkedList save = new LinkedList();
int coptNum = 0, humanNum = 0;
Game() {
for(int i = 0; i < 20 + (Math.random() * 10 / 3); i++) {
save.add("b");
}
save.add("a");
}


public int getMachinNum() {
int compN = (int) (Math.random() * 10 / 3);
return compN;
}
public int getHumenNum() {
int humenN = new Scanner(System.in).nextInt();
return humenN;
}
}


public class stickGame {
static int n = 0;
public static void main(String args[]){
try{
Game game = new Game();
System.out.println("你要拿几个火柴?(1~3根):");
while(!(stickGame.n == 1 && stickGame.n == 2)) {
int n =  game.getHumenNum();
for(int i = 0; i <= n; i++) {
String string1 = (String) game.save.get(i);
if(string1 == "a"){
System.out.println("电脑赢");
break;
}
game.save.remove(0);
}
System.out.println("电脑拿了" + game.getMachinNum() + "个火柴");
for(int j = 0; j < game.getMachinNum(); j++) {
String string2 = (String)game.save.get(j);
if(string2 == "a") {
stickGame.n = 2;
System.out.println("玩家赢");
break;
}
game.save.get(0);
}
System.out.println("你要拿几个火柴?");
}
}catch(Exception e) {
System.out.println("游戏结束!");
}
}
}