導航:首頁 > 編程語言 > 飛行棋java

飛行棋java

發布時間:2022-12-19 06:59:52

1. 怎樣用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 {
}
}
}
}

2. java如何實現多人操作騎士飛行棋

畫MAP類:

package s1java.xmal1;

public class Map {

int[] map=new int[100]; //0:普通
int[] luckyTurn=; //1:幸運輪盤
int[] landMine=;//2:地雷
int[] pause=; //3:暫停
int[] timeTunnel=; //4:時空隧道
//給map[]寫入各種符號
public void createMap(){
for(int i=0;i<luckyTurn.length;i++){
map[luckyTurn[i]]=1;
}
for(int i=0;i<landMine.length;i++){
map[landMine[i]]=2;
}
for(int i=0;i<pause.length;i++){
map[pause[i]]=3;
}
for(int i=0;i<timeTunnel.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;i<end;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;i<end;i++){
for(int j=0;j<73;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;i<end;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==playerPos1&&index==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(position>99){
return 99;
}
switch(map.map[position]){
case 0://普通格
if(no==1&&playerPos2==position){//玩家1與玩家2相遇
playerPos2=0;
System.out.println(":-D 哈哈哈...踩到了!");
}else if(no==2&&playerPos1==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(playerPos2<6){
playerPos2=0;
}else{
playerPos2-=6;
}
}else if(no==2){
if(playerPos1<6){
playerPos1=0;
}else{
playerPos1-=6;
} }
break;

}
break;
case 2://地雷

position-=6;
System.out.println("踩到地雷,氣死了。");
break;
case 3://暫停
goAndStop[no-1]="off";
System.out.println("~~>_<~~ 要停戰一局了。");
break;
case 4://時空隧道
position+=10;
System.out.println("|-P 進入時空隧道真爽!");
break;
}
if(position<0){
return 0;
}else if(position>99){
return 99;
}else{
return position;
}

}
public void judge(){
if(playerPos1>playerPos2){
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(playerPos1<99&&playerPos2<99){
if(goAndStop[0].equals("on")){
step= throwShifter(1);
System.out.println("\n-----------------------");
System.out.println("骰子數"+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("骰子數"+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("// //");
System.out.println("// //");
System.out.println("// 騎士飛行棋 //");
System.out.println("// //");
System.out.println("// //");
System.out.println("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~兩人對戰~~~~~~~~~~~~~~~~~~~~~~~~");
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();
}

}

3. java源碼 飛行棋

這里找到一個,
http://www.longtengwang.com/softcode/java/game/200705/1783.html

閱讀全文

與飛行棋java相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:757
蘋果郵件無法連接伺服器地址 瀏覽:963
phpffmpeg轉碼 瀏覽:672
長沙好玩的解壓項目 瀏覽:145
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:737
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:486
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:382
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:350
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:151
伊克塞爾文檔怎麼進行加密 瀏覽:892
app轉賬是什麼 瀏覽:163