好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

JAVA小游戏骑士飞行棋.doc

11页
  • 卖家[上传人]:re****.1
  • 文档编号:526718258
  • 上传时间:2024-02-10
  • 文档格式:DOC
  • 文档大小:78.50KB
  • / 11 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 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 }; // 地雷位置 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; } } /** * 不同关卡在地图上的显示! * @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; } /** * 显示奇数行 * @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)); } } /// 显示偶数行 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 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(); } } //显示左竖行 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)); } } /** * 显示当前地图 * @param play1玩家1的当前位置 * @param play2玩家2的当前位置 */ public void showMap(int play1,int play2){ System.out.println("\n图例: " + "■ 暂停 ¤ 幸运轮盘 ★ 地雷 〓 时空隧道 ∷ 普通\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); }}游戏类: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 init() { map = new Map(); map.createMap(); play1 = 0; play2 = 0; goOrStop[0] = "on"; goOrStop[1] = "on"; } /** * 设置玩家角色 * @param no 玩家次序 * @param role 玩家角色名称 */ 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; 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")) { step = (int) (Math.random() * 10 % 6 + 1); } return step; //返回骰子点数 } /** * 计算玩家此次移动后的当前位置 * * @param no * 玩家次序 * @param position * 移动前位置 * @param step * 掷的骰子数目 * @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]) { 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: System.out.println("============================================"); System.out.println("欢迎进入幸运轮盘"); System.out.println("请选择一种运气:1、交换位置 2、轰炸对方"); System.out.println("============================================"); 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; } }else if(choice==2){ if(no == 1 && play2 < 6){ play2 = 0; }else {。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.