樓主好,這個是類似的哈
創(chuàng)新互聯(lián)公司是網(wǎng)站建設(shè)專家,致力于互聯(lián)網(wǎng)品牌建設(shè)與網(wǎng)絡(luò)營銷,專業(yè)領(lǐng)域包括網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、電商網(wǎng)站制作開發(fā)、重慶小程序開發(fā)公司、微信營銷、系統(tǒng)平臺開發(fā),與其他網(wǎng)站設(shè)計及系統(tǒng)開發(fā)公司不同,我們的整合解決方案結(jié)合了恒基網(wǎng)絡(luò)品牌建設(shè)經(jīng)驗和互聯(lián)網(wǎng)整合營銷的理念,并將策略和執(zhí)行緊密結(jié)合,且不斷評估并優(yōu)化我們的方案,為客戶提供全方位的互聯(lián)網(wǎng)品牌整合方案!
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 {
}
}
}
}
畫MAP類:
package s1java.xmal1;
public class Map {
int[] map=new int[100]; //0:普通
int[] luckyTurn={6,23,40,55,69,83}; //1:幸運輪盤
int[] landMine={5,13,17,33,38,50,64,80,94};//2:地雷
int[] pause={9,27,60,93}; //3:暫停
int[] timeTunnel={20,25,45,63,72,88,90}; //4:時空隧道
//給map[]寫入各種符號
public void createMap(){
for(int i=0;iluckyTurn.length;i++){
map[luckyTurn[i]]=1;
}
for(int i=0;ilandMine.length;i++){
map[landMine[i]]=2;
}
for(int i=0;ipause.length;i++){
map[pause[i]]=3;
}
for(int i=0;itimeTunnel.length;i++){
map[timeTunnel[i]]=4;
}
}
public void showMap(int playerPos1,int playerPos2){
showLine1(0,31,playerPos1,playerPos2);
showRLine(31,35,playerPos1,playerPos2);
showLine2(35,66,playerPos1,playerPos2);
showLLine(66,69,playerPos1,playerPos2);
showLine1(69,100,playerPos1,playerPos2);
}
public void showLine1(int start,int end,int playerPos1,int playerPos2){
for(int i=start;iend;i++ ){
System.out.print(getGraph(map[i],i,playerPos1,playerPos2));
}
System.out.println();
}
public void showRLine(int start,int end,int playerPos1,int playerPos2){
for(int i=start;iend;i++){
for(int j=0;j73;j++){
System.out.print(" ");
}
System.out.println(getGraph(map[i],i,playerPos1,playerPos2));
}
}
public void showLine2(int start,int end,int playerPos1,int playerPos2){
for(int i=end-1;i=start;i--){
System.out.print(getGraph(map[i],i,playerPos1,playerPos2));
}
System.out.println();
}
public void showLLine(int start,int end,int playerPos1,int playerPos2){
for(int i=start;iend;i++){
System.out.println(getGraph(map[i],i,playerPos1,playerPos2));
}
}
public String getGraph(int i,int index,int playerPos1,int playerPos2){
String graph=" ";
if(index==playerPos1index==playerPos2){
graph="@@";
}else if(index==playerPos1){
graph="A";
}else if(index==playerPos2){
graph="B";
}else{
switch(i){
case 1:
graph="¤";
break;
case 2:
graph="★";
break;
case 3:
graph="■";
break;
case 4:
graph="〓";
break;
default:graph="⊙";
break;
}
}
return graph;
}
}
Game類:
package s1java.xmal1;
import java.util.Scanner;
public class Game {
Scanner input = new Scanner(System.in);
Map map;
int playerPos1;
int playerPos2;
String[] goAndStop=new String[2];
String[] playerName=new String[2];
public void init(){
map=new Map();
map.createMap();
map.showMap(0, 0);
goAndStop[0]="on";
goAndStop[1]="on";
}
public void setRole(int no,int role){
switch(role){
case 1:playerName[no-1]="比爾";break;
case 2:playerName[no-1]="奧巴馬";break;
case 3:playerName[no-1]="普京";break;
case 4:playerName[no-1]="布朗";break;
}
}
public int throwShifter(int no){
int step=0;
System.out.println(playerName[no-1]+"按任意字母鍵回車:");
String answer=input.next();
step=(int)(Math.random()*10%6)+1;
return step;
}
public int getCurPos(int no,int position,int step){
position=position+step;
if(position99){
return 99;
}
switch(map.map[position]){
case 0://普通格
if(no==1playerPos2==position){//玩家1與玩家2相遇
playerPos2=0;
System.out.println(":-D 哈哈哈...踩到了!");
}else if(no==2playerPos1==position){
playerPos1=0;
System.out.println(":-D 哈哈哈...踩到了!");
}
break;
case 1://幸運輪盤
System.out.println("\n◆◇◆◇◆◇歡迎進入幸運輪盤◆◇◆◇◆◇");
System.out.println("請選擇一種運氣:");
System.out.println("1.交換位置2.轟炸對手");
int choice=input.nextInt();
int temp;
switch(choice){
case 1: //交換位置
if(no==1){
temp=position;
position=playerPos2;
playerPos2=temp;
}else if(no==2){
temp=position;
position=playerPos1;
playerPos1=temp;
}
break;
case 2: //轟炸對手
if(no==1){
if(playerPos26){
playerPos2=0;
}else{
playerPos2-=6;
}
}else if(no==2){
if(playerPos16){
playerPos1=0;
}else{
playerPos1-=6;
} }
break;
}
break;
case 2://地雷
position-=6;
System.out.println("踩到地雷,氣死了。");
break;
case 3://暫停
goAndStop[no-1]="off";
System.out.println("~~_~~ 要停戰(zhàn)一局了。");
break;
case 4://時空隧道
position+=10;
System.out.println("|-P 進入時空隧道真爽!");
break;
}
if(position0){
return 0;
}else if(position99){
return 99;
}else{
return position;
}
}
public void judge(){
if(playerPos1playerPos2){
System.out.println("玩家1"+playerName[0]+"最先到達終點,獲得勝利。恭喜!恭喜!");
}else{
System.out.println("玩家2"+playerName[1]+"最先到達終點,獲得勝利。恭喜!恭喜!");
}
}
public void play(){
System.out.println("\n\n\n\n");
System.out.println("\n※※※※※※※※※※※※※※※※※※※※※※※※※\n");
System.out.println(" Game Start \n");
System.out.println("※※※※※※※※※※※※※※※※※※※※※※※※※\n\n");
System.out.println("^_^"+playerName[0]+"的士兵: A");
System.out.println("^_^"+playerName[1]+"的士兵: B\n");
System.out.println("\n圖例:"+"■暫停 ¤幸運輪盤 ★地雷 〓時空隧道 ⊙ 普通\n");
map.showMap(playerPos1, playerPos2);
int step;
while(playerPos199playerPos299){
if(goAndStop[0].equals("on")){
step= throwShifter(1);
System.out.println("\n-----------------------");
System.out.println("骰子數(shù)"+step);
playerPos1=getCurPos(1,playerPos1,step);
System.out.println("你"+playerName[0]+"當前的位置:"+playerPos1);
System.out.println("對手"+playerName[1]+"當前的位置:"+playerPos2);
System.out.println("\n-----------------------");
map.showMap(playerPos1, playerPos2);
if(playerPos1==99){
break;
}
}else{
System.out.println("\n"+playerName[0]+"停擲一次。\n");
goAndStop[0]="on";
}
System.out.println("\n\n\n\n");
if(goAndStop[1].equals("on")){
step= throwShifter(2);
System.out.println("\n-------------------------------");
System.out.println("骰子數(shù)"+step);
playerPos2=getCurPos(2,playerPos2,step);
System.out.println("你"+playerName[1]+"當前的位置:"+playerPos2);
System.out.println("對手"+playerName[0]+"當前的位置:"+playerPos1);
System.out.println("\n-------------------------------");
map.showMap(playerPos1, playerPos2);
if(playerPos2==99){
break;
}
}else{
System.out.println("\n"+playerName[1]+"停擲一次。\n");
goAndStop[1]="on";
}
System.out.println("\n\n\n\n");
}
System.out.println("\n\n\n\n");
System.out.println("\n************************************************\n");
System.out.println(" Game Over \n");
System.out.println("************************************************\n\n");
judge();
}
public void start(){
init();
System.out.println("\n※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※");
System.out.println("http:// //");
System.out.println("http:// //");
System.out.println("http:// 騎士飛行棋 //");
System.out.println("http:// //");
System.out.println("http:// //");
System.out.println("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~兩人對戰(zhàn)~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("請選擇角色:1.比爾2.奧巴馬3.普京4.布朗");
System.out.println("請玩家1選擇角色:");
int role1=input.nextInt();
int role2;
do{
System.out.println("請玩家2選擇角色:");
role2=input.nextInt();
}while(role2==role1);
setRole(1,role1);
setRole(2,role2);
play();
}
}
主方法類:
package s1java.xmal1;
public class StartGame {
public static void main(String[] args) {
Game game=new Game();
game.start();
}
}
樓上說的很對,switch首先不是循環(huán),只是一個判斷,i的值影響你地圖上輸出的到底是什么類型的圖案,我把我寫的源碼給你,你看看,注釋比較全,加油學吧,不懂多問問同學或老師
地圖類:
package s1java.t70.qsfxq;
public class Map {
int[] map = new int[100]; //對戰(zhàn)地圖
int[] luckyTurn = ; //幸運輪盤
int[] landMine = ; //地雷位置
int[] pause = ; //暫停
int[] timeTunnel = ; //時空隧道
/**
* 生成地圖:
* 關(guān)卡代號為:1:幸運輪盤 2:地雷 3: 暫停 4:時空隧道 0:普通
*/
public void createMap(){
int i = 0;
//在對戰(zhàn)地圖上設(shè)置幸運輪盤
for(i = 0; i luckyTurn.length; i++){
map[luckyTurn[i]] = 1;
}
//添加代碼實現(xiàn)在對戰(zhàn)地圖上設(shè)置地雷
for(i = 0; i landMine.length; i++) {
map[landMine[i]] = 2;
}
//添加代碼實現(xiàn)在對戰(zhàn)地圖上設(shè)置暫停
for(i = 0; i pause.length; i++) {
map[pause[i]] = 3;
}
//添加代碼實現(xiàn)在對戰(zhàn)地圖上設(shè)置時空隧道
for(i = 0; i timeTunnel.length; i++) {
map[timeTunnel[i]] = 4;
}
}
/**
* 顯示地圖關(guān)卡對應(yīng)的圖形
* @param i 地圖當前位置的關(guān)卡代號
* @param index 當前地圖位置編號
* @param playerPos1 玩家1的當前位置
* @param playerPos2 玩家2的當前位置
* @return 地圖當前位置的對應(yīng)圖片
*/
public String getGraph(int i, int index, int playerPos1, int playerPos2){
String graph = "";
// 添加代碼
if(playerPos1 == index playerPos2 == index) {
graph = "@@";
}
else if(playerPos1 == index) {
graph = "A";
}
else if(playerPos2 == index) {
graph = "B";
}
else {
switch(i) {
case 0:
graph = "∷";
break;
case 1:
graph = "¤";
break;
case 2:
graph = "★";
break;
case 3:
graph = "■";
case 4:
graph = "〓";
}
}
return graph;
}
/**
* 輸出地圖的奇數(shù)行(第1、3行)
* @param start 輸出的起始點在地圖上的位置
* @param end 輸出的結(jié)束點在地圖上的位置
* @param playerPos1 玩家1的當前位置
* @param playerPos2 玩家2的當前位置
*/
public void showLine1(int start, int end, int playerPos1, int playerPos2){
//添加代碼
for(int i = start; i = end; i++ ){
System.out.print(getGraph(map[i], i,playerPos1, playerPos2));
}
}
/**
* 輸出地圖的偶數(shù)行(第2行)
* @param start 輸出的起始點在地圖上的位置
* @param end 輸出的結(jié)束點在地圖上的位置
* @param playerPos1 玩家1的當前位置
* @param playerPos2 玩家2的當前位置
*/
public void showLine2(int start, int end, int playerPos1, int playerPos2){
for(int i = end-1; i = start; i-- ){
System.out.print(getGraph(map[i], i,playerPos1, playerPos2));
}
}
/**
* 輸出地圖的右豎列
* @param start 輸出的起始點在地圖上的位置
* @param end 輸出的結(jié)束點在地圖上的位置
* @param playerPos1 玩家1的當前位置
* @param playerPos2 玩家2的當前位置
*/
public void showRLine(int start, int end, int playerPos1, int playerPos2){
for(int i = start; i end; i++){
for(int j = 28; j 0; j--){ //輸出29個空格
System.out.print(" ");
}
System.out.print(getGraph(map[i], i,playerPos1, playerPos2));
System.out.println();
}
}
/**
* 輸出地圖的左豎列
* @param start 輸出的起始點在地圖上的位置
* @param end 輸出的結(jié)束點在地圖上的位置
* @param playerPos1 玩家1的當前位置
* @param playerPos2 玩家2的當前位置
*/
public void showLLine(int start, int end, int playerPos1, int playerPos2){
//添加代碼
for(int i = start; i end; i++){
System.out.print(getGraph(map[i], i,playerPos1, playerPos2));
System.out.println();
}
}
/**
* 顯示對戰(zhàn)地圖
* @param playerPos1 玩家1的當前位置
* @param playerPos2 玩家2的當前位置
*/
public void showMap(int playerPos1, int playerPos2){
//顯示地圖第一行
showLine1(0, 30,playerPos1,playerPos2);
//換行
System.out.println();
//顯示地圖右豎行
showRLine(31,35,playerPos1,playerPos2);
//顯示地圖第二行
showLine2(35,66,playerPos1,playerPos2);
//換行
System.out.println();
//顯示地圖左豎行
showLLine(66,69,playerPos1,playerPos2);
//顯示地圖第3行
showLine1(69, 99,playerPos1,playerPos2);
}
}
GAME類:
package s1java.t70.qsfxq;
import java.util.*;
public class Game {
//聲明地圖
Map map =new Map();
//Map map;
//聲明對戰(zhàn)中玩家1的當前位置
int playerPos1;
//聲明對戰(zhàn)中玩家2的當前位置
int playerPos2;
//聲明走或停標識設(shè)置
String[] goAndStop = new String[2];
//聲明對戰(zhàn)角色
String[] playerName = new String[2];
/**
* 初始化游戲的一局
*/
public void init(){
//創(chuàng)建Map對象
//生成地圖
map.createMap();
//設(shè)置玩家1起始位置
playerPos1 = 0;
//設(shè)置玩家2起始位置
playerPos2 = 0;
//記錄玩家1下一次走或停
goAndStop[0] = "on";
//設(shè)置玩家2下一次走或停
goAndStop[1] = "on";
}
/**
* 開始游戲
*/
public void start(){
//調(diào)用初始化方法
init();
//顯示游戲界面
map.showMap(playerPos1, playerPos2);
System.out.println("\n");
System.out.println("1、戴高樂 2、艾森豪威爾 3、麥克阿瑟 4、巴頓\n");
//角色設(shè)置
Scanner input = new Scanner(System.in);
System.out.print("1P選擇人物: ");
int role = input.nextInt();
setRole(1,role);
boolean judge = true;
do {
System.out.println();
System.out.print("2P選擇人物: ");
int role2 = input.nextInt();
if(role2 == role) {
System.out.println("角色重復,請重新選擇人物!");
}
else {
setRole(2,role2);
}
}while(judge == false);
//開始游戲
play();
}
/**
* 設(shè)置對戰(zhàn)角色
* @param no 玩家次序 1:玩家1 2:玩家2
* @param role 角色代號
*/
public void setRole(int no, int role){
switch(role){
case 1:
playerName[no-1] = "戴高樂";
break;
case 2:
//設(shè)置玩家名稱為"艾森豪威爾"
playerName[no-1] = "艾森豪威爾";
break;
case 3:
//設(shè)置玩家名稱為"麥克阿瑟"
playerName[no-1] = "麥克阿瑟";
break;
case 4:
//設(shè)置玩家名稱為"巴頓"
playerName[no-1] = "巴頓";
break;
default:
break;
}
}
/**
* 兩人對戰(zhàn)玩法
*/
public void play(){
System.out.println("\n\n\n\n");
System.out.print("\n\n****************************************************\n");
System.out.print(" Game Start \n");
System.out.print("****************************************************\n\n");
//顯示對戰(zhàn)雙方士兵樣式
System.out.println("^_^" + playerName[0] + "的士兵: A");
System.out.println("^_^" + playerName[1] + "的士兵: B\n");
//顯示對戰(zhàn)地圖
System.out.println("\n圖例: " + "■ 暫停 ¤ 幸運輪盤 ★ 地雷 〓 時空隧道 ∷ 普通\n");
map.showMap(playerPos1, playerPos2);
//游戲開始
int step; //存儲骰子數(shù)目
while(playerPos1 99 playerPos2 99){ //有任何一方走到終點,跳出循環(huán)
//輪流擲骰子
if(goAndStop[0].equals("on")){
//玩家1擲骰子
step = throwShifter(1); //擲骰子
System.out.println("\n-----------------"); //顯示結(jié)果信息
System.out.println("骰子數(shù): "+ step);
playerPos1 = getCurPos(1, playerPos1, step); //計算這一次移動后的當前位置
System.out.println("\n您當前位置: "+ playerPos1);
System.out.println("對方當前位置:"+ playerPos2);
System.out.println("-----------------\n");
map.showMap(playerPos1, playerPos2); //顯示當前地圖
if(playerPos1 == 99){ //如果走到終點
break; //退出
}
}else{
System.out.println("\n" + playerName[0] +"停擲一次!\n"); //顯示此次暫停信息
goAndStop[0] = "on"; //設(shè)置下次可擲狀態(tài)
}
System.out.println("\n\n\n\n");
if(goAndStop[1].equals("on")){
//玩家2擲骰子
step = throwShifter(2); //擲骰子
System.out.println("\n-----------------"); //顯示結(jié)果信息
System.out.println("骰子數(shù): "+ step);
playerPos2 = getCurPos(2, playerPos2, step); //計算這一次移動后的當前位置
System.out.println("\n您當前位置: "+ playerPos2);
System.out.println("對方當前位置:"+ playerPos1);
System.out.println("-----------------\n");
map.showMap(playerPos1, playerPos2);
if(playerPos2 == 99){ //如果走到終點
break; //退出
}
}else{
System.out.println("\n" + playerName[1] + "停擲一次!\n"); //顯示此次暫停信息
goAndStop[1] = "on"; //設(shè)置下次可擲狀態(tài)
}
System.out.println("\n\n\n\n");
}
//游戲結(jié)束
System.out.println("\n\n\n\n");
System.out.print("****************************************************\n");
System.out.print(" Game Over \n");
System.out.print("****************************************************\n\n");
judge();
}
/**
* 擲骰子
* @param no 玩家次序
* @return step 擲出的骰子數(shù)目
*/
public int throwShifter(int no){
//定義變量存儲骰子數(shù)目
int step = 0;
//提示玩家啟動擲骰子
System.out.println("\n");
System.out.print("請輸入任意鍵開擲骰子!");
Scanner input = new Scanner(System.in);
input.nextInt();
//模擬擲骰子:產(chǎn)生一個1~6的數(shù)字作為玩家擲的骰子數(shù)目
Random random = new Random();
step = random.nextInt(5) + 1;
return step;
}
/**
* 計算玩家此次移動后的當前位置
* @param no 玩家次序
* @param position 移動前位置
* @param step 擲的骰子數(shù)目
* @return position 移動后的位置
*/
public int getCurPos(int no, int position, int step){
position = position + step; //第一次移動后的位置
if(position = 99){
return 99;
}
Scanner input = new Scanner(System.in);
switch(map.map[position]){ //根據(jù)地圖中的關(guān)卡代號進行判斷
case 0: //走到普通格
if(position == playerPos2){ //添加條件:玩家1與對方騎兵相遇
//添加代碼實現(xiàn):踩到對方,對方回到起點
playerPos2 = 0;
System.out.println(":-D 哈哈哈哈...踩到了!");
}
if (position == playerPos1){ //添加條件:玩家2與對方騎兵相遇
//添加代碼實現(xiàn):踩到對方,對方回到起點
playerPos1 = 0;
System.out.println(":-D 哈哈哈哈...踩到了!");
}
break;
case 1: //幸運輪盤
System.out.println("\n◆◇◆◇◆歡迎進入幸運輪盤◆◇◆◇◆");
System.out.println(" 請選擇一種運氣:");
System.out.println(" 1. 交換位置 2. 轟炸");
System.out.println("=============================\n");
int choice = input.nextInt();
int temp; //交換時的臨時變量
switch(choice){
case 1: //交換位置
if(no == 1){
//添加代碼實現(xiàn)交換:position與playerPos2數(shù)值互換
temp = playerPos2;
playerPos2 = position;
position = temp;
}else if(no == 2){
//添加代碼實現(xiàn)交換:position與playPos1數(shù)值互換
temp = playerPos1;
playerPos1 = position;
position = temp;
}
break;
case 2: //轟炸
if(no == 1){ //no為1并且玩家2位置小于6
//添加代碼實現(xiàn):計算玩家2當前位置
if(playerPos2 6) {
playerPos2 = 0;
}
else {
//添加代碼實現(xiàn):計算玩家2當前位置
playerPos2 -= 6;
}
}
if(no == 2){ //no為2并且玩家1位置小于6
//添加代碼實現(xiàn): 計算玩家1當前位置
if(playerPos1 6) {
playerPos1 = 0;
}
else{
//添加代碼實現(xiàn):計算玩家1當前位置
playerPos1 -= 6;
}
}
break;
}
break;
case 2: //踩到地雷
//添加代碼實現(xiàn):踩到地雷退6步
position -= 6;
System.out.println("~:-( " + "踩到地雷,氣死了...");
break;
case 3: //下一次暫停一次
//添加代碼實現(xiàn):設(shè)置下次暫停擲骰子
goAndStop[no-1] = "off";
System.out.println("~~_~~ 要停戰(zhàn)一局了。");
break;
case 4: //時空隧道
//添加代碼實現(xiàn):進入時空隧道,加走10步
position += 10;
System.out.println("|-P " + "進入時空隧道, 真爽!");
break;
}
//返回此次擲骰子后玩家的位置坐標
if(position 0){
return 0;
}else if(position 99){
return 99;
}else{
return position;
}
}
/**
* 顯示對戰(zhàn)結(jié)果
*/
public void judge(){
//添加代碼
if(playerPos1 playerPos2) {
System.out.println(playerName[0] + "獲得了勝利!");
}
else {
System.out.println(playerName[1] + "獲得了勝利!");
}
}
}
程序入口:
package s1java.t70.qsfxq;
public class StartGane {
public static void main(String[] args) {
Game game = new Game();
game.start();
}
}