//考核项目:控制台实现,25号前提交
//加分项:用面向对象实现
//要求:不允许用一个方法直接写完,尽量不要披着羊皮的狼
import java.util.Scanner;
//游戏:飞行棋
//龟兔赛跑:乌龟随机1-3格,兔子随机1-6格
//跑道 – 100格,每20格会随机出现五种功能格各一个
//功能格:
//1.幸运星 ** 可以再次执行一次
//2.传送门== 乌龟传送到下两个传送门,兔子传送到下一个传送门,如果后方无传送门则直接传送到终点
//3.地雷 @@ 乌龟炸回到上一个地雷格,兔子炸回到上两个地雷格,如果前方无地雷则直接回到起点
//4.下坡 ^^ 乌龟遇到下坡前进10格
//5.树 || 兔子遇到树停止3个回合
//传送门和地雷没有联动效果,其他会触发联动效果
public class Game {
public static int[] route=new int[101];
public static int[] route1=new int[101];
public static int[] route2=new int[101];
public static int[] route4=new int[101];
public static Rabbit r=new Rabbit();
public static Tortoise t=new Tortoise();
public static int turn=1;
public static void main(String[] args) {
map();
print(route);
new Scanner(System.in).nextLine();
while(true){
if(turn%2==0){
Game.moveT();
turn++;
if(route[100]==9||route4[100]==8){
return;
}
}else {
Game.moveR();
turn++;
if(route[100]==9||route4[100]==8){
return;
}
}
new Scanner(System.in).nextLine();
}
}
public static void moveT(){
t.move();
cmpT(t);
System.out.println();
print(route);
route[t.getStep()]=0;
}
public static void moveR(){
r.move();
cmpR(r);
System.out.println();
print(route4);
route4[r.getStep1()]=0;
}
public static void map(){
int n=1;
int k = 1;
for(int i=0;i<5;i++) {
while ((k / 20) != 0) {
route[k] = 0;
route4[k]=0;
k++;
}
k++;
int num1 = (int) (Math.random() * 20) + n;
int num2 = (int) (Math.random() * 5) + 1;
route[num1] = num2;
route4[num1]=num2;
n=n+20;
}
}
public static void print(int[] s){
for(int i=1;i<101;i++){
if(s[i]==0){
System.out.print("--");
}else if(s[i]==8){
System.out.print("兔子");
}else if(s[i]==9){
System.out.print("乌龟");
}else if(s[i]==1){
System.out.print("**");
}else if(s[i]==2){
System.out.print("==");
}else if(s[i]==3){
System.out.print("@@");
}else if(s[i]==4){
System.out.print("^^");
}else {
System.out.print("||");
}
}
}
public static void cmpT(Tortoise a){
for(int i=1;i<101;i++){
if(route1[i]==9&&(route[i]==0||route[i]==5)){
route[i]=9;
}else if(route[i]==1&&route1[i]==9){
a.move();
cmpT(a);
}else if(route[i]==2&&route1[i]==9){
for(int k=i+1;k<101;k++){
if(route[k]==2){
for(int j=k+1;j<101;j++){
route1[i]=0;
route[j]=9;
a.setStep(k);
break;
}
}else if (k==100){
a.setStep(100);
route1[i]=0;
route[100]=9;
}
}
}else if(route[i]==3&&route1[i]==9){
for(int k=i-1;k>0;k--){
if(route[k]==3){
route1[i]=0;
route[k]=9;
a.setStep(k);
route1[k]=9;
break;
}
if(k==1){
route[1]=9;
route1[i]=0;
a.setStep(1);
}
}
}else if(route[i]==4&&route1[i]==9){
route[i+10]=9;
route1[i]=0;
a.setStep(i+10);
}
}
}
public static void cmpR(Rabbit s){
for(int i=1;i<101;i++){
if(route2[i]==8&&(route4[i]==0||route4[i]==4)){
route4[i]=8;
}else if(route4[i]==1&&route2[i]==8){
s.move();
cmpR(s);
}else if(route4[i]==2&&route2[i]==8){
for(int k=i+1;k<101;k++){
if(route4[k]==2){
route2[i]=0;
route4[k]=8;
s.setStep1(k);
break;
}else if (k==100){
s.setStep1(100);
route2[i]=0;
route4[100]=8;
}
}
}else if(route4[i]==3&&route2[i]==8){
for(int k=i-1;k>0;k--){
if(route4[k]==3){
for(int j=k-1;j>0;j--){
if(route4[j]==3){
route2[i]=0;
route4[j]=8;
s.setStep1(j);
route2[j]=8;
break;
}
}
}
if(k==1){
route4[1]=8;
route2[i]=0;
s.setStep1(1);
}
}
}else if(route4[i]==4&&route2[i]==8){
route4[i+10]=8;
route2[i]=0;
s.setStep1(i+10);
}else if(route4[i]==5&&route2[i]==8){
for(int k=0;k<3;k++){
Game.moveT();
new Scanner(System.in).nextLine();
}
}
}
}
}
兔子类
public class Rabbit{
private int step1=1;
public int getStep1() {
return step1;
}
public void setStep1(int step1) {
this.step1 = step1;
}
public void move(){
int num = (int) (Math.random() * 5) + 1;
Game.route2[step1]=0;
step1=step1+num;
if(step1>100){
Game.route2[100]=8;
}else {
Game.route2[step1]=8;
}
}
}
乌龟类
public class Tortoise{
private int step=1;
public int getStep() {
return step;
}
public void setStep(int step) {
this.step = step;
}
public void move(){
int num = (int) (Math.random() * 3) + 1;
Game.route1[step]=0;
step=step+num;
if(step>100){
Game.route1[100]=9;
}else {
Game.route1[step]=9;
}
}
}