




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
package s1java.xmal1;public class Map int map = new int100; /对战地图int luckyTurn = 6, 23, 40, 55, 69, 83; /幸运轮盘 int landMine = 5, 13, 17, 33, 38, 50, 64, 80, 94; /地雷位置int pause = 9, 27, 60, 93; /暂停int timeTunnel = 20, 25, 45, 63, 72, 88, 90; /时空隧道 /* * 生成地图: * 关卡代号为:1:幸运轮盘 2:地雷 3: 暂停 4:时空隧道 0:普通 */ public void createMap() int i = 0; /在对战地图上设置幸运轮盘 for(i = 0; i luckyTurn.length; i+) mapluckyTurni = 1; /添加代码实现在对战地图上设置地雷 for(i = 0; i landMine.length; i+) maplandMinei = 2; /添加代码实现在对战地图上设置暂停 for(i = 0; i pause.length; i+ ) mappausei = 3; /添加代码实现在对战地图上设置时空隧道 for(i = 0; i timeTunnel.length; i+) maptimeTunneli = 4; /* * 显示地图关卡对应的图形 * param i 地图当前位置的关卡代号 * param index 当前地图位置编号 * param playerPos1 玩家1的当前位置 * param playerPos2 玩家2的当前位置 * return 地图当前位置的对应图片 */ public String getGraph(int i, int index, int playerPos1, int playerPos2) String graph = ; if(playerPos1=index&index=playerPos2) graph=; else if(playerPos1=index) graph=; else if(playerPos2=index) graph=; else switch(i) case 1: graph=; break; case 2: graph=; break; case 3: graph=; break; case 4: graph=; break; default: graph=; /添加代码 return graph; /* * 输出地图的奇数行(第1、3行) * param start 输出的起始点在地图上的位置 * param end 输出的结束点在地图上的位置 * param playerPos1 玩家1的当前位置 * param playerPos2 玩家2的当前位置 */ public void showLine1(int start, int end, int playerPos1, int playerPos2) /添加代码 for(int i = start; i = start; i- ) System.out.print(getGraph(mapi, i,playerPos1, playerPos2); /* * 输出地图的右竖列 * param start 输出的起始点在地图上的位置 * param end 输出的结束点在地图上的位置 * param playerPos1 玩家1的当前位置 * param playerPos2 玩家2的当前位置 */ public void showRLine(int start, int end, int playerPos1, int playerPos2) for(int i = start; i 0; j-) /输出29个空格 System.out.print( ); System.out.print(getGraph(mapi, i,playerPos1, playerPos2); System.out.println(); /* * 输出地图的左竖列 * param start 输出的起始点在地图上的位置 * param end 输出的结束点在地图上的位置 * 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(mapi, i,playerPos1, playerPos2); System.out.println(); /* * 显示对战地图 * param playerPos1 玩家1的当前位置 * param playerPos2 玩家2的当前位置 */ public void showMap(int playerPos1, int playerPos2) /显示地图第一行 /换行 /显示地图右竖行 /显示地图第二行 /换行 /显示地图左竖行 /显示地图第3行 showLine1(0, 30, playerPos1, playerPos2); System.out.println(); showRLine(31, 34, playerPos1, playerPos2); showLine2(35, 65, playerPos1, playerPos2); System.out.println(); showLLine(66, 68, playerPos1, playerPos2); showLine1(69, 99, playerPos1, playerPos2); package s1java.xmal1;import java.util.*;public class Game /声明地图Map map; /声明对战中玩家1的当前位置int playerPos1; /声明对战中玩家2的当前位置int playerPos2; /声明走或停标识设置 String goAndStop=new String2; /声明对战角色 String playerName=new String2; /* * 初始化游戏的一局 */ public void init() /创建Map对象 map = new Map(); /生成地图 map.createMap(); /设置玩家1起始位置 playerPos1=0; /设置玩家2起始位置 playerPos2=0; /记录玩家1下一次走或停 goAndStop0=on; /设置玩家2下一次走或停 goAndStop1=on; /* * 开始游戏 */ public void start() /调用初始化方法 init(); /显示游戏界面 System.out.println(); System.out.println(/ /); System.out.println(/ /); System.out.println(/ 骑 士 飞 行 棋 /); System.out.println(/ /); System.out.println(/ /); System.out.println(nnnn); System.out.println(-两 人 对 战-); /角色设置 System.out.println(请选择角色: 1. 戴高乐 2. 艾森豪威尔 3. 麦克阿瑟 4. 巴顿 ); /开始游戏 System.out.print(请玩家1选择角色:); Scanner in=new Scanner(System.in); int role=in.nextInt(); setRole(1, role); System.out.print(请玩家2选择角色:); role=in.nextInt(); setRole(2, role); play(); /* * 设置对战角色 * param no 玩家次序 1:玩家1 2:玩家2 * param role 角色代号 */ public void setRole(int no, int role) switch(role) case 1: playerNameno-1 = 戴高乐; break; case 2: /设置玩家名称为艾森豪威尔 playerNameno-1 = 艾森豪威尔; break; case 3: /设置玩家名称为麦克阿瑟 playerNameno-1 = 麦克阿瑟; break; case 4: /设置玩家名称为巴顿 playerNameno-1 = 巴顿; break; default: break; /* * 两人对战玩法 */ public void play() System.out.println(nnnn); System.out.print(nn*n); System.out.print( Game Start n); System.out.print(*nn); /显示对战双方士兵样式 System.out.println(_ + playerName0 + 的士兵:); System.out.println(_ + playerName1 + 的士兵: n); /显示对战地图 System.out.println(n图例: + 暂停 幸运轮盘 地雷 时空隧道 普通n); map.showMap(playerPos1, playerPos2); /游戏开始 int step; /存储骰子数目 while(playerPos1 99 & playerPos2 = 99) return 99; Scanner input = new Scanner(System.in); switch(map.mapposition) /根据地图中的关卡代号进行判断 case 0: /走到普通格 if(no=1&playerPos2=position) /添加条件:玩家1与对方骑兵相遇 /添加代码实现:踩到对方,对方回到起点 playerPos2=0; System.out.println(:-D 哈哈哈哈.踩到了!); if(no=2&playerPos1=position) /添加条件:玩家2与对方骑兵相遇 /添加代码实现:踩到对方,对方回到起点 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) /添加代码实现交换:position与playerPos2数值互换 temp=position; position=playerPos2; playerPos2=temp; else if(no = 2) /添加代码实现交换:position与playPos1数值互换 temp=position; position=playerPos1; playerPos1=temp; break; case 2: /轰炸 if(no=1&playerPos26) /no为1并且玩家2位置小于6 /添加代码实现:计算玩家2当前位置 playerPos2=0; /实现计算玩家2当前位置 else /添加代码实现:计算玩家2当前位置 playerPos2=playerPos2-6; if(no=2&playerPos16) /no为2并且玩家1位置小于6 /添加代码实现: 计算玩家1当前位置 playerPos1=0; else /添加代码实现:计算玩家1当前位置 playerPos1=playerPos1-6; break; break; case 2: /踩到地雷 /添加代码实现:踩到地雷退6步 if(no=1&playerPos26)playerPos1=position=playerPos1-6;System.out.print(playerName0+:(踩到地雷死了。); else if(no=2&playerPos26)playerPos2=position=playerPos1-6;System.out.print(playerName1+:(踩到地雷死了。); break; case 3: /下一次暂停一次 /添加代码实现:设置下次暂停掷骰子 if(no=1)goAndStop0=off;Syst
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025届春季中国融通集团校园招聘模拟试卷及答案详解(名校卷)
- 未载有消费者权益保护承诺书5篇
- 教室里的那一幕记叙文13篇
- 家庭装饰美化承诺书6篇
- 2025年芜湖安徽工程大学硕士专职辅导员招聘8人考前自测高频考点模拟试题及参考答案详解一套
- 2025河南省中医院(河南中医药大学第二附属医院)招聘博士研究生64人模拟试卷及答案详解(考点梳理)
- 企业员工发展目标设置及跟进模板
- 2025广西梧州学院高层次人才引进考前自测高频考点模拟试题及一套答案详解
- 我和动物的故事作文(8篇)
- 2025广东佛山市中心血站南海血站招聘公益一类事业编制工作人员2人考前自测高频考点模拟试题附答案详解(考试直接用)
- 非遗文化在地方高校美术教育中的应用路径研究
- 七一党课:传承红色基因勇担时代使命2025年建党104周年“七一”专题党课
- 国家科技基础资源调查专项2025项目重要支持方向
- 租赁佣金提成管理制度
- 心理辅导室管理制度
- 工程量清单审核要点
- 2025至2030中国农机市场行业项目调研及市场前景预测评估报告
- 2026版步步高大一轮高考数学复习第一章 §1.6 一元二次方程、不等式含答案
- 2025年成人高考高升专语文全真模拟试卷(含作文范文)真题演练
- 留置导尿考试试题及答案
- 2025-2030铌行业市场现状供需分析及投资评估规划分析研究报告
评论
0/150
提交评论