怎样用Java开发一个飞行棋游戏?
楼主好,这个是类似的哈
import java.util.Scanner;
{
SnakeLadder3333333(String play, int sum) {
this.play = play;
this.sum = sum;
}
String play;
int sum = 0;
int i = 0;
public void add(SnakeLadder3333333 other) {
int i = (int) (Math.random() * (6 - 1) + 1);
sum = sum + i;
if ((sum < 16 || sum > 16) && (sum < 38 || sum > 38) && (sum < 72 || sum > 72) && (sum < 83 || sum > 83)
&& (sum < 78 || sum > 78) && (sum < 99 || sum > 99) && (sum <= 100)) {
System.out.println(play + "got " + i + " points on the die");
System.out.println(play + " got " + sum);
System.out.println(other.play + " got " + other.sum);
} else if (15 < sum && sum < 17) {
System.out.println(play + "got " + i + " points on the die");
System.out.println(play + "is on a ladder");
sum = sum + 8;
System.out.println(play + " got " + sum);
System.out.println(other.play + " got " + other.sum);
} else if (37 < sum && sum < 39) {
System.out.println(play + "got " + i + " points on the die");
System.out.println(play + "is on a ladder");
sum = sum + 26;
System.out.println(play + " got " + sum);
System.out.println(other.play + " got " + other.sum);
} else if (71 < sum && sum < 73) {
System.out.println(play + "got " + i + " points on the die");
System.out.println(play + "is on a ladder");
sum = sum + 19;
System.out.println(play + " got " + sum);
System.out.println(other.play + " got " + other.sum);
} else if (82 < sum && sum < 84) {
System.out.println(play + "got " + i + " points on the die");
System.out.println(play + "is on a snake");
sum = sum - 19;
System.out.println(play + " got " + sum);
System.out.println(other.play + " got " + other.sum);
} else if (77 < sum && sum < 79) {
System.out.println(play + "got " + i + " points on the die");
System.out.println(play + "is on a snake");
sum = sum - 18;
System.out.println(play + " got " + sum);
System.out.println(other.play + " got " + other.sum);
} else if (98 < sum && sum < 100) {
System.out.println(play + "got " + i + " points on the die");
System.out.println(play + "is on a snake");
sum = sum - 7;
System.out.println(play + " got " + sum);
System.out.println(other.play + " got " + other.sum);
} else if (sum >= 100|| other.sum >= 100) {
System.out.println(play + " got " + sum);
System.out.println(other.play + " got " + other.sum);
System.out.println(play + "got " + i + " points on the die");
System.out.println(play + " lost " + other.play + " Won");
}
}
public boolean live(SnakeLadder3333333 other) {
if (sum >= 100 || other.sum >= 100) {
System.out.println(play + " lost " + other.play + " Won");
return false;
}
return true;
}
public static void main(String[] args) {
String q, m;
int e, n;
@SuppressWarnings("resource")
Scanner scanner = new Scanner(System.in);
SnakeLadder3333333 p1 = new SnakeLadder3333333("Player a ", 0);
SnakeLadder3333333 p2 = new SnakeLadder3333333("Player b ", 0);
while (true) {
p1.add(p2);
System.out.print("Enter c to continue, s to stop: ");
q = scanner.next();
e = q.indexOf('s');
p2.live(p1);
if (e == 0) {
return;
} else {}
p2.add(p1);
System.out.print("Enter c to continue, s to stop: ");
m = scanner.next();
n = m.indexOf('s');
p1.live(p2);
if (n == 0) {
return;
} else {
}
}
}
}