java飛行棋實(shí)現(xiàn)思路
更新時(shí)間:2020年09月21日 07:37:06 作者:Sisto
這篇文章主要為大家詳細(xì)介紹了java飛行棋的實(shí)現(xiàn)思路,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了java飛行棋的注釋版,供大家參考,具體內(nèi)容如下
可以直接用:
import java.util.Scanner;
public class Fly3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int all1 = 0;// 記錄A的步數(shù)
int all2 = 0;// 記錄B的步數(shù)
int flag1 = 1;// 對于A的暫停情況進(jìn)行判斷
int flag2 = 1;// 對于B的暫停情況進(jìn)行判斷
int first1 = 0;// 進(jìn)行初始化判斷
int first2 = 0;
System.out.print("|||||||||✈|||||||||||||||||||||||" + "\n||||✈||||||飛行棋Beta版||||||||||||\n"
+ "|||||||||||||||||||||||||||✈|||||\n"+ "||||||||✈||||||||||||||||||||||||");// 標(biāo)題顯示
System.out.println();
System.out.println();
System.out.println();
System.out.println("\t}}}}圖形展示{{{{");
System.out.println("✈為傳送門,一次10格" + "\n💣為炸彈,一次退回6格" + "\n⚡為被雷劈,一次直接返回原點(diǎn) " + "\n💩為幸運(yùn)輪盤,踩上去可選擇相關(guān)"
+ "\n🕔為暫停,踩上后下一次行動(dòng)無法進(jìn)行" + "\n注:玩家與玩家的位置相同時(shí),后一個(gè)玩家將會(huì)將上一個(gè)玩家擠退2格");
System.out.println();
System.out.println();
String A = "玩家A";// 用戶選擇角色
A = login(A);
String B = "玩家B";
B = login(B);
if (A.equals(B)) {
B = B + "2號";
}
maps(icon(all1, all2));
for (int i = 0;; i++) {
// A玩家視角👇
System.out.println(A + "開始投骰子");
int random1 = (int) (Math.random() * 6 + 1);
String msg = sc.nextLine();
System.out.println("少女祈禱中。。。");
System.out.println(A + "走" + random1 + "步");
all1 += random1;
if (first1 > 0) {// 判斷是否為第一次運(yùn)行地圖(由于數(shù)組坐標(biāo)重復(fù)的原因)
if (flag1 % 2 != 0) {// 判斷為第幾次踩到了暫停格子
all1 = all1 - random1;// 如果是第二次則將前面走的隨機(jī)步數(shù)減回去
System.out.println("但是" + A + "不能走!因?yàn)?);
}
}
first1++;
all2 = samepoint(all1, all2, B, A);// 判斷二者坐標(biāo)相同時(shí)(當(dāng)A擠到B的位置時(shí)B怎么辦(一種為后退四個(gè)格子一種為回到原點(diǎn)))
all1 = walk(A, all1);// 得到A所在數(shù)組下標(biāo)位置,接下來對A的位置進(jìn)行一次是否暫停的判定
flag1 = check(all1, flag1);
/*
* if (all1 == 15 || all1 == 28 || all1 == 85 || all1 == 90)
* {//(在輸出地圖之后對A當(dāng)前所在的位置進(jìn)行判定,如果滿足則讓flag自加1)
* flag1++;}此時(shí)flag在暫停判定模塊中滿足條件,進(jìn)入判定,當(dāng)?shù)诙谓Y(jié)束后flag則不會(huì)滿足上面暫停模塊的判定條件 else { flag1 =
* 0; }//正常情況時(shí)flag被賦值為0;則不會(huì)走到上面的暫停判定模塊
*
*/
if (all1 == 55 || all1 == 22 || all1 == 10) {// 對幸運(yùn)轉(zhuǎn)盤進(jìn)行操作判定
System.out.println("請選擇" + A + "要執(zhí)行的操作!\n1.和" + B + "換個(gè)位置\n2.讓" + B + "退后個(gè)4格子");
int choice = sc.nextInt();
if (choice == 1) {
int temp = all1;
all1 = all2;
all2 = temp;
System.out.println(A + "和" + B + "的位置交換了!");
} else {
if (all2 < 4) {
all2 = 0;
System.out.println("直接把" + B + "送回原點(diǎn)了!");
} else {
all2 -= 4;
}
}
}
maps(icon(all1, all2));// 判斷A是否符合條件獲勝
System.out.println(A+"的位置是"+all1+"\n"+B+"的位置是"+all2+"\n");
if (all1 >= 100) {
System.out.println(A + "贏啦");
return;
}
// 到此為止,對A的一輪判定結(jié)束
// B玩家地圖視角👇
System.out.println(B + "開始投骰子");
int random2 = (int) (Math.random() * 6 + 1);
String msg2 = sc.nextLine();
System.out.println("少女祈禱中。。。");
System.out.println(B + "走" + random2 + "步");
all2 += random2;
if (first2 > 0) {// 判斷是否初始化
if (flag2 % 2 != 0) {// 判斷第幾次踩到了暫停格子
all2 = all2 - random2;
System.out.println("但是" + B + "不能走!因?yàn)?);
}
}
first2++;
all1 = samepoint(all2, all1, A, B);// 判斷二者坐標(biāo)相同時(shí)(當(dāng)B擠到A的位置時(shí)A怎么辦(一種為后退四個(gè)格子一種為回到原點(diǎn)))
all2 = walk(B, all2);
flag2 = check(all2, flag2);
if (all2 == 55 || all2 == 22 || all2 == 10) {
System.out.println("請選擇" + B + "要執(zhí)行的操作!\n1.和" + A + "換個(gè)位置\n2.讓" + A + "退后個(gè)4格子");
int choice = sc.nextInt();
if (choice == 1) {
int temp = all2;
all2 = all1;
all1 = temp;
System.out.println(B + "和" + A + "的位置交換了!");
} else {
if (all1 < 4) {
all1 = 0;
System.out.println("直接把" + A + "送回原點(diǎn)了!");
} else {
all1 -= 4;
}
}
}
maps(icon(all1, all2));
System.out.println(A+"的位置是"+all1+"\n"+B+"的位置是"+all2+"\n");
if (all2 >= 100) {// 判斷B是否符合條件獲勝
System.out.println(B + "贏啦");
return;
}
// 到此位置,對B的一輪判定結(jié)束
}
}
public static void maps(String[] a) {// 加空格是為了美觀
for (int i = 0; i < 32; i++) {
System.out.print(a[i] + " ");
}
System.out.println();// 第一排地圖圖形輸出
for (int i = 0; i < 32; i++) {
System.out.print(" ");
}
System.out.println(" " + a[32]);// 第二排地圖圖形輸出
for (int i = 0; i < 32; i++) {
System.out.print(" ");
}
System.out.println(" " + a[33]);// 第三排地圖圖形輸出
for (int i = 65; i > 33; i--) {
System.out.print(a[i] + " ");// 第四排地圖圖形輸出
}
System.out.println();
System.out.println(a[66]);
System.out.println(a[67]);// 第五第六排地圖輸出
for (int i = 68; i < 100; i++) {
System.out.print(a[i] + " ");// 第七排地圖圖形輸出
}
for (int i = 100; i < 105; i++) {// 結(jié)尾小旗子圖像輸出
System.out.print(a[i]);
}
System.out.println();
}
public static String[] icon(int a, int b) {
String[] map = new String[105];
for (int i = 0; i < 105; i++) {
if (i == 32 || i == 33 || i == 66 || i == 67) {
map[i] = "||";// 豎向輸出道路
} else if (i == 3 || i == 9 || i == 23 || i == 40) {
map[i] = "✈";// 傳送門logo
} else if (i == 75 || i == 62 || i == 48 || i == 37 || i == 98) {
map[i] = "💣";// 炸彈logo
} else if (i == 15 || i == 28 || i == 85 || i == 90) {
map[i] = "🕔";// 暫停logo
} else if (i == 55 || i == 22 || i == 10) {
map[i] = "💩";// 幸運(yùn)轉(zhuǎn)盤logo
} else if (i == 100 || i == 101 || i == 102 || i == 103 || i == 104) {
map[i] = "🚩";// 結(jié)尾處旗幟logo
} else if (i == 99) {
map[i] = "⚡";// 結(jié)尾處閃電logo
} else {
map[i] = "=";// 其余為橫向的道路
}
}
map[b] = "B";
map[a] = "A";
return map;
}
public static int walk(String player, int a) {// 對當(dāng)前角色應(yīng)該走到的數(shù)組下標(biāo)進(jìn)行判斷
int num = a;
switch (a) {
case 3:
case 9:
case 23:
case 40:
System.out.println(player + "進(jìn)入傳送門,傳送10格!");
num = a + 10;
break;
case 75:
case 62:
case 48:
case 37:
case 98:
System.out.println(player + "危??!\n踩到炸彈了,退6格!");
num = a - 6;
return num;
case 15:
case 28:
case 85:
case 90:
num = a;
System.out.println(player + "踩到了暫停格子!");
break;
case 55:
case 22:
case 10:
num = a;
System.out.println(player + "踩到了幸運(yùn)轉(zhuǎn)盤?。。?!");
break;
case 99:
num = 0;
System.out.println(player + "危!!!\n被雷劈了,直接送回原點(diǎn)");
break;
default:
num = a;
break;
}
return num;
}
public static int check(int a, int b) {// a為位置,b為狀態(tài)判斷
if (a == 15 || a == 28 || a == 85 || a == 90) {
b++;
} else {
b = 0;
}
return b;
}
public static String login(String a) {
String[] names = { "勞拉", "不知火舞", "春麗" };
Scanner sc = new Scanner(System.in);
System.out.println("可選角色:1.勞拉\t2.不知火舞\t3.春麗");
System.out.println("請" + a + "選擇你的角色");// 角色選擇
int aplayer = sc.nextInt();
String player = names[aplayer - 1];
return player;
}
public static int samepoint(int a, int b, String A, String B) {// 輸入的A為受害者,B為幸運(yùn)玩家
if (a == b && a >= 2 && a != 0) {
b = b - 2;
System.out.println(A + "玩家被" + B + "玩家擠回去了2格!");
return b;
} else if (a == b && a < 2 && a > 0) {
b = 0;
System.out.println(A + "玩家被" + B + "玩家擠回去了原點(diǎn)!");
}
return b;
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
MyBatis-Plus中SimpleQuery查詢實(shí)現(xiàn)
本文主要介紹了MyBatis-Plus中SimpleQuery查詢實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
Spring boot 集成 Druid 數(shù)據(jù)源過程詳解
這篇文章主要介紹了Spring boot 集成 Druid 數(shù)據(jù)源過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08
Java聊天室之實(shí)現(xiàn)客戶端一對一聊天功能
這篇文章主要為大家詳細(xì)介紹了Java簡易聊天室之實(shí)現(xiàn)客戶端一對一聊天功能,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以了解一下2022-10-10
Java中l(wèi)ist.foreach不能使用字符串拼接的問題
這篇文章主要介紹了Java中l(wèi)ist.foreach不能使用字符串拼接的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09
request.getRequestURL()等方法得到路徑的區(qū)別及說明
這篇文章主要介紹了request.getRequestURL()等方法得到路徑的區(qū)別及說明,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12
詳解Spring Cloud 斷路器集群監(jiān)控(Turbine)
這篇文章主要介紹了詳解Spring Cloud 斷路器集群監(jiān)控(Turbine),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05

