JAVA小游戏骑士飞行棋

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
.print("\n\n************************************************** **\n");
System.out.print(" Game Start \n"); System.out
.print("\n\n************************************************** **\n");
System.out.println("========================================== ==");
System.out.println("欢迎进入幸运轮盘"); System.out.println("请选择一种运气:1、交换位置 2、轰炸对方");
System.out.println("========================================== ==");
*/
public int getCurPos(int no, int position, int step) {
position = position + step;
if (position >= 99) {
return 9Байду номын сангаас;
}
Scanner input = new Scanner(System.in);
}
}else if(choice==2){ if(no == 1 && play2 < 6){ play2 = 0; }else { play2=play2-6; } if(no==2&&play1<6){ play1=0; }else { play1=play1-6; }
} break; case 2:
case 3: playRole[no - 1] = "麦克阿瑟"; break;
case 4: playRole[no - 1] = "巴顿"; break;
} }
//玩家掷骰子操作 public int throwShifter(int no) {
int step = 0; System.out.println("\n\n" + playRole[no - 1] + "请输入\"Y\"开 始掷骰子!"); Scanner input = new Scanner(System.in); String s = input.next(); if (s.equals("y")) {
System.out.println("^_^" + playRole[0] + "的士兵: A"); System.out.println("^_^" + playRole[1] + "的士兵: B"); System.out.println("\n图例: " + "■ 暂停 ¤ 幸运轮盘 ★ 地雷 〓 时 空隧道 ∷ 普通\n"); map.showMap(play1, play2); // 游戏开始
}
/** * 不同关卡在地图上的显示! * @param i * @param index * @param play1 * @param play2 * @return */
public String gerGrap(int i, int index, int play1, int play2) { String grap = ""; if (play1 == index && play2 == index) { grap = "@@"; } else if (play1 == index) { grap = "A"; } else if (play2 == index) { grap = "B"; } else { switch (i) { case 0: grap = "∷"; break; case 1: grap = "¤"; break; case 2: grap = "★"; break; case 3: grap = "■"; break; case 4: grap = "〓"; break; } } return grap;
position = position - 6; System.out.println("踩到地雷了,气死我了!"); break; case 3: goOrStop[no - 1] = "off"; System.out.println("要停战一局了!"); break; case 4: position = position + 10; System.out.println("进入时空隧道真爽!"); break;
int temp; int choice = input.nextInt(); if (choice == 1) {
if(no==1){ temp=position; position=play2; play2=temp;
}else if(no==2){ temp=position; position=play1; play1=temp;
}
}
/// 显示偶数行 public void showLine2(int start, int end, int play1, int play2){
for(int i = end-1 ; i >= start ; i--){ System.out.print(gerGrap(map[i],i,play1,play2));
} }
//显示左竖行 public void showLLine(int start, int end, int play1, int play2){
for(int i = start ; i < end ; i++){
System.out.println(gerGrap(map[i],i,play1,play2)); } }
switch (map.map[position]) {
case 0:
if (no == 1 && play2 == position) {
play2 = 0; System.out.println("哈哈哈~~~~~踩到了,你回去吧"); } if (no == 2 && play1 == position) { play1 = 0; System.out.println("哈哈哈~~~~~踩到了,你回去吧"); } break; case 1:
JAVA 小游戏骑士飞行棋
————人机对战和双人游戏
地图类:
package com.sibin.flyingChess;
public class Map { int[] map = new int[100]; // 对战地图 int[] luckyTurn = { 6, 23, 40, 55, 69, 83 }; // 幸运轮盘 int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 }; // 地雷
///初始化 public void init() {
map = new Map(); map.createMap(); play1 = 0; play2 = 0; goOrStop[0] = "on"; goOrStop[1] = "on"; }
/** * 设置玩家角色 * @param no 玩家次序 * @param role 玩家角色名称 */
/** * 显示当前地图 * @param play1玩家1的当前位置 * @param play2玩家2的当前位置 */
public void showMap(int play1,int play2){ System.out.println("\n图例: " + "■ 暂停 ¤ 幸运轮盘 ★ 地雷 〓 时
}
}
游戏类:
package com.sibin.flyingChess;
import java.util.Scanner;
public class Game { Map map; int play1; int play2; String[] goOrStop = new String[2]; String[] playRole = new String[2];
} }
//显示右竖行 public void showRLine(int start, int end, int play1, int play2){
for(int i = start ; i <= end ; i++){ for(int j = 54 ; j > 0 ; j --){ System.out.print(" "); } System.out.print(gerGrap(map[i],i,play1,play2)); System.out.println();
}
/** * 显示奇数行 * @param start * @param end * @param play1 * @param play2 */
public void showLine1(int start, int end, int play1, int play2) {
for(int i = start; i <=end ; i++){ System.out.print(gerGrap(map[i],i,play1,play2));
} if (position < 0) {
return 0; } else if (position > 99) {
return 99; } return position;
}
/** * 操作游戏玩法 * @param model 对战模式:1、双人对战 2、人机对战! */
public void play(int model) { System.out.println("\n\n\n\n"); System.out
空隧道 ∷ 普通\n"); showLine1(0,30,play1,play2); System.out.println(); showRLine(31,34,play1,play2); showLine2(35,65,play1,play2); System.out.println(); showLLine(65, 68, play1, play2); showLine1(69, 99, play1, play2);
位置 int[] pause = { 9, 27, 60, 93 }; // 暂停 int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 }; // 时空隧道
/** * 给各个关卡赋值 */
public void createMap() { int i = 0; // g各个数组的下标值。 for (i = 0; i < luckyTurn.length; i++) { map[luckyTurn[i]] = 1; } for (i = 0; i < landMine.length; i++) { map[landMine[i]] = 2; } for (i = 0; i < pause.length; i++) { map[pause[i]] = 3; } for (i = 0; i < timeTunnel.length; i++) { map[timeTunnel[i]] = 4; }
step = (int) (Math.random() * 10 % 6 + 1);
} return step; //返回骰子点数 }
/**
* 计算玩家此次移动后的当前位置
*
* @param no
*
玩家次序
* @param position
*
移动前位置
* @param step
*
掷的骰子数目
* @return position 移动后的位置
public void setRole(int no, int role) { switch (role) { case 0: playRole[no - 1] ="电脑"; break; case 1: playRole[no - 1] = "艾森豪威尔"; break; case 2: playRole[no - 1] = "戴高乐"; break;
相关文档
最新文档