龟兔赛跑

String[] array = new String[70];
int gui = 0;
int tu = 0;
System.out.println("比赛开始");
while (true){
Random random = new Random();
int num = random.nextInt(10)+1;
if (num >=1 && num <= 5){
gui += 3;
}
else if (num >= 6 && num <= 7){
gui -= 6;
if (gui < 0){
gui = 0;
}
}
else {
gui += 1;
}
if (num >=1 && num <= 2){
}
else if (num >= 3 && num <= 4){
tu += 9;
}
else if (num == 5){
tu -= 12;
if (tu < 0){
tu = 0;
}
}
else if (num >= 6 && num <= 8){
tu += 1;
}
else {
tu -= 2;
if (tu < 0){
tu = 0;
}
}
if (gui >= 70){
System.out.println("龟赢了");
break;
}
else if (tu >= 70){
System.out.println("兔子赢了");
break;
}
if (gui == tu){
array[gui] = "OUCH!!!";
}
else {
array[gui] = "G";
array[tu] = "T";
}
for (int i = 0;i < array.length;i++){
if (i == gui || i == tu){
System.out.print(array[i]+" ");
}
else {
System.out.print("_ ");
}
}
System.out.println();
Thread.sleep(300);
}

你可能感兴趣的:(龟兔赛跑)