中易网

急求骑士飞行棋的代码

答案:1  悬赏:0  
解决时间 2021-02-10 09:37
急求骑士飞行棋的代码
最佳答案
画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;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();
}

}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
解方程组(写出过程):3x+5y=6 6x+15y=16
陇念泻地址在什么地方,想过去办事
马鞍山机动车违反禁令标志怎么处罚
天天炫斗南海祭坛多少战力能打
上秦镇金家湾村卫生室怎么去啊,有知道地址的
王者荣耀黄忠怎么打野 黄忠
爽肤水用英文怎么说阿?
= =。我想问下我笑起来眼角上翘是怎么回事
居尚会所地址有知道的么?有点事想过去
公务员报名时间
抛腹产已经三个月了,为什么伤口还是痒,而且
如果我报考的职位属于那种条件艰苦的岗位就我
唐氏足浴按摩地址有知道的么?有点事想过去
满面桃花开是什么意思
元香饺子馆怎么去啊,有知道地址的么
推荐资讯
随手香-厨师帮餐饮培训做的重庆老火锅味道怎
为什么我在玩DNF时QQ音乐和QQ总卡死
宏鑫油漆店怎么去啊,有知道地址的么
苏州日韩道日语培训怎么样,好不好?
龙门县老区建设研究促进会天堂山镇分会在什么
佳惠超市龙归分店我想知道这个在什么地方
大龙地毯怎么去啊,有知道地址的么
荣宝斋天津分店怎么去啊,有知道地址的么
你,把一根九米长的绳子平均截成十一段,每段
京东换了个新的号码绑定为啥查不到以前的物流
在星雅俊园买了房子,不晓得这边以后逛街方便
ID密码正确,怎么显示如下图,而且家人共享不
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?