骑士飞行棋源代码

合集下载

C#飞行棋源代码

C#飞行棋源代码

C#飞⾏棋源代码1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;56namespace飞⾏棋7 {89class Program10 {11public static int[] maps = new int[100]; //声明⼀个静态数组⽤来存储玩家A跟玩家B的坐标12//两个玩家的坐标13static int[] Players = new int[2];14//存储两个玩家的姓名15static string[] playerNames = new string[2];16//两个玩家的标记,拥有某⼀个玩家暂停17static bool[] GamePause = new bool[2];18static void Main(string[] args)19 {20 GameShow();//调⽤游戏提⽰信息21#region提⽰⽤户输⼊玩家姓名及姓名的判断22 Console.WriteLine("请输⼊玩家A的姓名:");23 playerNames[0] = Console.ReadLine();24while (playerNames[0] == "")25 {26 Console.WriteLine("玩家A的名字不能为空,请重新输⼊");27 playerNames[0] = Console.ReadLine();28 }29 Console.WriteLine("请输⼊玩家B的姓名:");30 playerNames[1] = Console.ReadLine();31while (playerNames[1] == "" || playerNames[1] == playerNames[0])32 {33if (playerNames[1] == "")34 {35 Console.WriteLine("玩家B的名字不能为空,请重新输⼊");36 playerNames[1] = Console.ReadLine();37 }38else39 {40 Console.WriteLine("玩家B的名字不能与玩家A的名字相同,请重新输⼊");41 playerNames[1] = Console.ReadLine();42 }43 }44#endregion45 Console.Clear();//玩家姓名输⼊OK 清屏46 GameShow();47 Console.WriteLine("{0}的⼠兵⽤A表⽰", playerNames[0]);48 Console.WriteLine("{0}的⼠兵⽤B表⽰", playerNames[1]);49 GameMap();//调⽤地图50 ShowMap();//画图51#region玩游戏52while (Players[0] < 99 && Players[1] < 99)53// 当玩家A 和玩家B 么有⼀个⼈到达终点的时候,两个玩家继续玩游戏54 {55if (GamePause[0] == false)56 {57 PlayGame(0);58 }59else60 {61 GamePause[0] = false;62 }63if (Players[0] >= 99)64 {65 Console.WriteLine("玩家{0}⽆耻的赢了玩家{1}", playerNames[0], playerNames[1]);66break;67 }68if (GamePause[1] == false)69 {70 PlayGame(1);71 }72else73 {74 GamePause[1] = false;75 }76if (Players[1] >= 99)77 {78 Console.WriteLine("玩家{0}⽆耻的赢了玩家{1}", playerNames[1], playerNames[0]);79break;80 }81 }//while82#endregion83 Console.ReadKey();//等待84 }85///<summary>86///两个玩家玩游戏87///</summary>88public static void PlayGame(int playNumber)89 {90 Random r = new Random();91int rNumber = r.Next(1, 7);92 Console.WriteLine("玩家{0}按任意键开始郑骰⼦", playerNames[playNumber]);93 Console.ReadKey(true);94 Console.WriteLine("玩家{0}掷骰⼦,掷出了{1}", playerNames[playNumber], rNumber);95 Players[playNumber] += rNumber;96 Console.ReadKey(true);97 Console.WriteLine("玩家{0}:请按任意键开始移动!!!", playerNames[playNumber]);98 Console.ReadKey(true);99 Console.WriteLine("玩家{0}:移动完了", playerNames[playNumber]);100 Console.ReadKey(true);101// 玩家A有可能踩到了B ,空格,幸运轮盘,地雷,暂停,时空隧道102if (Players[playNumber] == Players[1 - playNumber])103 {104 Console.WriteLine("{0}玩家踩到了{1}玩家,{2}玩家退6格", playerNames[playNumber], playerNames[1 - playNumber], playerNames[1 - playNumber]);105 Players[1 - playNumber] -= 6;106 Console.ReadKey(true);107 }108else// 玩家A踩到了关卡109 {110// 玩家的坐标111 changePots();112switch (maps[Players[playNumber]])113 {114case0:115 Console.WriteLine("玩家{0}踩到了⽅块,安全", playerNames[playNumber]);116 Console.ReadKey(true);117break;118119case1:120 Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择:1--交换位置 2--轰炸对⽅", playerNames[playNumber]);121string input = Console.ReadLine();122while (true)123 {124if (input == "1")125 {126 Console.WriteLine("玩家{0}选择与玩家{1}交换位置", playerNames[playNumber], playerNames[1 - playNumber]);127 Console.ReadKey(true);128int temp = Players[playNumber];129 Players[playNumber] = Players[1 - playNumber];130 Players[1 - playNumber] = temp;131 Console.WriteLine("位置交换完成!!!按任意键继续游戏!!!");132 Console.ReadKey(true);133break;134 }135else if (input == "2")136 {137 Console.WriteLine("玩家{0}选择了轰炸玩家{1},玩家{2}倒退6格", playerNames[playNumber], playerNames[1 - playNumber], playerNames[1 - playNumber]); 138 Console.ReadKey(true);139 Players[1 - playNumber] -= 6;140 Console.WriteLine("玩家B倒退6格", playerNames[1 - playNumber]);141break;142 }143else144 {145 Console.WriteLine("只能输⼊1或者2 1--交换位置 2--轰炸对⽅");146 input = Console.ReadLine();147 }148 }149break;150case2:151 Console.WriteLine("玩家{0}踩到了地雷,退6格", playerNames[playNumber]);152 Console.ReadKey(true);153 Players[playNumber] -= 6;154break;155case3:156 Console.WriteLine("玩家{0}猜到了暂停,暂停⼀回合", playerNames[playNumber]);157 GamePause[playNumber] = true;158break;//暂停⼀回合是整个游戏最复杂的逻辑,需要最后再写159case4:160 Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", playerNames[playNumber]);161 Players[playNumber] += 10;162 Console.ReadKey(true);163break;164 }//switch165 }//else166 changePots();167 Console.Clear();// 清屏168 ShowMap();169 }170171///<summary>172///当玩家坐标发⽣改变的时候173///限定玩家不能跳出地图的界限174///</summary>175public static void changePots()176 {177if (Players[0] < 0)178 {179 Players[0] = 0;180 }181if (Players[0] >= 99)182 {183 Players[0] = 99;184 }185if (Players[1] < 0)186 {187 Players[1] = 0;188 }189if (Players[1] >= 99)190 {191 Players[1] = 99;192 }193 }194195///<summary>196///画游戏开头提⽰信息197///</summary>198///199public static void GameShow()200 {201 Console.ForegroundColor = ConsoleColor.Yellow;202 Console.WriteLine("*****************************");203 Console.ForegroundColor = ConsoleColor.Red;204 Console.WriteLine("*****************************");205 Console.ForegroundColor = ConsoleColor.Green;206 Console.WriteLine("**** Weiterli 飞⾏棋V1.0 ****");207 Console.ForegroundColor = ConsoleColor.Red;208 Console.WriteLine("*****************************");209 Console.ForegroundColor = ConsoleColor.Yellow;210 Console.WriteLine("*****************************");211 }212213214//int[] luckyturn={6,23,40,55,69,83};//幸运轮盘215//int[] lanmine ={5,13,17,33,38,50,64,80,94};//地雷☆216//int[]pause={9,27,60,93};//暂停217//int[] timeTunnel={20,25,45,63,72,88,90}//时空隧道218///<summary>219///初始化游戏地图220///(数组长度100,索引 0-99)221///<para>luckyturn幸运轮盘lanMine地雷 pause暂停 timeTunnel时空隧道</para>222///<para>注意:把数组当中的数字转换成控制台中显⽰的特殊字符串的过程就是初始化地图</para> 223///</summary>224public static void GameMap()225 {226int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘227for (int i = 0; i < luckyturn.Length; i++)228 {229// int index = luckyturn[i];230 maps[luckyturn[i]] = 1;231 }232int[] landmine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆233for (int i = 0; i < landmine.Length; i++)234 {235 maps[landmine[i]] = 2;236 }237int[] pause = { 9, 27, 60, 93 };//暂停238for (int i = 0; i < pause.Length; i++)239 {240 maps[pause[i]] = 3;241 }242int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道243for (int i = 0; i < timeTunnel.Length; i++)244 {245 maps[timeTunnel[i]] = 4;246 }247 }248249250///<summary>251///画地图252///</summary>253public static void ShowMap()254 {255 Console.WriteLine("图例:幸运轮盘:◎地雷:☆暂停:▲时空隧道:卐"); 256#region第⼀横⾏257for (int i = 0; i < 30; i++)258 {259 Console.Write(DrawMaps(i));// 画关卡260 }//for261#endregion262 Console.WriteLine();263#region画第⼀个竖⾏264//第⼀竖⾏30-35265for (int i = 30; i < 35; i++)266 {267for (int j = 0; j <= 28; j++)268 {269 Console.Write("");270 }271 Console.Write(DrawMaps(i));272 ;// 画关卡273274 Console.WriteLine();275276 }277#endregion278#region画第⼆横⾏279for (int i = 64; i >= 35; i--)280 {281 Console.Write(DrawMaps(i));282 }283 Console.WriteLine();//画完第⼆横⾏应当换⾏284#endregion285#region画第⼆竖⾏286for (int i = 65; i <= 69; i++)287 {288 Console.WriteLine(DrawMaps(i));289 }290#endregion291#region画第三横⾏292for (int i = 70; i <= 99; i++)293 {294 Console.Write(DrawMaps(i));295 }296 Console.WriteLine();//画完第三横⾏应当换⾏297#endregion298299 }300301302///<summary>303///画关卡的⽅法304///</summary>305///<param name="i"></param>306///<returns></returns>307public static string DrawMaps(int i)308 {309string str = "";310#region画关卡311if (Players[0] == Players[1] && Players[0] == i)312 {313 str = "<>";314 }315else if (Players[0] == i)316 {317 str = "A";318 }319else if (Players[1] == i)320 {321 str = "B";322 }323else324 {325switch (maps[i])326 {327case0:328329 Console.ForegroundColor = ConsoleColor.White;330 str = "□";331break;332case1:333334 Console.ForegroundColor = ConsoleColor.Red;335 str = "◎";336break;337case2:338339 Console.ForegroundColor = ConsoleColor.Green;340 str = "☆";341break;342case3:343 Console.ForegroundColor = ConsoleColor.Yellow; 344 str = "▲";345break;346case4:347 Console.ForegroundColor = ConsoleColor.Blue; 348 str = "卐";349break;350 }//swicth351 }//if352#endregion353return str;354 }355356 }357 }C#飞⾏棋。

java骑士飞行棋 小游戏

java骑士飞行棋 小游戏

突然想起自己刚学java时,老师让写一个java骑士飞行棋,那时候还不知道写,到处问人,勉强写好了,结果全是放在主函数里,今天闲来没事,花了一会,再次写了个骑士飞行棋小游戏,希望对初学者有帮助吧。

代码中,可能用到了初学者还没接触到的东西,不过都不难,注释都有写明,花点时间就能明白的。

一共三个类。

分别:Game.javaMap.javaPlayer.javapackage chou.game.flying;import java.util.Random;import java.util.Scanner;public class Game {private Scanner sc = new Scanner(System.in);private static Map map = new Map();/*** 静态块,初始化地图* 加载时就会被执行的内容* 不理解的,可以在static{}块里打印一句话,看看控制台反映*/static {map.initMap();}/*** 游戏开始*/public void GameStart() {//游戏开始界面welcome();//选择角色,生成对象数组Player [] players = getPlayer();//游戏开始循环,直到有玩家胜出,结束boolean isAnyoneWin = false;while (!isAnyoneWin) {//遍历玩家数组,让每个玩家依次进行掷点for (int i = 0; i < players.length; i++) {//对玩家的状态进行判断,是否处于暂停状态if (players[i].getStatus() == 1) {//如果玩家处于暂停状态,恢复暂停状态并跳过此回合players[i].setStatus(0);statusSay(players[i]);continue;}//判断玩家,手动掷点if (i != 0) {letPlayerRoll(players[i]);}//进行掷点int count = roll();System.out.println(players[i].getName() + " 掷出了 " + count + " 点");//记录玩家roll点前位置和roll点后位置,判断玩家位置是否到达终点players[i].setLastPosition(players[i].getPosition());players[i].setPosition(players[i].getPosition() + count);//判断是否踩中对方int secondNum = Math.abs(1 - i);if (isHit(players[i], players[secondNum])) {players[secondNum].setPosition(0);if (players[i].getLastPosition() != 0) {changMap(players[i].getLastPosition(),players[i].getLastPositionFlag());}}if (checkAnyoneWin(players[i].getPosition())) {isAnyoneWin = true;//打印游戏结束标语gameOver(players[i]);continue;}else {//判断将去位置是否有特殊效果,判断效果之后,理论上来说,应该再次进行判断是否有特殊效果//但我们这里不设这种情出现,因为再来循环的话,代码会更复杂,不利于初学者学习//在这里,我们只判断再进行一次roll点的判定String mapBuff = null;mapBuff = getMapFlag(players[i].getPosition());if (!("=".equals(mapBuff))) {players[i] = checkBuff(players[i], mapBuff);}else if ("*".equals(mapBuff)) {count = roll();players[i].setPosition(players[i].getPosition() + count);}//判断是否踩中对方secondNum = Math.abs(1 - i);if (isHit(players[i], players[secondNum])) {players[secondNum].setPosition(0);if (players[i].getLastPosition() != 0) {changMap(players[i].getLastPosition(), players[i].getLastPositionFlag());}}//记录玩家去的位置的形状,地图复原使用mapBuff = getMapFlag(players[i].getPosition());players[i].setLastPositionFlag(mapBuff);//改变地图上玩家的位置,先复原,再改变//初始位置是为0,所以要判断if (players[i].getLastPosition() != 0) {changMap(players[i].getLastPosition(),players[i].getLastPositionFlag());}//三目运算符,i == 0 是一个布尔式,? 疑问,如果是真,返回:前面的值,如果假,:后面的值mapBuff = i == 0 ? "C" : "P";changMap(players[i].getPosition(), mapBuff);}map.showMap();}}}/*** 判断是否踩中对方* @param first 前面玩家* @param second 后面玩家*/public boolean isHit(Player first,Player second) {boolean temp = false;if (first.getPosition() == second.getPosition()) {temp = true;}return temp;}/*** 玩家掷点阻塞* @param player 玩家信息*/public void letPlayerRoll(Player player) {System.out.println("请玩家 " + player.getName() + " 掷点~");sc.next();}/*** 检查玩家到达的地图位置是否有特殊效果* @param player 玩家* @param mapBuff 地图标识* @return执行过buff后的玩家对象*/public Player checkBuff(Player player,String mapBuff) { if ("-".equals(mapBuff)) {System.out.println(player.getName()+ " 进入黑洞,迷失了方向,后退6步");System.out.println(player.getName() + ":shit!");player.setPosition(player.getPosition() - 6);}else if ("+".equals(mapBuff)) {System.out.println(player.getName() + " 进入时空隧道,前进6步");System.out.println(player.getName() + ":luckily!");player.setPosition(player.getPosition() + 6);}else if ("*".equals(mapBuff)) {System.out.println(player.getName() + " 进行了空间跳跃~再来一次");System.out.println(player.getName() + ":see me fly!");player.setStatus(0);}else if ("^".equals(mapBuff)) {System.out.println(player.getName() + " 抛锚了,暂停一次");System.out.println(player.getName() + ":what is the fuck!");player.setStatus(1);}return player;}/*** 改变地图上玩家的位置* @param position 位置* @param flag 地图形状*/public void changMap(int position, String flag) {if (position < 31) {map.map[0][position - 1] = flag;}else if (position > 30 && position < 36) {map.map[position - 30][29] = flag;}else if (position > 35 && position < 66) {map.map[6][position - 35] = flag;}else if (position > 65 && position < 71) {map.map[position - 59][0] = flag;}else if (position > 70 && position < 101) {map.map[12][position - 71] = flag;}}/*** 暂停言语* @param player 被暂停的玩家*/public void statusSay(Player player) {System.out.println(player.getName() + " 暂停中...........");}/*** 获得地图指定位置的形状* @param position 位置* @return*/public String getMapFlag(int position) {String flag = "=";if (position < 31) {flag = map.map[0][position - 1];}else if (position > 30 && position < 36) {flag = map.map[position - 30][29];}else if (position > 35 && position < 66) {flag = map.map[6][65 - position];}else if (position > 65 && position < 71) {flag = map.map[position - 59][0];}else if (position > 70 && position < 101) {flag = map.map[12][position - 71];}return flag;}/*** 胜利标语* @param player 玩家*/public void gameOver(Player player) {System.out.println("whar a palyer!!");System.out.println(" 玩家 " + player.getName() + " 率先到达终点,获得了胜利");}/*** 判断是否胜利* @param position 位置* @return boolean,temp*/public boolean checkAnyoneWin(int position) {boolean temp = false;temp = position >= 100 ? true : false;return temp;}/*** 掷点* @return int,count 点数*/public int roll () {int count = 0;//产生一个6以内的随机数Random random = new Random();count = random.nextInt(6) + 1;return count;}/*** 选择角色* @return Player [],players 玩家对象数组*/public Player [] getPlayer(){boolean flag = true;//创建对象数组,长度为2,用来接收玩家对象和电脑Player [] players = new Player[2];Player player = new Player();player.setNum(1);Player computer = new Player();while (flag) {String userChoose = sc.next();//获取输入内容,判断是否 1,2,3,根据选择给玩家对象赋名if (!userChoose.matches("[1-3]")) {System.out.println("→ 选择角色失败,请重新选择");} else {switch (Integer.parseInt(userChoose)) {case 1:player.setName("YaGaMi");break;case 2:player.setName("Killer");break;case 3:player.setName("Chou");break;default:break;}System.out.println("→ 你选择了 " + player.getName() + " 作为你的游戏角色");System.out.println("→ 电脑选择了 Fujiwara no Mokou 作为游戏角色" );computer.setName("Fujiwara no Mokou");//数组第1位是玩家,第二位是电脑players[1] = player;players[0] = computer;flag = false;}}return players;}public void welcome() {System.out.println("*********************************");System.out.println("*******欢迎来到飞行棋小游戏*******");System.out.println("*********************************");System.out.println();System.out.println("游戏说明:");System.out.println("地图上随机出现 * - ^ + 四种效果");System.out.println("分别代码:再掷1次,后退6步,暂停1次,前进6步");System.out.println();System.out.println("→ 请选择你的喜欢的游戏角色编号:");System.out.println("1.YaGaMi");System.out.println("2.Killer");System.out.println("3.Chou");}public static void main(String[] args) {new Game().GameStart();}}package chou.game.flying;public class Map {public String [][] map = new String[13][30];public void initMap() {for (int i = 0; i < map.length; i++) {for (int j = 0; j < map[i].length; j++) {if(i == 0 || i == 6 || i == 12 || (i < 6 && j == 29) || (i > 6 && j == 0)){map[i][j] = "=";}else {map[i][j] = " ";}}}map[0][6] = "+";map[0][8] = "-";map[0][15] = "*";map[0][20] = "-";map[0][29] = "^";map[3][29] = "*";map[6][7] = "^";map[6][16] = "+";map[6][20] = "-";map[6][28] = "^";map[10][0] = "*";map[12][7] = "-";map[12][8] = "^";map[12][15] = "-";map[12][20] = "^";map[12][23] = "-";map[12][28] = "-";}public void showMap(){for (int i = 0; i < map.length; i++) {for (int j = 0; j < map[i].length; j++) {if(i == 6){System.out.print(map[i][29-j] + " ");}else {System.out.print(map[i][j] + " ");}}System.out.println();}}public static void main(String[] args) {}}package chou.game.flying;public class Player {private String name;//玩家状态private int status;//玩家当前位置private int position;//玩家上把位置private int lastPosition;//玩家上把位置的地图形状private String lastPositionFlag;//玩家编号private int num;public int getNum() {return num;}public void setNum(int num) {this.num = num;}public String getName() {return name;}public void setName(String name) { = name;}public int getStatus() {return status;}public void setStatus(int status) {this.status = status;}public int getPosition() {return position;}public void setPosition(int position) { this.position = position;}public int getLastPosition() {return lastPosition;}public void setLastPosition(int lastPosition) { stPosition = lastPosition;}public String getLastPositionFlag() {return lastPositionFlag;}public void setLastPositionFlag(String lastPositionFlag) { stPositionFlag = lastPositionFlag;}}。

Python飞行棋游戏代码

Python飞行棋游戏代码

Python飞行棋游戏代码飞行棋游戏涉及到游戏逻辑、界面设计等多个方面,这里仅提供一个简单的Python飞行棋游戏框架,使用pygame库实现。

要运行此代码,请确保已安装pygame库。

import pygameimport sysimport random# 初始化pygamepygame.init()# 设置窗口大小screen_width = 800screen_height = 600screen = pygame.display.set_mode((screen_width, screen_height))# 设置标题pygame.display.set_caption("飞行棋")# 加载背景图片background = pygame.image.load("background.png")# 加载棋子图片player = pygame.image.load("player.png")opponent = pygame.image.load("opponent.png")# 设置棋盘格子大小grid_size = 40# 创建棋盘board = [[0 for _ in range(grid_size)] for _ in range(grid_size)]# 随机放置玩家和对手棋子player_pos = random.randint(0, grid_size - 1), random.randint(0, grid_size - 1)opponent_pos = random.randint(0, grid_size - 1), random.randint(0, grid_size - 1)while player_pos == opponent_pos:opponent_pos = random.randint(0, grid_size - 1), random.randint(0, grid_size - 1)# 将棋子图片放置在棋盘格子上board[player_pos[0]][player_pos[1]] = playerboard[opponent_pos[0]][opponent_pos[1]] = opponent# 游戏主循环turn = 1while True:# 处理事件for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()sys.exit()elif event.type == pygame.MOUSEBUTTONDOWN:x, y = event.posrow, col = x // grid_size, y // grid_sizeif board[row][col] == 0:board[row][col] = turn % 2turn += 1# 清屏screen.blit(background, (0, 0))# 绘制棋盘格子for i in range(grid_size):for j in range(grid_size):pygame.draw.rect(screen, (255, 255, 255), (i * grid_size, j * grid_size, grid_size, grid_size), 1)if board[i][j] == 1:pygame.draw.circle(screen, (0, 0, 255), (i * grid_size + grid_size // 2, j * grid_size + grid_size // 2), 10)elif board[i][j] == 2:pygame.draw.circle(screen, (255, 0, 0), (i * grid_size + grid_size // 2, j * grid_size + grid_size // 2), 10)# 更新屏幕pygame.display.update()请注意,这个代码仅仅实现了一个非常简化的飞行棋游戏,只有一个可以移动的棋子。

java飞行棋实现思路

java飞行棋实现思路

java飞⾏棋实现思路本⽂实例为⼤家分享了java飞⾏棋的注释版,供⼤家参考,具体内容如下可以直接⽤:import java.util.Scanner;public class Fly3 {public static void main(String[] args) {// TODO Auto-generated method stubScanner sc = new Scanner(System.in);int all1 = 0;// 记录A的步数int all2 = 0;// 记录B的步数int flag1 = 1;// 对于A的暂停情况进⾏判断int flag2 = 1;// 对于B的暂停情况进⾏判断int first1 = 0;// 进⾏初始化判断int first2 = 0;System.out.print("|||||||||✈|||||||||||||||||||||||" + "\n||||✈||||||飞⾏棋Beta版||||||||||||\n"+ "|||||||||||||||||||||||||||✈|||||\n"+ "||||||||✈||||||||||||||||||||||||");// 标题显⽰System.out.println();System.out.println();System.out.println();System.out.println("\t}}}}图形展⽰{{{{");System.out.println("✈为传送门,⼀次10格" + "\n 为炸弹,⼀次退回6格" + "\n⚡为被雷劈,⼀次直接返回原点 " + "\n 为幸运轮盘,踩上去可选择相关" + "\n 为暂停,踩上后下⼀次⾏动⽆法进⾏" + "\n注:玩家与玩家的位置相同时,后⼀个玩家将会将上⼀个玩家挤退2格");System.out.println();System.out.println();String A = "玩家A";// ⽤户选择⾓⾊A = login(A);String B = "玩家B";B = login(B);if (A.equals(B)) {B = B + "2号";}maps(icon(all1, all2));for (int i = 0;; i++) {// A玩家视⾓System.out.println(A + "开始投骰⼦");int random1 = (int) (Math.random() * 6 + 1);String msg = sc.nextLine();System.out.println("少⼥祈祷中。

JAVA小游戏骑士飞行棋源码03

JAVA小游戏骑士飞行棋源码03

JA V A小游戏骑士飞行棋源码03游戏过程:package s1java.xmal1;public class Game{//声明地图Map map;//声明玩家1和玩家2int playerPos1 ;int playerPos2 ;//声明走或停标识String[] goAndStop = new String[2];//声明对战角色String[] playerName = new String[2];/*** 初始化游戏的第一局**/public void init(){//新建Map对象map = new Map();//初始化地图map.createMap();//初始化玩家1和玩家2的位置playerPos1 = 0 ;playerPos2 = 0 ;//初始化玩家1和玩家2的走停标识goAndStop[0] = "on";goAndStop[1] = "on";}/*** 设置对战角色* @param no 玩家次序1:玩家1 2:玩家2* @param role 角色代号1:戴高乐2:艾森豪威尔3:麦克阿瑟4:巴顿*/public void setRole(int no , int role){if(no == 1){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;}}if(no == 2){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 void start(){init();}public void}。

骑士漫游源代码

骑士漫游源代码

Dim method(3) As dian, lj(50) As dian, lj2(50) As dianDim herep As dian, nextp As dianDim qidian As dian, zhongdian As dianDim sum As LongDim k As Integer, g As IntegerDim m As Integer, n As IntegerDim ytlj As String, sylj As StringPrivate Sub Command1_Click()Text1.Text = ""ytlj = ""'初始化棋盘的偏移值method(0).xzb = 2: method(0).yzb = 1method(1).xzb = 2: method(1).yzb = -1method(2).xzb = 1: method(2).yzb = 2method(3).xzb = 1: method(3).yzb = -2'初始化棋盘的当前位置herep.xzb = 1: herep.yzb = 1m = Val(InputBox("通过键盘输入棋盘的横坐标n(2-50的整数):", "棋盘的横坐标"))n = Val(InputBox("通过键盘输入棋盘的纵坐标m(2-50的整数):", "棋盘的纵坐标"))If m < 2 Or n < 2 Or m > 50 Or n > 50 ThenMsgBox "输入的数值超出规定范围,请你重新输入!"Elseflag = find(n, m) '在记录集中从头查找符合指定条件的记录, 若找到则将查找到的记录作为当前记录调用find函数,在下面有定义If flag = 1 ThenFor i = 1 To kytlj = ytlj + "(" + Trim(Str(lj(i).xzb)) + "," + Trim(Str(lj(i).yzb)) + ")——>"If i Mod 5 = 0 Then ytlj = ytlj + Chr(13) + Chr(10) '五个点为一行为了简单醒目Next iytlj = ytlj + "(" + Trim(Str(n)) + "," + Trim(Str(m)) + ")" '没有合适的路径的时候呆在原来的位置Else: ytlj = "No" '通过循环查找没有合适的路径,则输出NO End IfText1.Text = ytlj '把找到的路径显示出来,通过五个点为一行显示在文本框中End If '结束路径的查找End Sub'在n×m的棋盘上寻找从左下角到右上角的一条路径Private Function find(n, m) '定义find函数,实现其功能'初始化变量opti(主要是用来标记是哪种走的那一种移动发法)和运用栈顶元素指针kopti = 0: k = 0'能否向下一位置进行移动Do While Not (herep.xzb = n And herep.yzb = m) '不在原地点就可以满足循环的条件Do While opti <= 3r = herep.xzb + method(opti).xzbC = herep.yzb + method(opti).yzbIf r <= n And C <= m And C >= 1 Then Exit Do '满足循环的条件就退出循环查找路径opti = opti + 1 '向下一个位置进行查找另一种路径Loop '结束寻找路径'若可以向下一位置移动,就移动到下一位置If opti <= 3 Thenk = k + 1: lj(k).xzb = herep.xzblj(k).yzb = herep.yzbherep.xzb = r: herep.yzb = Copti = 0'若不能再向下移动,就回溯(回朔就是一直向前走,碰壁就会头)Else'若栈空,则返回0,并结束寻找If k = 0 Thenfind = 0Exit Function '退出这个函数End If'栈顶元素出栈,并存入nextpnextp.xzb = lj(k).xzbnextp.yzb = lj(k).yzbk = k - 1'确定下一种移动方法If herep.xzb - nextp.xzb = 2 ThenIf herep.yzb > nextp.yzb Thenopti = 1Else: opti = 2End IfElseIf herep.yzb > nextp.yzb Thenopti = 3End If'产生新的当前位置herep,把这个位置当做起点在从新找下一个路径herep.xzb = nextp.xzbherep.yzb = nextp.yzbEnd IfLoopfind = 1 '返回true值,则找到路径End FunctionPrivate Sub Command2_Click()Text1.Text = ""n = Val(InputBox("请输入棋盘横坐标n(2-50的整数):", "棋盘横坐标"))m = Val(InputBox("请输入棋盘纵坐标m(2-50的整数):", "棋盘纵坐标"))If m < 2 Or n < 2 Or m > 50 Or n > 50 ThenMsgBox "输入的数超出范围,请你重新输入数值!" '当输入的数超过所规定的数时,程序进行提醒,让用户重新输入Elseqidian.xzb = Val(InputBox("请输入起点的横坐标(小于n):", "起始横坐标")) '输入起始坐标,即棋盘上初始位置qidian.yzb = Val(InputBox("请输入起点的纵坐标(小于m):", "起始纵坐标")) If qidian.xzb > m Or qidian.yzb > n Or qidian.xzb < 1 Or qidian.yzb < 1 ThenMsgBox "起点超出棋盘范围,请重新输入!" '当输入的数超过所规定的数时,程序进行提醒,让用户重新输入Elsezhongdian.xzb = Val(InputBox("请输入终点的横坐标(小于n):", "终点横坐标")) '输入棋盘的最终坐标,也就是终点坐标zhongdian.yzb = Val(InputBox("请输入终点的纵坐标(小于m):", "终点纵坐标"))If zhongdian.xzb > n Or zhongdian.yzb > m Or zhongdian.xzb < 2 Or zhongdian.yzb < 2 ThenMsgBox "终点超出棋盘范围,请重新输入!" '当输入的数超过所规定的数时,程序进行提醒,让用户重新输入Else'初始化路径数目sum = 0'调用函数进行寻找所有的路径Call try(qidian.xzb, qidian.yzb) '调用try函数,并输入起点坐标Text1.Text = "从(" + Trim(Str(qidian.xzb)) + "," + Trim(Str(qidian.yzb)) + ")到(" + _Trim(Str(zhongdian.xzb)) + "," + Trim(Str(zhongdian.yzb)) + ")的路径共有" + Str(sum) + " 种。

java小项目骑士飞行棋(含视频地址)

java小项目骑士飞行棋(含视频地址)

骑士飞行棋骑士飞行棋简介:《骑士飞行棋》又名《别生气》,是一款跟传统的飞行棋一模一样的小游戏。

游戏中每家有4个棋兵,谁4个兵最先到达目的地谁就赢(每一家的目的地各不相同,用颜色区别,大本营是什么颜色目的就是什么颜色)。

当没有活动的兵时,每家可以连续扔3次,直到扔出6点释放出一个兵。

之后每轮只能扔一次,棋兵前进的格数由扔出的点数决定,扔几点就走几步。

无论是前进或者后退,当棋兵最后落脚的地方踩到对方棋兵时,就把对方棋兵轰回老家,当踩到地雷就后退6格,当踩到“¤”时,就进入幸运轮盘,里面有8种运气:前进、后退、交换位置、转移、暂停一轮、奖励一次、设置地雷、轰炸(将对方棋兵炸退6步)。

一、需求分析:1、定义一个类MAP,生成游戏中的地图,地图中包括幸运轮盘“¤”的位置,地雷位置,暂停位置,时候隧道位置。

同时构造成员方法creatMap生成对战图,设置相关的成员变量;构造成员方法getGraph返回地图当前位置的对应图片。

定义构造方法showLine1输出地图的奇数行(第1、3行),定义showLine2输出地图的偶数行(第2行);定义showRLine输出地图的右竖列;定义showLLine输出地图的左数列;最后定义showMap方法显示对战图。

2、定义游戏类Game,定义相关的成员变量,包括对战图map,对战中玩家1的当前位置playerPos1,对战中玩家2的当前位置playerPos2,走或停标识设置goAndStop,对战角色playerName。

构造成员方法init()调用生成地图方法creatMap;开始游戏方法start(),同时构造成员方法setRole设置对战角色。

构造对战玩法的方法play。

其中方法play中调用掷骰子成员方法throwShifter,并返回掷出的骰子数目;构造成员方法getCurPos计算玩家此次移动后的当前位置,返回移动后的位置,构造方法judge 显示对战结果。

飞行棋游戏程序C语言代码

飞行棋游戏程序C语言代码

#include "stdio.h"#include "windows.h"#include "conio.h"#include "stdlib.h"#include "time.h"void restart(int map[100]){intm[100]={100,0,0,0,0,2,1,0,0,3,0,0,0,2,0,0,0,2,0,0,4,0,0,1,0,4,0,3,0,0,0,0,0,2,0,0,0,0,2,0,1,0,0,0,0,4, 0,0,0,0,2,0,0,0,0,1,0,0,0,0,3,0,0,4,2,0,0,0,0,1,0,0,4,0,0,0,0,0,0,0,2,0,0,1,0,0,0,0,4,0,4,0,0,3,2,0,0,0, 0,0 };/*这里是地图代码*/int i;FILE * fp = fopen("map.txt","r");if(fp != 0){printf("找到地图。

尝试加载地图……");for(i=0;i<100;i++){fscanf(fp,"%d",&map[i]);if(map[i] != 0 && map[i] != 1 && map[i] != 2 && map[i] != 3 && map[i] != 4 && map[i] != 10 && map[i] != 20 && map[i] != 100){map[i]=m[i];}}fclose(fp);}else{printf("未找到地图。

加载默认地图中……");for(i=0;i<100;i++)map[i]=m[i];}printf("地图加载完成");Sleep(500);}/*用来给map数组赋值*/ /*用来输出游戏规则*//*用来输出地图*/void printmap(int map[]){int i=0,j=1;printf("'∷'是平地,'¤'是幸运罗盘,'★'是地雷,'■'是暂停,'〓'是时空隧道\n");printf("\n");for(i=0;i<31;i++){switch(map[i]){case 0:printf("∷");break;case 1:printf("¤");break;case 2:printf("★");break;case 3:printf("■");break;case 4:printf("〓");break;case 10:printf("A");break;case 20:printf("B");break;case 100:printf("@@");break;}}printf("\n");for(;i<35;i++){switch(map[i]){case 0:printf("∷\n");break; case 1:printf("¤\n");break; case 2:printf("★\n");break; case 3:printf("■\n");break; case 4:printf("〓\n");break; case 10:printf("A\n");break; case 20:printf("B\n");break; }}for(;i<66;i++){switch(map[66-(j++)]){case 0:printf("∷");break;case 1:printf("¤");break;case 2:printf("★");break;case 3:printf("■");break;case 4:printf("〓");break;case 10:printf("A");break;case 20:printf("B");break;}} printf("\n");for(;i<69;i++){switch(map[i]){case 0:printf("∷\n");break;case 1:printf("¤\n");break;case 2:printf("★\n");break;case 3:printf("■\n");break;case 4:printf("〓\n");break;case 10:printf("A\n");break;case 20:printf("B\n");break;}}for(;i<100;i++){switch(map[i]){case 0:printf("∷");break;case 1:printf("¤");break;case 2:printf("★");break;case 3:printf("■");break;case 4:printf("〓");break;case 10:printf("A");break;case 20:printf("B");break;case 100:printf("@@");break;}}printf("\n");printf("\n");}/*用来输出地图*//* 拟定双人游戏规则及产生走路动画*/int _flash(int map[],int ss,int *pl,int *pl2,int whatplayer) {int i, t;time_t now,d;char c;printf("%d!",ss);Sleep(100);if(whatplayer==1){for(i=0;i<100;i++){if(map[i]==10){map[i]=0;break;}}for(i=1;i<=ss;i++){system("cls");printmap(map);if(*pl+ss>=99 || *pl2+ss>=99){if(*pl+ss>=99){*pl=99;return 0;}else if(*pl2+ss>=99){*pl2=99;return 0;}}t=map[*pl+i]; map[*pl+i]=10; Sleep(100);system("cls");printmap(map);Sleep(100);map[*pl+i]= t;}Sleep(50);system("cls");*pl=*pl+ss;if(map[*pl]==1){printf("恭喜来到幸运罗盘!\n");printf("请做出选择:\n");printf("按1.和对方骑兵交换位置按2.轰炸对方骑兵(炸退六步) 按其他键: 还是算了\n"); c=getch();switch(c){case '1':printf("嗖嗖嗖............\n");Sleep(500);printf("B: \" 怎么回事??\" \n");Sleep(300); t=*pl;*pl=*pl2;*pl2= t;system("cls");Sleep(50);break;case '2':printf("A: \" 炸弹归来...... \" \n");Sleep(500);printf("B: \" 哎呦喂!\" \n");Sleep(300);map[*pl2]=0;*pl2=*pl2-6;if(map[*pl]==map[*pl2]){Sleep(300);printf("B: \" :-D 哈哈哈哈...踩到了! \" \n");Sleep(800);map[0]=20;map[*pl]=0;*pl=0;system("cls");}if(*pl2<0)*pl2=0;system("cls");Sleep(50);break;}}else if(map[*pl]==2){Sleep(300);printf("A: \" ~~:-( 踩到地雷,气死了......\" \n"); Sleep(50);Sleep(300);map[*pl]=0;*pl=*pl-6;if(map[*pl]==map[*pl2]){Sleep(300);printf("A: \" :-D 哈哈哈哈...踩到了! \" \n"); Sleep(800);map[0]=20;map[*pl2]=0;*pl2=0;system("cls");}if(*pl<0)*pl=0;system("cls");}else if(map[*pl]==3){printf("~~>_<~~ 要停战一局了。

c飞行棋

c飞行棋

ch != 2) { Console.WriteLine(&quot;输入错误,只接收 1 或者 2&quot;); int.TryParse(Console.ReadLine(), out ch); } if (ch == 1) { int t; t = p[0]; p[0] = p[1]; p[1] = t; } else { p[(pi == 1) ? 0 : 1] -= 6; if (p[(pi == 1) ? 0 : 1] &lt; 0) p[(pi == 1) ? 0 : 1] = 0; } break; #endregion #region 地雷 2 case 2: Console.Clear(); MakeStarMap(); Console.WriteLine(&quot;NO,竟然是地雷,又要退 后 6 格了 555&quot;);p[pi] -= 6; if (p[pi]&lt; 0) p[pi ] = 0; break;//地雷退后 6 格 #endregion #region 暂停 3 case 3: Console.Clear(); MakeStarMap(); Console.WriteLine(&quot;NO, 竟 然 是 暂 停 &quot;); pi = (pi == 1) ? 0 : 1; Play(ref pi); MakeStarMap(); pi = (pi == 1) ? 0 : 1; break;//使另一个玩家先进行一次,返回后在来一次 #endregion #region 时光隧道 4 case 4 : Console.Clear(); MakeStarMap(); Console.WriteLine(&quot;哈哈, 哥哥穿越了 傻 妞我来了&quot;); int i; for (i = 0; p[pi] != 时光隧道[i]; i++) ; if (i == 时光隧道.Length - 1) p[pi] = 时光隧道[--i]; else p[pi] = 时光隧道[++i]; break; #endregion default: break;//表示为普通

骑士飞行棋——精选推荐

骑士飞行棋——精选推荐

骑⼠飞⾏棋⼀个棋牌类⼩游戏先写⼀个地图类: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}; //时空隧道/*** ⽣成地图:* 关卡代号为:1:幸运轮盘 2:地雷 3: 暂停 4:时空隧道 0:普通*/public void createMap(){int i = 0;//在对战地图上设置幸运轮盘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 playerPos1 玩家1的当前位置* @param playerPos2 玩家2的当前位置* @return地图当前位置的对应图⽚*/public String getGraph(int i, int index, int playerPos1, int playerPos2){String graph = "";//添加代码if(playerPos1 == index && playerPos2 == index)graph = "@@";else if(playerPos1 == index)graph = "A";else if(playerPos2 == index)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;}/*** 输出地图的奇数⾏(第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 < end; i++)System.out.print(getGraph(map[i], i, playerPos1, playerPos2));}/*** 输出地图的偶数⾏(第2⾏)* @param start 输出的起始点在地图上的位置* @param end 输出的结束点在地图上的位置* @param playerPos1 玩家1的当前位置* @param playerPos2 玩家2的当前位置*/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));}}/*** 输出地图的右竖列* @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< end; i++){for(int j = 29; j > 0; j--){ //输出29个空格System.out.print(" ");}System.out.print(getGraph(map[i], 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(map[i], i, playerPos1, playerPos2));System.out.println();}}/*** 显⽰对战地图* @param playerPos1 玩家1的当前位置* @param playerPos2 玩家2的当前位置*/public void showMap(int playerPos1, int playerPos2){//显⽰地图第⼀⾏showLine1(0, 31, playerPos1, playerPos2);//换⾏System.out.println();//显⽰地图右竖⾏showRLine(31, 35, playerPos1, playerPos2);//显⽰地图第⼆⾏showLine2(35, 66, playerPos1, playerPos2);//换⾏System.out.println();//显⽰地图左竖⾏showLLine(66, 69, playerPos1, playerPos2);//显⽰地图第3⾏showLine1(69, 100, playerPos1, playerPos2);}}接下来是游戏类:import java.util.*;public class Game {//声明地图Map map;//声明对战中玩家1的当前位置int playerPos1;//声明对战中玩家2的当前位置int playerPos2;//声明⾛或停标识设置String[] goAndStop = new String[2];//声明对战⾓⾊String[] playerName = new String[2];/*** 初始化游戏的⼀局*/public void init(){//创建Map对象map = new Map();//⽣成地图map.createMap();//设置玩家1起始位置playerPos1 = 0;//设置玩家2起始位置playerPos2 = 0;//记录玩家1下⼀次⾛或停goAndStop[0] = "on";//设置玩家2下⼀次⾛或停goAndStop[1] = "on";}/*** 开始游戏*/public void start(){//调⽤初始化⽅法init();//显⽰游戏界⾯System.out.print("※※※※※※※※※※※※※※※※※※※※※※※※※\n");System.out.println("// //");System.out.println("// //");System.out.println("// 骑⼠飞⾏棋 //"); System.out.println("// //");System.out.println("// //");System.out.print("※※※※※※※※※※※※※※※※※※※※※※※※※\n");System.out.println();System.out.println();System.out.println();System.out.println("~~~~~~~~~~~~~~~~~~两⼈对战~~~~~~~~~~~~~~~~~~~"); System.out.println();System.out.println("请选择⾓⾊: 1. 戴⾼乐 2. 艾森豪威尔 3. 麦克阿瑟 4. 巴顿");//⾓⾊设置System.out.print("请玩家1选择⾓⾊:");Scanner input = new Scanner(System.in);int role1 = input.nextInt();int role2;do{System.out.print("请玩家2选择⾓⾊:");role2 = input.nextInt();}while(role1 == role2);setRole(1, role1);setRole(2, role2);//开始游戏play();}/*** 设置对战⾓⾊* @param no 玩家次序 1:玩家1 2:玩家2* @param role ⾓⾊代号*/public void setRole(int no, int role){switch(role){case 1:playerName[no-1] = "戴⾼乐";break;case 2://设置玩家名称为"艾森豪威尔"playerName[no-1] = "艾森豪威尔";case 3://设置玩家名称为"麦克阿瑟"playerName[no-1] = "麦克阿瑟";case 4://设置玩家名称为"巴顿"playerName[no-1] = "巴顿";default:break;}}/*** 两⼈对战玩法*/public void play(){System.out.println("\n\n\n\n");System.out.print("\n\n****************************************************\n");System.out.print(" Game Start \n");System.out.print("****************************************************\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")){//玩家1掷骰⼦step = throwShifter(1); //掷骰⼦System.out.println("\n-----------------"); //显⽰结果信息System.out.println("骰⼦数: "+ step);playerPos1 = getCurPos(1, playerPos1, step); //计算这⼀次移动后的当前位置System.out.println("\n您当前位置: "+ playerPos1);System.out.println("对⽅当前位置:"+ 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")){//玩家2掷骰⼦step = throwShifter(2); //掷骰⼦System.out.println("\n-----------------"); //显⽰结果信息System.out.println("骰⼦数: "+ step);playerPos2 = getCurPos(2, playerPos2, step); //计算这⼀次移动后的当前位置System.out.println("\n您当前位置: "+ playerPos2);System.out.println("对⽅当前位置:"+ 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.print("****************************************************\n");System.out.print(" Game Over \n");System.out.print("****************************************************\n\n");judge();}/*** 掷骰⼦* @param no 玩家次序* @return step 掷出的骰⼦数⽬*/public int throwShifter(int no){//定义变量存储骰⼦数⽬int step = 0;//提⽰玩家启动掷骰⼦System.out.print("请输⼊任意key并回车开始掷骰⼦:");Scanner input = new Scanner(System.in);input.next();//模拟掷骰⼦:产⽣⼀个1~6的数字作为玩家掷的骰⼦数⽬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 && position == playerPos2){ //添加条件:玩家1与对⽅骑兵相遇 //添加代码实现:踩到对⽅,对⽅回到起点playerPos2 = 0;System.out.println(":-D 哈哈哈哈...踩到了!");}if (no == 2 && position == playerPos1){ //添加条件:玩家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 = playerPos2;playerPos2 = position;position = temp;}else if(no == 2){//添加代码实现交换:position与playPos1数值互换temp = playerPos1;playerPos1 = position;position = temp;}break;case 2: //轰炸if(no==1 && playerPos2<6){ //no为1并且玩家2位置⼩于6//添加代码实现:计算玩家2当前位置playerPos2 = 0;}else{//添加代码实现:计算玩家2当前位置playerPos2 -= 6;}if(no==1 && playerPos1<6){ //no为2并且玩家1位置⼩于6//添加代码实现: 计算玩家1当前位置playerPos1 = 0;}else{//添加代码实现:计算玩家1当前位置playerPos1 -= 6;}break;}break;case 2: //踩到地雷//添加代码实现:踩到地雷退6步position -= 6;System.out.println("~:-( " + "踩到地雷,⽓死了...");break;case 3: //下⼀次暂停⼀次//添加代码实现:设置下次暂停掷骰⼦goAndStop[no-1] = "off";System.out.println("~~>_<~~ 要停战⼀局了。

骑士飞行棋

骑士飞行棋

开发一款C语言小游戏——骑士飞行棋第一部分案例描述案例目的加强对C语言的理解,加强使用数组、链表等操作;学习游戏开发过程。

案例难度★★★★案例覆盖技能点1、使用基本语句语法2、常用函数的使用3、数组使用4、加深对链表的理解推荐案例完成时间5天适用课程和对象C语言编程基础第二部分需求和开发环境使用技术和开发环境C语言、VC6需求分析游戏规则和传统的飞行棋一样,支持两人对战采用100格小型游戏棋盘游戏规则:对战双方轮流掷骰子控制自己的骑兵前进或后退,在游戏棋盘上设置有关卡普通地雷暂停时空隧道幸运轮盘(提供两种运气:交换位置和轰炸)棋盘上的关卡只在骑兵第一次移动遇到时有效设计1.棋盘示例:2.地图的实现:地图信息以整型数据存储在数组中地图显示思路:将对战地图划分成4个部分分别显示奇数行:顺序输出地图数组中代号对应图像右竖行:先输出空格,再输出数组中代号对应图像偶数行:逆序输出地图数组中代号对应图像3.游戏控制两个玩家轮流掷骰子,如果上轮走到暂停关卡,停掷一次部分伪代码示例://显示游戏开始while(玩家一的步数< 99 && 玩家二步数< 99){ //任意一个人走到终点,跳出循环//玩家1掷骰子if(首先判断是否是暂停)){//掷骰子获得移动的步数//移动if(玩家一的步数== 99){ //走到终点break; //退出}}else{//提示此轮停掷设置状态为停掷状态; //设置下次状态}//玩家2 掷骰子……}//显示游戏结束并进行评判4.实现游戏规则关键:当移动到某一点遇到关卡时,怎么办?前进?后退?停止?……部分伪代码示例:switch(i){case 0: //普通格if(对方在此格){//对方被炸回起点}case 1: //幸运轮盘//选择和对方交换位置——做交换//选择轰炸对方——对方退6步case 2: //地雷//退后6步case 3: //暂停键//设置状态变量为暂停,标识下轮暂停case 4: //时空隧道//再前进10步}界面示例起始游戏页面:根据用户的选择,以游戏规则为基础程序做出相应的提示。

java小项目 类与 对象 骑士飞行棋代码

java小项目  类与 对象 骑士飞行棋代码

/**主体方法import java.util.Random;import java.util.Scanner;public class Game {public Map map;Scanner in = new Scanner(System.in);Random run = new Random();static private int[][] temp = { { 0, 0 }, { 0, 0 } };// 分别记录玩家的// 位置.........用来标记人所代替的位置// 之前的状态private String[] name = { "张飞", "关羽", "赵云", "刘备" };private static String[] palyer = new String[2];private int[] p = { 12, 12 };// 暂停标准相差数即为暂停次数private static boolean falg;// 轰炸标记public Game() {map = new Map();}/*** 选择玩家** @return*/public void choice() {System.out.println("------------------------------------------------------------------------------");System.out.println("------------------------------------------------------------------------------");System.out.println("------------------------------------------------------------------------------");System.out.println("---------------骑士飞行棋---------------------");System.out.println("------------------------------------------------------------------------------");System.out.println("------------------------------------------------------------------------------");System.out.println("------------------------------------------------------------------------------");System.out.print("分别选择角色:");for (int i = 0; i < name.length; i++)System.out.print(i + 1 + "." + name[i] + "\t");System.out.println();System.out.println("玩家一:");int n = in.nextInt();palyer[0] = name[n - 1];System.out.println("玩家二:");n = in.nextInt();palyer[1] = name[n - 1];}/*** 色子** @return*/public int stochastic() {int n = run.nextInt(6) + 1;return n;}/*** 初始作用** @param num*/public void person(int num) {// num人的编号if (p[num] < p[1 - num]) {System.out.println(palyer[num] + "暂停" + palyer[1 - num] + "继续");p[num] += 1;person(1 - num);;}// 暂停map.showMap(map.getMap());map.getMap()[temp[num][0]] = temp[num][1];// 人走只后坐标恢复原来的//System.out.println("按任意键开始");System.out.println(palyer[num] + "开走...............");//int mm = in.nextInt();int t = stochastic();System.out.println(palyer[num] + "向前迈了" + t + "个步子.......");palyGame(temp[num][0] += t, num);// 返回人得到随机数的位子return;}/**** 运行游戏** @param n* @param num*/public void palyGame(int n, int num) {// n 随机数+人的初始位置num 表示人switch (map.getMap()[n]) {case 1:System.out.println(palyer[num] + "真悲剧..........碰到了地雷了退"+ (n - 6 > 0 ?6 : n - 1) + "步");palyGame(temp[num][0] = n - (n - 6 > 0 ? 6 : n - 1), num);break;case 2:System.out.println(palyer[num] + "运气真差遇到定身符了暂停一次");p[num] -= 1;temp[num][1] = map.getMap()[n];map.getMap()[n] = 6 - num;System.out.println(palyer[num] + "走到了" + n + "步");break;case 3:System.out.println(palyer[num] + "运气真好步进入时空隧道");for (int i = n + 1; i < map.getMap().length-20; i++) {if (map.getMap()[i] == 3) {temp[num][1] = map.getMap()[i];map.getMap()[i] = 6 - num;temp[num][0] = i;System.out.println(palyer[num] + "走到了" + i + "步");break;}if (i == map.getMap().length - 1-20) {System.out.println("你的时空隧道已是最后一个");System.out.println(palyer[num] + "走到了" + n + "步");temp[num][1] = map.getMap()[n];map.getMap()[n] = 6 - num;break;}}break;case 4:System.out.println(palyer[num] + "运气真好得到幸运盘...");lucky(n, num);return;case 5:if (5 + num == 6) {System.out.println(palyer[num] + "走到了" + n + "步");break;} else {System.out.println(palyer[num] + "真悲剧..........碰到了"+ palyer[1 - num] + "了退" + (n - 6 > 0 ? 6 : n - 1)+ "步");palyGame(temp[num][0] = n - (n - 6 > 0 ? 6 : n - 1), num);}break;case 6:if (6 + num == 6) {System.out.println(palyer[num] + "走到了" + n + "步");break;} else {System.out.println(palyer[num] + "真悲剧..........碰到了"+ palyer[1 - num] + "了退" + (n - 6 > 0 ? 6 : n - 1)+ "步");palyGame(temp[num][0] = n - (n - 6 > 0 ? 6 : n - 1), num);}break;default:System.out.println(palyer[num] + "走到了" + n + "步");temp[num][1] = map.getMap()[n];map.getMap()[n] = 6 - num;break;}if (falg) {falg = false;return;}}/*** 幸运转盘** @param person*/public void lucky(int mm, int num) {System.out.println("1轰炸.\t2.交换位置");int n = in.nextInt();if (n == 1) {temp[num][1] = map.getMap()[mm];map.getMap()[mm] = 6 - num;System.out.println(palyer[num] + "走到了" + mm + "步");num = num == 1 ? 0 : 1;map.getMap()[temp[num][0]] = temp[num][1];temp[num][0] = temp[num][0]- (temp[num][0] - 6 > 0 ? 6 : temp[num][0] - 1);temp[num][1] = map.getMap()[temp[num][0]];falg = true;palyGame(temp[num][0], num);return ;} else {temp[num][1] = map.getMap()[mm];map.getMap()[mm] = 6 - num;String str;str = palyer[0];palyer[0] = palyer[1];palyer[1] = str;map.setFf(!map.getFf());System.out.println(palyer[1 - num] + "与" + palyer[num] + "互换位置");person(num);return;}}/****/public void palyShow(int num){if (p[num] < p[1 - num]) {p[num] += 1;person(1 - num);}person(num);// 暂停if (temp[num][0]>= 100) {System.out.println(palyer[num] + "赢得比赛");System.out.println("-----------------------------------------------GAMEOVER-----------------------------------------------");return;}palyShow(1-num);}}/**地图;import java.util.Arrays;import java.util.Random;public class Map {int[] map = new int[130];private boolean ff;{for (int i = 3; i < map.length; i++) {Random run = new Random();map[i] = run.nextInt(10);switch (map[i]) {case 1:map[i] = 1;break;case 3:map[i] = 2;break;case 5:map[i] =3;break;case 8:map[i] =4;break;default:map[i] = 0;}}}/*** 设置游戏数据** @param map*//** public void setMap(int map[]){ for(int i=0;i<map.length;i++) * this.map[i]=map[i]; }*//*** 得到游戏数组** @return*/public int[] getMap() {return map;// Arrays.copyOfRange(map,0,map.length);}/*** 显示游戏界面动态地图.....................** @param map*/// public void showMap(int[] map){// int start=0,end=48;// int falg1=4,falg2=2,i;// while(end<map.length){// for( i=start;i<end;i++){// if(falg1==1&&falg2==1){// for(int j=start;j<end;j++){System.out.print("--------");}// show(map[i]);// System.out.println();// }// else {show(map[i]);// if(falg1==1&&falg2==2) {System.out.println();}// }// }// if(falg1==4) System.out.println();// start=end;end+=48/falg1;// falg1=falg1==4?1:4;// if(falg1==1) falg2=falg2==2?1:2;// }// }/*** 固定地图** @param map*/public void showMap(int[] map) {int i;for (i = 0; i < 30; i++)show(map[i]);System.out.println();for (i = 30; i < 35; i++) {for (int j = 0; j < 30; j++)System.out.print("--");show(map[i]);System.out.println();}for (i = 64; i >= 35; i--)show(map[i]);for (i = 65; i < 70; i++) {show(map[i]);System.out.println();}for (i = 70; i < 100; i++)show(map[i]);System.out.println();System.out.println("----------------------------------------------------------------------------------------------------------------------");}/*** 根据输入的数字判断输出什么** @param n* @@ 两人重合时A玩家1 B玩家2 ¤幸运轮盘★地雷■ 暂停〓时空隧道∷普通格*/public void show(int n) {switch (n) {case 1:System.out.print("★");break;// 地雷case 2:System.out.print("■");break;// 暂停case 3:System.out.print("〓");break;// 时空隧道case 4:System.out.print("¤");break;// 幸运转盘case 5:if (ff)System.out.print("A");elseSystem.out.print("B");break;// 玩家1case 6:if (ff)System.out.print("B");elseSystem.out.print("A");break;// 玩家2case 7:System.out.print("0");break;// 玩家在一起default:System.out.print("::");break;// 通道}}void setFf(boolean ff) {this.ff = ff;}public boolean getFf() {// TODO Auto-generated method stubreturn ff;}}/**运行主函数public class StartGame {static Game game = new Game();public static void Main() {int num = 0;game.choice();game.palyShow(num);}public static void main(String[] s) { Main();}}。

飞行棋的代码

飞行棋的代码

飞行棋的代码#include#include#include#include#include#include "windows.h"char Player1[10]; //玩家1姓名char Player2[10]; //玩家2姓名char Name1[10]="Sun"; //可选择的玩家姓名char Name2[10]="Lun";char Name3[10]="Run";char Name4[10]="Aun";int Player1X=11; //玩家1,X的坐标int Player1Y=0; //玩家1,Y的坐标int Player2X=11; //玩家2,X的坐标int Player2Y=0; //玩家2,Y的坐标int n=0; //记录掷骰子的局数int Map[13][30]={1,1,1,5,1,1,1,3,1,1,1,1,1,5,1,1,1,1,1,1,1,4,1,1,1,1,1,1,3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,1,1,3,1,1,1,1,1,2,1,1,1,1,3,5,1,1,1,1,1,4,1,1,1,5,1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,4,1,1,5,1,1,1,1,4,1,1,3,1,1,1,1,1,1,4,1,1,1,3,1,1,1,1};//地图的数组//使走过的关卡变成道路void GoToXYSpace(int x, int y){COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut, pos);printf("::");}//闯关完成的提示void GoToXYEnd(int x, int y,int i){COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut, pos);printf("玩家%d闯关成功",i);}//抹掉幸运轮盘底部的提示void GOT oK(int x, int y){COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut, pos);printf(" \n");}//地图底部的提示void GoToPrompt(int x, int y,int num1,int num2,int i ){COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut, pos);fflush(stdin);printf("玩家%d掷出了%d点按回车键继续.第%d回合玩家%d掷骰子",num2,i,n,num1);}//停止关卡的提示void GoToStop(int x, int y,int num){COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut, pos);fflush(stdin);printf("按回车键继续.第%d回合玩家%d此回合停止",n,num);}//玩家1的打印void GoToXYP1(int x, int y)//玩家1{COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut, pos);printf("%c%c",Player1[0],Player1[0]);}//玩家2的打印void GoToXYP2(int x, int y)//玩家2{COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut, pos);printf("%c%c",Player2[0],Player2[0]);}//幸运轮盘的提示void GoToLuck(int x, int y){COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut, pos);fflush(stdin);printf("恭喜你可以实现一个愿望,请选择:\n");printf(" 1.与对方交换位置\n");printf(" 2.轰炸对方使其退后6步\n");printf(" 请选择:");}//游戏开始的提示void GoToStart(int x, int y)//开始{COORD pos = {x,y};HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut, pos);fflush(stdin);printf("按回车键开始.玩家1开始掷骰子");}//产生随机数int Random(){srand(time(NULL));return (rand()%6+1);}//对玩家1的各种判断void Dice1(int i){if(Player1X==Player2X&&Player1Y==Player2Y) GoToXYP2(Player1X,Player1Y);elseGoToXYSpace(Player1X,Player1Y);//打印道路Map[Player1Y][(Player1X-11)/2]=1;if(Player1X<69&&Player1Y==0)//第一横行{Player1X+=i*2;if(Player1X>69){Player1Y+=(Player1X-69)/2;Player1X=69;}GoToXYP1(Player1X,Player1Y);}else if(Player1X==69&&Player1Y<=6)//第一竖行{Player1Y+=i;if(Player1Y>6){Player1X-=(Player1Y-6)*2;Player1Y=6;}GoToXYP1(Player1X,Player1Y);}else if(Player1X<69&&Player1Y==6)//逆行{Player1X-=i*2;if(Player1X<11){Player1Y+=(11-Player1X)/2;Player1X=11;}GoToXYP1(Player1X,Player1Y);}else if(Player1X==11&&Player1Y>=6)//第二竖行{Player1Y+=i;if(Player1Y>12){Player1X+=(Player1Y-12)*2;Player1Y=12;}GoToXYP1(Player1X,Player1Y);}else if(Player1X<=69&&Player1Y==12)//最后一行{ Player1X+=i*2;if(Player1X>69)Player1X=69;GoToXYP1(Player1X,Player1Y);}}//对玩家2的各种打印,步骤如玩家1void Dice2(int i){if(Player1X==Player2X&&Player1Y==Player2Y) GoToXYP1(Player2X,Player2Y);elseGoToXYSpace(Player2X,Player2Y);Map[Player2Y][(Player2X-11)/2]=1;if(Player2X<69&&Player2Y==0){Player2X+=i*2;if(Player2X>69){Player2Y+=(Player2X-69)/2;Player2X=69;}GoToXYP2(Player2X,Player2Y);}else if(Player2X==69&&Player2Y<=6) {Player2Y+=i;if(Player2Y>6){Player2X-=(Player2Y-6)*2;Player2Y=6;}GoToXYP2(Player2X,Player2Y);}else if(Player2X<69&&Player2Y==6)//逆行{Player2X-=i*2;if(Player2X<11){Player2Y+=(11-Player2X)/2;Player2X=11;}GoToXYP2(Player2X,Player2Y);}else if(Player2X==11&&Player2Y>=6) {Player2Y+=i;if(Player2Y>12){Player2X+=(Player2Y-12)*2;Player2Y=12;}GoToXYP2(Player2X,Player2Y);}else if(Player2X<=69&&Player2Y==12) {Player2X+=i*2;if(Player2X>69)Player2X=69;GoToXYP2(Player2X,Player2Y);}}//地图的打印void PrintMap(int Map[][30]){int i,j;for(i=0;i<13;i++)for(j=0;j<30;j++){if(j==0)printf(" ");switch(Map[i][j]){case 0: printf(" ");break;case 1: printf("::");break;case 2: printf("¤");break;case 3: printf("★");break;case 4: printf("■");break;case 5: printf("〓");break;}if(j==29)printf("\n");}}//开始界面的打印void Printstart(){printf(" |¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤|\n"); printf(" | |\n");printf(" |骑士飞行棋|\n");printf(" | |\n");printf(" |¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤|\n"); printf("\n 两人对战\n\n");printf("请选择角色:1.Sun \n"); printf(" 2.Lun \n");printf(" 3.Run \n");printf(" 4.Aun ");}//游戏说明的打印void PrintEx(){printf(" |¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤|\n");printf(" | |\n");printf(" |游戏说明|\n");printf(" | |\n");printf(" |¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤|\n");printf(" 玩家选择的角色以两个首字母为代表如Saber(SS)\n"); printf(" \n图标::代表普通道路\n");printf(" \n图标■代表暂停一回合掷骰子\n");printf(" \n图标★代表地雷踩中退后6步\n");printf(" \n图标¤代表幸运轮盘可选择与对方互换或轰炸对方\n"); printf(" \n图标〓代表时空隧道前进10步\n");printf(" \n地图共100步,谁率先到达终点则胜利\n");printf(" 按回车键开始游戏:");}//角色的选择void Select(){int i;printf("\n请玩家1选择角色:");scanf("%d",&i);if(i==1)strcpy(Player1,Name1);else if(i==2)strcpy(Player1,Name2);else if(i==3)strcpy(Player1,Name3);else if(i==4)strcpy(Player1,Name4);printf("\n请玩家2选择角色:");scanf("%d",&i);if(i==1)strcpy(Player2,Name1);else if(i==2)strcpy(Player2,Name2);else if(i==3)strcpy(Player2,Name3);else if(i==4)strcpy(Player2,Name4);}//主函数int main(){system("color a");char ch;Printstart(); //打印开始Select(); //角色system("cls"); //清屏PrintEx();ch=getch();system("cls");PrintMap(Map); //打印地图while(1){n++;//记录局数int i,j,a;if(Player1X==11&&Player1Y==0)//开始提示的条件{GoToStart(11,15);ch=getch();}if(Map[Player1Y][(Player1X-11)/2]==4)//是否暂停{Map[Player1Y][(Player1X-11)/2]=1;GoToStop(11,15,1);getchar();GoToPrompt(11,15,2,1,i);getchar();}else{i=Random();Dice1(i);if(Player1X==69&&Player1Y==12)//是否到终点{GoToXYEnd(24,20,1);getchar();return 0;}GoToPrompt(11,15,2,1,i);if(Map[Player1Y][(Player1X-11)/2]==5)//是否时空隧道{ i=10;Dice1(i);}if(Map[Player1Y][(Player1X-11)/2]==3)//炸弹{i=-6;Dice1(i);}if(Map[Player1Y][(Player1X-11)/2]==2)//幸运轮盘{GoToLuck(11,16);scanf("%d",&j);if(j==1){a=Player1X;Player1X=Player2X;Player2X=a;a=Player1Y;Player1Y=Player2Y;Player2Y=a;GoToXYP1(Player1X,Player1Y); GoToXYP2(Player2X,Player2Y);}if(j==2){i=-6;Dice2(i);}GOT oK(10,16);GOT oK(10,17);GOT oK(10,18);GOT oK(10,19);}getchar();}if(Map[Player2Y][(Player2X-11)/2]==4) {Map[Player2Y][(Player2X-11)/2]=1; GoToStop(11,15,2);getchar();GoToPrompt(11,15,1,2,i);}else{i=Random();Dice2(i);if(Player2X==69&&Player2Y==12) {GoToXYEnd(24,20,2);getchar();return 0;}GoToPrompt(11,15,1,2,i);if(Map[Player2Y][(Player2X-11)/2]==5) {i=10;Dice2(i);}if(Map[Player2Y][(Player2X-11)/2]==3) {i=-6;Dice2(i);}if(Map[Player2Y][(Player2X-11)/2]==2) {GoToLuck(11,16);scanf("%d",&j);getchar();if(j==1){a=Player1X;Player1X=Player2X;Player2X=a;a=Player1Y;Player1Y=Player2Y;Player2Y=a;GoToXYP1(Player1X,Player1Y); GoToXYP2(Player2X,Player2Y); }if(j==2){i=-6;Dice1(i);}GOT oK(10,16);GOT oK(10,17);GOT oK(10,18);GOT oK(10,19);}getchar();}}}。

飞行棋CocosCreatorTypeScript

飞行棋CocosCreatorTypeScript

飞行棋CocosCreatorTypeScript 飞行棋是一款经典的桌面游戏,在不同地区有着不同的名称,比如天地人、飞机棋等。

随着技术的进步,飞行棋也进入了电子游戏的领域。

本文将介绍如何使用CocosCreator和TypeScript来开发一款飞行棋游戏。

一、概述飞行棋是一种多人对战的棋盘游戏,玩家通过投掷骰子并按照点数前进相应的步数,目标是第一个到达终点。

游戏中还设有一些特殊点,玩家经过这些点时会触发不同的事件,增加游戏的趣味性。

二、游戏规则1. 游戏初始化游戏开始时,每个玩家的棋子都位于起点位置,玩家按照顺时针的方式进行游戏。

2. 投掷骰子玩家轮流掷骰子,每次掷骰子后,可以向前移动相应步数的格子。

3. 目标和终点玩家的目标是尽快到达终点,终点位置由每个玩家的起点位置加上固定的步数得到。

4. 特殊点游戏棋盘上有一些特殊的点,玩家经过这些点时会触发不同的事件,比如前进或后退若干步,交换位置等。

三、开发环境准备在开始开发之前,我们需要准备好开发环境。

首先,确保已安装CocosCreator和Node.js。

然后,创建一个新的CocosCreator项目,选择TypeScript作为开发语言。

四、游戏界面设计1. 棋盘背景游戏的主界面是一个棋盘背景,可以使用CocosCreator的Sprite 组件加载一个棋盘背景图片,或者绘制一个棋盘背景精灵。

2. 棋子每个玩家都有一个棋子,可以使用精灵或者动画来表示。

通过控制棋子的位置来实现前进或者后退的效果。

3. 骰子游戏中需要一个骰子来掷出点数,可以使用按钮或者点击屏幕的方式来模拟掷骰子的动作。

在TypeScript中,可以使用事件监听来实现这一功能。

五、游戏逻辑实现在游戏逻辑实现中,可以使用TypeScript来管理游戏的状态和玩家的操作。

以下是一些主要的逻辑实现步骤:1. 游戏初始化在游戏开始时,需要初始化游戏的状态,包括玩家的初始位置、当前玩家等信息。

骑士飞行棋Java编程演示

骑士飞行棋Java编程演示

你踩到地雷了 自己倒退 步 你踩到地雷了,自己倒退6步. 地雷



暂停设置
踩到暂停,暂停一次. 踩到暂停,暂停一次 暂停 一次
程序: 程序:
player[ currentPlayer ].setStop( true );


∷ ◎ ★ ■ 〓

∷ ◎ ★ ■ 〓

∷ ◎ ★ ■ 〓

§
转盘设置
74 … 100
明白了,开始游戏吧! 明白了,开始游戏吧!

①②
玩家进入
……
∷ ◎ ★ ■ 〓 ∷ ∷ ∷ ∷
普 转 地 暂 隧 通 盘 雷 停 道
∷ ∷ ◎ ★ ■ 〓
∷ 〓 ■ ★ ◎ ∷ ∷ ∷ ∷ ∷ ∷ ∷ ∷ ∷ ◎ ★ ■ 〓 ∷ ∷ ∷ ∷
……
∷ ∷
给你们骰子! 给你们骰子!
你们熟悉下地图! 你们熟悉下地图!
……

§
公平游戏!不准作弊! 公平游戏!不准作弊!
你们~~~ 我会根据地图设置来奖励和惩罚你们
玩家② 玩家②说, 他不懂规则, 给他看… 他不懂规则,让我示范给他看 等等… 等等 ???
也好! 也好! 开始吧! 开始吧!
①②
∷ ◎ ★ ■ 〓

∷ ◎ ★ ■ 〓

∷ ◎ ★ ■ 〓

§
先看掷骰子

玩家①示范 玩家①
掷 骰 子
public int throwShift() { int step = 0; Scanner input = new Scanner(System.in); input.next(); step = (int) (Math.random() * 6) + 1; return step; }

C#实现飞行棋小游戏

C#实现飞行棋小游戏

C#实现飞⾏棋⼩游戏本⽂实例为⼤家分享了C#实现飞⾏棋⼩游戏的具体代码,供⼤家参考,具体内容如下逻辑图以下是掷⾊⼦的⼀个代码,⽐较有代表性,⾥⾯的逻辑和内容都已注释,可通过注释了解这⼀⽅法的运作模式。

public static void RowTouZi(int playerPos) //掷⾊⼦{//产⽣随机数,掷⾊⼦的随机数Random r = new Random();int num = r.Next(1, 7);//定义⼀个字符串变量string msg = "";//提⽰⽤户信息Console.WriteLine("{0}按任意键开始掷⾊⼦", PlayerNames[playerPos]);//不显⽰⽤户按下的任意键Console.ReadKey(true);//根据不同的变量的值显⽰不同的情况Console.WriteLine("{0}掷出了{1}", PlayerNames[playerPos], num);//提⽰⽤户谁开始⾏动了Console.WriteLine("{0}按任意键开始⾏动...", PlayerNames[playerPos]);Console.ReadKey(true);//⽤户的坐标开始改变PlayerPos[playerPos] += num;//判断两个⽤户坐标可能出现的问题(重叠的问题)if (PlayerPos[playerPos] == PlayerPos[1- playerPos]){msg=string.Format("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerNames[playerPos], PlayerNames[1- playerPos], PlayerNames[1 - playerPos]); PlayerPos[1- playerPos] -= 6;}else{//检查是否出界CheckPos();switch (Map[PlayerPos[playerPos]]){//没有障碍case 0:msg ="⾏动完了";break;//踩到幸运轮盘case 1:msg = string.Format("{0}⾛到了幸运轮盘,请选择1--交换位置,2---轰炸对⽅", PlayerNames[playerPos]);//进⾏选择,调⽤Readint⽅法,只可以让⽤户输⼊1或2;int number = ReadInt(msg, 1, 2);//进⾏判断⽤户选择的哪个⽅案,进⾏执⾏相应的代码if (number == 1){//交换位置int temp = 0;temp = PlayerPos[playerPos];temp = PlayerPos[playerPos];PlayerPos[playerPos] = PlayerPos[1- playerPos];PlayerPos[1- playerPos] = temp;msg=string.Format("玩家{0}选择了玩家{1}交换位置", PlayerNames[playerPos], PlayerNames[1- playerPos]);}else{PlayerPos[1- playerPos] = 0;msg = string.Format("玩家{0}选择了轰炸玩家{1}", PlayerNames[playerPos], PlayerNames[1- playerPos]);}break;//踩到地雷了case 2:msg="踩到地雷了,后退6步";//坐标后退6PlayerPos[playerPos] -= 6;//检查是否出界CheckPos();break;//踩到暂停了case 3:msg ="踩到暂停了";//将flag数组中的false,改为true,执⾏true相应的代码flag[playerPos] = true;break;//踩到了时空隧道case 4:msg = string.Format("恭喜你,踩到时空隧道,前进10步");//坐标前进10PlayerPos[playerPos] += 10;//判断是否出界CheckPos();break;}}Console.Clear(); //清除掉原来的地图DrawMap(); //在画⼀边地图//因为只有⼀种情况出现,所以msg的值经过判断之后也是只有⼀种,然后将其内容显⽰出来Console.WriteLine(msg);}⼩知识总结:可以通过判断,显⽰内容case 0:msg=string.Format("玩家{0}踩到了玩家{1},玩家{2}退6格", PlayerNames[playerPos], PlayerNames[1- playerPos], PlayerNames[1 - playerPos]); case 1:msg = string.Format("{0}⾛到了幸运轮盘,请选择1--交换位置,2---轰炸对⽅", PlayerNames[playerPos]);Console.WriteLine(msg);以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

C#基础篇六飞行棋

C#基础篇六飞行棋

C#基础篇六飞⾏棋飞⾏棋业务:我们要能够让2个玩家在地图上按照游戏规则进⾏游戏玩家类变量:玩家位置,玩家名称,玩家标识,玩家是否在陷阱中⽅法:投骰⼦,移动地图类变量:地图数据数组⽅法:初始化地图数据,绘制地图,显⽰Logo游戏规则类变量:⽅法:第⼀次游戏说明,判断玩家位置是否有障碍物,根据不同障碍物执⾏不同操作,判断游戏是否结束using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace P03FlyQi{class Program{#region ----------------1.全局变量 mapData/playerMark/palyerNames/playerPosition/playerIsInTrap-------------------//1.全局变量-----------------------------//--------1.1 地图数据-----------------/// <summary>/// 地图数据数组/// </summary>static string[] mapData = new string[100];//--------1.2 玩家数据-----------------/// <summary>/// 玩家标识 A / B/// </summary>static string[] playerMark = new string[2];/// <summary>/// 玩家名字/// </summary>static string[] playerNames = new string[2];/// <summary>/// 玩家位置/// </summary>static int[] playerPosition = new int[2];/// <summary>/// 玩家是否在陷阱中/// </summary>static bool[] playerIsInTrap = new bool[2];#endregionstatic void Main(string[] args){StartGame();Console.ReadLine();}#region 0.0 游戏开始 void StartGame()/// <summary>/// 0.0 游戏开始/// </summary>static void StartGame(){//0.1 初始化数据InitData();//0.2 显⽰ LogoShowLogo();//0.3 游戏进⾏Playing();}#endregion#region 1.0 初始化数据⽅法 void InitData()/// <summary>/// 1.0 初始化数据⽅法/// </summary>static void InitData(){//1.初始化地图数据InitMapData();//2.初始化玩家数据InitPlayerData();}#endregion#region 1.1 初始化地图数据 void InitMapData()/// <summary>/// 1.1 初始化地图数据/// </summary>static void InitMapData(){//a.为地图⾥所有单元都默认赋值为 "普通"for (int i = 0; i < mapData.Length; i++){mapData[i] = "普通";}//b.设置障碍物mapData[5] = "地雷";mapData[25] = "地雷";mapData[45] = "地雷";mapData[85] = "地雷";mapData[15] = "陷阱";mapData[33] = "陷阱";mapData[65] = "陷阱";mapData[95] = "陷阱";mapData[12] = "时空隧道";mapData[28] = "时空隧道";mapData[54] = "时空隧道";mapData[79] = "时空隧道";mapData[7] = "幸运轮盘";mapData[37] = "幸运轮盘";mapData[47] = "幸运轮盘";mapData[69] = "幸运轮盘";}#endregion#region 1.2 初始化玩家数据 void InitPlayerData()/// <summary>/// 1.2 初始化玩家数据/// </summary>static void InitPlayerData(){playerMark[0] = "A";playerMark[1] = "B";playerNames[0] = ReadString("请输⼊玩家A的姓名:");Console.WriteLine("玩家{0}的名字设置成功啦~~~:)\n", playerMark[0]);do{playerNames[1] = ReadString("请输⼊玩家B的姓名:");if (playerNames[1] == playerNames[0]){Console.WriteLine("两个名字不能⼀样~~~");}else{Console.WriteLine("玩家{0}的名字设置成功啦~~~:)\n", playerMark[1]); break;}} while (true);}#endregion#region 2.0 显⽰游戏Logo void ShowLogo()/// <summary>/// 2.0 显⽰游戏Logo/// </summary>static void ShowLogo(){Console.WriteLine("********************************************");Console.WriteLine("* *");Console.WriteLine("* ⽜ B 的骑⼠飞⾏棋 *");Console.WriteLine("* *");Console.WriteLine("********************************************");#endregion#region 3.0 游戏进⾏中 void Playing()/// <summary>/// 3.0 游戏进⾏中/// </summary>static void Playing(){//3.1清屏Console.Clear();//3.2显⽰LogoShowLogo();//3.3显⽰第⼀次运⾏游戏的说明消息ShowFirstRoundMsg();//3.4游戏轮流进⾏PlayRounds();}#endregion#region 3.1 显⽰第⼀次运⾏游戏的说明消息 void ShowFirstRoundMsg()/// <summary>/// 3.1 显⽰第⼀次运⾏游戏的说明消息/// </summary>static void ShowFirstRoundMsg(){Console.WriteLine("{0} 和 {1} 两个好基友将在此次游戏中⼀决雌雄~~!", playerNames[0], playerNames[1]); Console.WriteLine("玩家【{0}】⽤【A】表⽰~~", playerNames[0]);Console.WriteLine("玩家【{0}】⽤【B】表⽰~~", playerNames[1]);Console.WriteLine("如果两个玩家位置相同,则⽤ <> 表⽰~!");Console.WriteLine("游戏开始~~~");}#endregion/// <summary>/// 游戏结束标识/// </summary>static bool isGameOver = false;#region 3.2 游戏轮流进⾏ void PlayRound()/// <summary>/// 3.2 游戏轮流进⾏/// </summary>static void PlayRounds(){//3.2.1绘制地图ShowMap();while (!isGameOver){//3.2.2玩家开始玩~~PlayAnRound();}}#endregion#region 3.2.1 绘制地图 void ShowMap()/// <summary>/// 3.2.1 绘制地图/// </summary>static void ShowMap(){//1.绘制第⼀部分:第1个横杠(从左到右)for (int i = 0; i < 30; i++){string unitIcon = GetMapUnitIconByType(i);Console.Write(unitIcon);}Console.WriteLine();//2.绘制第⼆部分:第1个竖线(右竖线)for (int i = 30; i < 35; i++){string unitIcon = GetMapUnitIconByType(i);for (int j = 0; j < 29; j++){Console.Write(" ");}Console.WriteLine(unitIcon);}//3.绘制第三部分:第2个横杠(从右到左)for (int i = 64; i>=35; i--){string unitIcon = GetMapUnitIconByType(i);Console.Write(unitIcon);Console.WriteLine();//4.绘制第四部分:第2个竖线(左竖线)for (int i = 65; i < 70; i++){string unitIcon = GetMapUnitIconByType(i);Console.WriteLine(unitIcon);}//5.绘制第五部分:第3个横杠(从左到右)for (int i = 70; i < 100; i++){string unitIcon = GetMapUnitIconByType(i);Console.Write(unitIcon);}Console.WriteLine();//绘制地图后,恢复原来的字体颜⾊Console.ResetColor();}#endregion#region 3.2.1.1 根据地图下标,返回地图图标或者玩家标识 string GetMapUnitIconByType(int mapIndex) /// <summary>/// 3.2.1.1 根据地图下标,返回地图图标或者玩家标识/// 获取地图下标对应的地图单元类型(普通、地雷、陷阱...),返回对应的符号!/// </summary>/// <param name="mapIndex">地图单元下标</param>static string GetMapUnitIconByType(int mapIndex){string strUnitIcon = "";//1.判断地图位置是否有玩家if (mapIndex == playerPosition[0])//玩家A的位置{//如果两个玩家的位置相同,则需要返回 <>if (playerPosition[0] == playerPosition[1]){Console.ForegroundColor = ConsoleColor.Gray;strUnitIcon = "<>";}else{Console.ForegroundColor = ConsoleColor.White;strUnitIcon = playerMark[0];}}else if (mapIndex == playerPosition[1])//玩家B的位置{Console.ForegroundColor = ConsoleColor.White;strUnitIcon = playerMark[1];}else//地图符号{switch (mapData[mapIndex]){case "普通":Console.ForegroundColor = ConsoleColor.White;strUnitIcon = "□";break;case "地雷":Console.ForegroundColor = ConsoleColor.Red;strUnitIcon = "◎";break;case "幸运轮盘":Console.ForegroundColor = ConsoleColor.Yellow;strUnitIcon = "卐";break;case "时空隧道":Console.ForegroundColor = ConsoleColor.Magenta;strUnitIcon = "○";break;case "陷阱":Console.ForegroundColor = ConsoleColor.Green;strUnitIcon = "井";break;}}return strUnitIcon;}#endregion#region 3.2.2 两个玩家各投⼀次骰⼦ void PlayAnRound()/// <summary>/// 3.2.2 两个玩家各投⼀次骰⼦/// </summary>static void PlayAnRound(){int playNum = 0;//1.玩家A投骰⼦--------------------------//0.判断玩家A是否在陷阱中if (playerIsInTrap[0] == true)//如果在陷阱中,则停⽌⼀轮{Console.WriteLine("玩家【A】正艰难的向陷阱外攀爬~~~~按回车继续");playerIsInTrap[0] = false;//将玩家B的陷阱标识改成 false(已经停了⼀轮)Console.ReadLine();}else//否则,进⾏投骰⼦{playNum = GetAnRandomNum();//1.1修改玩家A的位置playerPosition[0] += playNum;Console.WriteLine("玩家【A】投了⼀个数字:{0},按回车继续...", playNum);Console.ReadLine();//1.2重新绘制地图Console.Clear();ShowLogo();ShowMap();//1.3判断玩家A新的位置上是否结束或有障碍物!,如果有,则进⾏相应处理JudgePosition(true);}//2.玩家B投骰⼦-----------------------------//0.判断玩家A是否在陷阱中if (playerIsInTrap[1] == true)//如果在陷阱中,则停⽌⼀轮{Console.WriteLine("玩家【B】正艰难的向陷阱外攀爬~~~~按回车继续");playerIsInTrap[1] = false;//将玩家B的陷阱标识改成 false(已经停了⼀轮)Console.ReadLine();}else{playNum = GetAnRandomNum();//2.1修改玩家B的位置playerPosition[1] += playNum;Console.WriteLine("玩家【B】投了⼀个数字:{0},按回车继续...", playNum);Console.ReadLine();//2.2重新绘制地图Console.Clear();ShowLogo();ShowMap();//2.3判断玩家B新的位置上是否结束或有障碍物!,如果有,则进⾏相应处理JudgePosition(false);}}#endregion#region 3.2.2.1 获取⼀个骰⼦数(1-6)/// <summary>/// 3.2.2.1 获取⼀个骰⼦数(1-6)/// </summary>static int GetAnRandomNum(){Random ran = new Random();return ran.Next(1, 7);}#endregion#region 3.2.2.2 判断玩家在地图上是否有障碍物,如果有则执⾏对应操作 void JudgePosition(bool isPlayerA) /// <summary>/// 3.2.2.2 判断玩家在地图上是否有障碍物,如果有则执⾏对应操作/// </summary>/// <param name="index"></param>static void JudgePosition(bool isPlayerA){//0.判断两个玩家的新位置是否已经超过地图,如果超过,则结束游戏if (playerPosition[0] >= 99){Console.WriteLine("游戏结束~~~玩家{0}赢了~~", playerMark[0]);isGameOver = true;}else if (playerPosition[1] >= 99){Console.WriteLine("游戏结束~~~玩家{0}赢了~~", playerMark[1]);isGameOver = true;}else{//1.玩家的位置int playerIndex = isPlayerA ? playerPosition[0] : playerPosition[1];//2.根据玩家所在地图的障碍物执⾏不同的操作switch (mapData[playerIndex]){case "地雷":{MeetBomb(isPlayerA);break;}case "幸运轮盘":{MeetLuckyCircle(isPlayerA);break;}case "时空隧道":{MeetTimeTunnuel(isPlayerA);break;}case "陷阱":{MeetTrap(isPlayerA);break;}}}}#endregion#region 3.2.2.2.1 遇到地雷 void MeetBomb(bool isPlayerA)/// <summary>/// 3.2.2.2.1 遇到地雷/// </summary>/// <param name="isPlayerA">是否为玩家A,或者玩家B</param>static void MeetBomb(bool isPlayerA){//1.如果是地雷,则提⽰要后退 6 格Console.WriteLine("真倒霉~~【{0}】踩到了地雷了~~!后退6格~~!按回车继续...", (isPlayerA ? playerMark[0] : playerMark[1]));//2.玩家退后 6 格if (isPlayerA){playerPosition[0] -= 6;}else{playerPosition[1] -= 6;}CheckPosition();Console.ReadLine();Console.Clear();ShowLogo();ShowMap();}#endregion#region 3.2.2.2.2 遇到时空隧道 void MeetTimeTunnuel(bool isPlayerA)/// <summary>/// 3.2.2.2.2 遇到时空隧道/// </summary>/// <param name="isPlayerA">是否为玩家A,或者玩家B</param>static void MeetTimeTunnuel(bool isPlayerA){//1.如果是地雷,则提⽰要后退 6 格Console.WriteLine("真幸运~~【{0}】进⼊时空隧道了~~ !前进6格⼦~~!按回车继续...", (isPlayerA ? playerMark[0] : playerMark[1])); //2.玩家退后 6 格if (isPlayerA){playerPosition[0] += 6;}else{playerPosition[1] += 6;}CheckPosition();Console.ReadLine();Console.Clear();ShowLogo();ShowMap();}#endregion#region 3.3.2.2.3 遇到陷阱 void MeetTrap(bool isPlayerA)/// <summary>/// 3.3.2.2.3 遇到陷阱/// </summary>/// <param name="isPlayerA"></param>static void MeetTrap(bool isPlayerA){//1.如果是地雷,则提⽰要后退 6 格Console.WriteLine("啊~~【{0}】掉进陷阱了~~ !暂停⼀局!按回车继续...", (isPlayerA ? playerMark[0] : playerMark[1]));//2.玩家进⼊陷阱if (isPlayerA){playerIsInTrap[0] = true;}else{playerIsInTrap[1] = true;}Console.ReadLine();}#endregion#region 3.3.2.4 遇到幸运轮盘 void MeetLuckyCircle()/// <summary>/// 3.3.2.4 遇到幸运轮盘/// </summary>static void MeetLuckyCircle(bool isPlayerA){//1.如果是地雷,则提⽰要后退 6 格string strPalyerMark = isPlayerA ? playerMark[0] : playerMark[1];int num = ReadANum("啊~~【" + strPalyerMark + "】被幸运之神遭砸了~~,请选择⼀个愿望:1.轰炸对⽅,对⽅后退6格;2.乾坤⼤挪移,和对⽅交换位置:"); switch (num){case 1://轰炸对⽅,对⽅后退6格{//如果是玩家A,那么玩家B的位置后退6格if (isPlayerA){playerPosition[1] -= 6;Console.WriteLine("您选择轰炸对⽅,玩家【B】将后退6格~!");}else//如果是玩家B,那么玩家A的位置后退6格{playerPosition[0] -= 6;Console.WriteLine("您选择轰炸对⽅,玩家【A】将后退6格~!");}break;}case 2://乾坤⼤挪移,和对⽅交换位置{//playerPosition[0] = playerPosition[0] + playerPosition[1];//playerPosition[1] = playerPosition[0] - playerPosition[1];//playerPosition[0] = playerPosition[0] - playerPosition[1];int temp = playerPosition[0];playerPosition[0] = playerPosition[1];playerPosition[1] = temp;Console.WriteLine("您选择了乾坤⼤挪移,和对⽅交换位置~!");break;}}CheckPosition();Console.ReadLine();Console.Clear();ShowLogo();ShowMap();}#endregion#region 4.检查玩家位置,⼀旦出现越界,则设置临界值 void CheckPosition()/// <summary>/// 4.检查玩家位置,⼀旦出现越界,则设置临界值/// </summary>static void CheckPosition(){if (playerPosition[0] < 0) playerPosition[0] = 0;if (playerPosition[1] < 0) playerPosition[1] = 0;if (playerPosition[0] > 99) playerPosition[0] = 99;if (playerPosition[1] > 99) playerPosition[1] = 99;}#endregion//-----------------------⼯具⽅法-------------------------------//-------------------------------------------------------------#region 0.0 读取⼀个⾮空字符串 string ReadString(string strMsg)/// <summary>/// 0.0 读取⼀个⾮空字符串/// </summary>/// <returns></returns>static string ReadString(string strMsg){string strMsgBack="";while (true){Console.Write(strMsg);strMsgBack = Console.ReadLine().Trim();if (string.IsNullOrEmpty(strMsgBack)){Console.WriteLine("您输⼊的字符串不能为空~~");}else{break;}}return strMsgBack;//返回接收到的⾮空字符串//Trim⽅法⽤来去掉字符串两边的空格,如:" aaa aaa " => "aaa aaa"//string.IsNullOrEmpty 判断字符串是否为空,如果为空,则返回 true;否则返回 false }#endregion#region 0.0 读取⼀个数值 int ReadANum(string strMsg)/// <summary>/// 0.0 读取⼀个数值/// </summary>/// <returns></returns>static int ReadANum(string strMsg){int num = -1;while (true){string strMsgBack = ReadString(strMsg);if (int.TryParse(strMsgBack, out num) && (num > 0 && num<3)){break;}else {Console.WriteLine("请输⼊ 1-2 之间的⼀个数值!");}}return num;}#endregion}}。

骑士飞行棋代码

骑士飞行棋代码

好几天没更新了,是因为给大家写这个小游戏去了,好久没写了,逻辑上出了问题,调试了好久终于出来了,我自己测试了下没什么大问题,不过应该还是会有BUG,希望大家下载后找到BUG了给我说下,呵呵,谢谢!代码:如下地图类Map():package com.yx.dao;/*** 地图类* @author Administrator**/public class Map {// 定义地图的大小int [] map = new int[100];int[] dilei = {5,16,56,72,80,85}; // 定义地雷的位置int[] luck = {15,50,88}; // 定义幸运大罗盘的位置int[] pulse = {9,25,35,48,65,85,92,95}; // 定义暂停的位置int[] time = {20,39,47,68,81,90}; // 定义时空隧道public int index = 0; // 定义起始位置public int playerA = 0; // 玩家A的位置public int playerB = 0; // 玩家B的位置/*** 找到定义地雷、幸运大罗盘等的位置,然后给他第一个数字来代替,为后面的判断做准备*/public void initialMap(){// 循环找出所有的地雷,并把它暂时标记为1for(int i = 0; i < 100; i++) {map[i] = 0;}for(int i =0; i < dilei.length; i++) {map[dilei[i]] = 1;}for(int i = 0; i < luck.length; i++) {map[luck[i]] = 2;}for(int i = 0; i < pulse.length; i++) {map[pulse[i]] = 3;}for(int i = 0; i < time.length; i++) {map[time[i]] = 4;}// 以下为判断玩家A或玩家B是否到达终点,是否该结束游戏if(playerA > 99) {map[playerA] = 99;}if(playerB > 99) {map[playerB] = 99;}// 以下是判断玩家A和玩家B是不是在同一个位置上if(playerA != playerB) {map[playerA] = 5;map[playerB] = 6;}else {map[playerA] = 7;}}// 指定地雷、幸运星等在地图上的团public void printMap() {switch(map[index]) {case 0:System.out.print("::");break;case 1:System.out.print("●");break;case 2:System.out.print("◑");break;case 3:System.out.print("〓");break;case 4:System.out.print("◎");break;case 5:System.out.print("A");break;case 6:System.out.print("B");break;case 7:System.out.print("♦");break;}}// 以下为地图的制作方法/*** 现实第一行横排地图*/public void showMap1() {for(index = 0; index < 30; index++) {printMap();}}/*** 现实右边一列的地图*/public void showMapRight() {for(index = 30; index < 35; index++) {System.out.println();System.out.print("\t\t\t\t\t\t ");printMap();}}/*** 显示第三行地图*/public void showMap2() {for(index = 64; index >= 35; index--) { printMap();}}/*** 显示左边列的地图*/public void showMapLeft() {for(index = 65; index < 70; index++) { System.out.println();printMap();}}/*** 最后一行的地图*/public void showMap3() {for(index = 70; index < 100; index++) { printMap();}}/*** 现实所有的地图*/public void showMap() {initialMap();showMap1();showMapRight();System.out.println();showMap2();showMapLeft();System.out.println();showMap3();System.out.println();}}游戏逻辑处理类Game():package com.yx.dao;import java.util.Scanner;/*** 游戏类* @author Administrator**/public class Game {Scanner input = new Scanner(System.in);Map map = new Map();String person1 = ""; // 玩家1名字String person2 = ""; // 玩家2名字boolean game1 = true; // 默认玩家1没有赢boolean game2 = true; // 默认为家2没有赢/*** 打印提示语句以及规定说明等*/public void init() {System.out.println("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※");System.out.println("////");System.out.println("////");System.out.println("// 骑士飞行棋//");System.out.println("////");System.out.println("////");System.out.println("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n\n");System.out.println("∽∽∽∽∽∽∽∽∽∽∽∽∽∽∽∽∽∽∽两人对站∽∽∽∽∽∽∽∽∽∽∽∽∽∽∽");System.out.println("请选择角色:1.戴高乐2.艾森豪威尔3.麦克阿瑟4.巴顿");System.out.println("请玩家1选择角色:");int Game1 = input.nextInt();System.out.println("请玩家2选择角色:");int Game2 = input.nextInt();switch (Game1) {case 1:person1 = "戴高乐";break;case 2:person1 = "艾森豪威尔";break;case 3:person1 = "麦克阿瑟";break;case 4:person1 = "巴顿";break;}switch (Game2) {case 1:person2 = "戴高乐";break;case 2:person2 = "艾森豪威尔";break;case 3:person2 = "麦克阿瑟";break;case 4:person1 = "巴顿";break;}/** 两人对战的玩法*/System.out.println("******************************************************************* *****\n");System.out.println(" Game Start \n");System.out.println("******************************************************************* *****\n");// 显示对战双方士兵的样式System.out.println("^-^" + person1 + "的士兵:A\n");System.out.println("^-^" + person2 + "的士兵:B\n");// 显示对战地图System.out.println("\n图例:" + "◐地雷※幸运转盘◑暂停〓时空隧道∷普通\n");map.showMap();do {if (game1) {System.out.println( person1 + "扔筛子产生一个随机数开始:");input.next();int number = (int) (Math.random() * 6 + 1);map.playerA += number;checkGameA();if (map.playerA >= 99) {map.showMap();System.out.println("\n"+person1 + "获得胜利!");judge();break;}} else {game1 = true;// 玩家可以重新移动}if (game2) {System.out.println(person2+ "扔筛子产生一个随机数开始:");input.next();int number = (int) (Math.random() * 6 + 1);map.playerB += number;checkGameB();System.out.println();if (map.playerB >= 99) {map.showMap();System.out.println("\n"+person2 + "获得胜利!");judge();break;}} else {game2 = true;// 玩家可以重新移动}map.showMap();} while (true);}public void checkGameA() {for (int i = 0; i < map.dilei.length; i++) {if (map.playerA == map.dilei[i]) {System.out.println("哎,真衰,踩到地雷了!");int number = (int) (Math.random() * 6 + 1);// 减去的是一个随机数map.playerA -= number;return;}}for (int i = 0; i < map.luck.length; i++) {if (map.playerA == map.luck[i]) {System.out.println("嘿嘿,遇上幸转盘了,我真幸运!");System.out.println("1.交换位置2.轰炸");System.out.println("您选择的是:");int num = input.nextInt();switch (num) {case 1:int temp = map.playerB;map.playerB = map.playerA;map.playerA = temp;break;case 2:map.playerA -= 10;break;}return;}}for (int i = 0; i < map.pulse.length; i++) {if (map.playerA == map.pulse[i]) {System.out.println("唉,得休息一会了!");game1 = false;return;}}for (int i = 0; i < map.time.length; i++) {if (map.playerA == map.time[i]) {System.out.println("哈哈,时空隧道!");map.playerA += 10;return;}}}public void checkGameB() {for (int i = 0; i < map.dilei.length; i++) {if (map.playerB == map.dilei[i]) {System.out.println("哎,真衰,踩到地雷了!");int number = (int) (Math.random() * 6 + 1);map.playerB -= number;// 减去一个随机数return;}}for (int i = 0; i < map.luck.length; i++) {if (map.playerB == map.luck[i]) {System.out.println("嘿嘿,遇上幸转盘了,我真幸运!");System.out.println("1.交换位置2.轰炸");System.out.println("您选择的是:");int num = input.nextInt();switch (num) {case 1:int temp = map.playerB;map.playerB = map.playerA;map.playerA = temp;break;case 2:map.playerA -= 10;break;}return;}}for (int i = 0; i < map.pulse.length; i++) {if (map.playerB == map.pulse[i]) {System.out.println("唉,得休息一会了!");game2 = false;return;}}for (int i = 0; i < map.time.length; i++) {if (map.playerB == map.time[i]) {System.out.println("哈哈,时空隧道!");map.playerA += 10;return;}}}public void judge() {System.out.println("******************************************************************* *****\n");System.out.println(" Game Over \n");System.out.println("******************************************************************* *****\n");}}测试类,游戏入口类Star():package com.yx.test;import com.yx.dao.Game;//import com.yx.dao.Map;public class test {/*** @param args*/public static void main(String[] args) {Game game = new Game();game.init();}}我这是分了两个包建立的,希望大家建立的时候注意下,或者可以直接加QQ,你可以直接下载到项目然后导入就可以了,这样就不存在其它问题了,呵呵。

c#骑士飞行器数据操作类

c#骑士飞行器数据操作类

using System;using System.Collections.Generic;using System.Linq;using System.Text; 官场小说namespace骑士飞行棋{class Class{static int[] playerPos = { 0, 0 }; //存储玩家的坐标,playerPos{0}代表玩家A,playerPos{1}代表玩家B!static int[] map = new int[100]; //定义地图数组static int meetCount = 0; //用于给2个玩家相遇循环用的变量meetcount代表相遇计数static int PD = 0;public static bool Suspend(){if (PD == 0){return true;}elsereturn false;}///<summary>///显示游戏的界面///</summary>public void ShowUi()//这里没有加static修饰符,在调用这个方法的时候必须先实例化类才可以用实例名点方法名调用{Console.WriteLine("******************************************************* ******");Console.WriteLine("* *");Console.WriteLine("* 骑士飞行棋 *");Console.WriteLine("* *");Console.WriteLine("******************************************************* ******");///<summary>///绘制地图的关卡///</summary>///<returns></returns>public static void InitialMap(){//定义地图中关卡的数组//在数组中用:□0代表普通// ◎1代表幸运轮盘// ☆2代表地雷// ▲3代表暂停// ※4代表时光隧道int[] luckyTurn = { 6, 23, 40, 55, 68, 83 }; //◎幸运轮盘int[] landMine = { 5, 13, 17, 33, 38, 50, 65, 80, 98 }; //☆地雷int[] pause = { 9, 27, 60, 93 }; //▲暂停int[] timeTunnel = { 20, 25, 45, 64, 72 }; //※时光隧道//给地图输入幸运轮盘坐标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;}///<summary>///绘制地图///</summary>public static void DrawMap(){Console.WriteLine("图例:◎1代表幸运轮盘☆2代表地雷▲3代表暂停※4代表时光隧道");//第一行:绘制下标0-29格的地图for (int i = 0; i <= 29; i++){Console.Write(JudgeMap(i));}Console.WriteLine();//第二行:绘制下标30-34格的地图for (int i = 30; i <= 34; i++){for (int j = 0; j < 29; j++){Console.Write(" ");}Console.WriteLine(JudgeMap(i));}//第三行:绘制下标35-64格的地图for (int i = 64; i >= 35; i--){Console.Write(JudgeMap(i));}Console.WriteLine();//第四行:绘制下标65-69格的地图for (int i = 65; i <= 69; i++){Console.WriteLine(JudgeMap(i));}//第五行:绘制下标70-99格的地图for (int i = 70; i <= 99; i++){Console.Write(JudgeMap(i));}Console.WriteLine();}///<summary>///判断地图关卡///</summary>///<param name="i">接收的值</param>///<returns></returns>public static string JudgeMap(int i){if (playerPos[0] == i && playerPos[1] == i){Console.ForegroundColor = ConsoleColor.Yellow;return"<>";}else if (playerPos[0] == i){Console.ForegroundColor = ConsoleColor.Yellow;return"A";}else if (playerPos[1] == i){Console.ForegroundColor = ConsoleColor.Yellow;return"B";}else{switch (map[i]){case 0:Console.ForegroundColor = ConsoleColor.White;return"□";case 1:Console.ForegroundColor = ConsoleColor.Red;return"◎";case 2:Console.ForegroundColor = ConsoleColor.DarkGray;return"☆";case 3:Console.ForegroundColor = ConsoleColor.Blue;return"▲";case 4:Console.ForegroundColor = ConsoleColor.Green;return"※";}}return"";}///<summary>///判断玩家坐标的方法以及关卡的判断///</summary>///<param name="i">用来接收玩家A跟玩家B地址的位置</param>///<param name="j">用来接收玩家A跟玩家B掷出来的点数</param>///<returns></returns>public static int PlayerPos(int i, int j){int result = 0; PD = 0;if (i == 0){//接收玩家掷出来的点数付给玩家A的位置,playerPos[0]+j把之前的点数加上新掷出的点数付给玩家A的位置playerPos[0] = playerPos[0] + j;meetCount++;while (meetCount > 1){if (playerPos[0] == playerPos[1] && i == 0){playerPos[1] = 0;Console.Clear();DrawMap();Console.ResetColor(); //把颜色设置为默认值Console.WriteLine("玩家{0}踩到玩家{1},玩家{2}退回源点!", [0], [1], [1]);Console.ReadKey(true);}break;}if (playerPos[0] > 99)//判断玩家A的位置是不是大于99如果是的话把玩家A 的位置定在99上面{playerPos[0] = 99;}else if (playerPos[0] < 0){playerPos[0] = 0;}//关卡判断if (map[playerPos[0]] == 1 && j != 0){bool lebel = true;while (lebel){Console.WriteLine("幸运轮盘!1:把对手炸退6步! 2:于对手交换位置");try{result = int.Parse(Console.ReadLine());if (result == 1){playerPos[1] -= 6;if (playerPos[1] < 0){playerPos[1] = 0;}lebel = false;Console.WriteLine("玩家{0}将把玩家{1}炸退了6步!按任意键继续", [0], [1]);Console.ReadKey(true);}else if (result == 2){Console.WriteLine("玩家{0}将与玩家{1}交换位置!按任意键继续", [0], [1]);Console.ReadKey(true);int temporary = playerPos[0];playerPos[0] = playerPos[1];playerPos[1] = temporary;lebel = false;}else{Console.WriteLine("你的输入有误!请重新输入!");lebel = true;}}catch{Console.WriteLine("你的输入有误!请重新输入!");lebel = true;}}}else if (map[playerPos[0]] == 2){Console.WriteLine("踩到地雷,后退6步!");Console.ReadKey(true);playerPos[0] -= 6;}else if (map[playerPos[0]] == 3){PD = 1;}else if (map[playerPos[0]] == 4){Console.WriteLine("时空隧道,前进6步!");Console.ReadKey(true);playerPos[0] += 6;}if (playerPos[0] > 99)//判断玩家A的位置是不是大于99如果是的话把玩家A 的位置定在99上面{playerPos[0] = 99;}else if (playerPos[0] < 0){playerPos[0] = 0;}//返回玩家A的位置return playerPos[0];}//接收玩家掷出来的点数付给玩家B的位置,playerPos[1]+j把之前的点数加上新掷出的点数付给玩家B的位置playerPos[1] = playerPos[1] + j;while (meetCount > 1){if (playerPos[1] == playerPos[0] && i == 1){playerPos[0] = 0;Console.Clear();DrawMap();Console.ResetColor(); //把颜色设置为默认值Console.WriteLine("玩家{0}踩到玩家{1},玩家{2}退回源点!", [1], [0], [0]);Console.ReadKey(true);}break;}if (playerPos[1] > 99)//判断玩家B的位置是不是大于99如果是的话把玩家B的位置定在99上面{playerPos[1] = 99;}else if (playerPos[1] < 0){playerPos[1] = 0;}//关卡判断if (map[playerPos[1]] == 1 && j != 0){bool lebel = true;while (lebel){Console.WriteLine("幸运轮盘!1:把对手炸退6步! 2:于对手交换位置");try{result = int.Parse(Console.ReadLine());if (result == 1){playerPos[0] -= 6;if (playerPos[0] < 0){playerPos[0] = 0;}lebel = false;}else if (result == 2){int temporary = playerPos[1];playerPos[1] = playerPos[0];playerPos[0] = temporary;lebel = false;}else{Console.WriteLine("你的输入有误!请重新输入!");lebel = true;}}catch{Console.WriteLine("你的输入有误!请重新输入!");lebel = true;}}}else if (map[playerPos[1]] == 2){Console.WriteLine("踩到地雷,后退6步!");Console.ReadKey(true);playerPos[1] -= 6;}else if (map[playerPos[1]] == 3){PD = 1;}else if (map[playerPos[1]] == 4){Console.WriteLine("时空隧道,前进6步!");Console.ReadKey(true);playerPos[1] += 6;}if (playerPos[1] > 99)//判断玩家B的位置是不是大于99如果是的话把玩家B的位置定在99上面{playerPos[1] = 99;}else if (playerPos[1] < 0){playerPos[1] = 0;}//返回玩家B的位置return playerPos[1];}///<summary>///返回玩家的位置///</summary>///<param name="i">判断玩家A跟玩家B,0是A,1是B</param> ///<returns></returns>public static int PlayerLocation(int i){if (i == 0){return playerPos[0];}else{return playerPos[1];}}}}灵域。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
}
#endregion
//-----------------------------------玩家准备完毕,游戏开始---------------------------------------------
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("◎幸运轮盘\t");
Console.ForegroundColor = ConsoleColor.Yellow;
}
}//初始地图--
static void DrawMap()
{
//□◎¤▲卍
#region 地图标示简介
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("玩家A[{0}]\t\t\t\t\t\t玩家B[{1}]\n", name[0], name[1]);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("<>AB同位置\t");
#region 游戏说明
Console.Clear();
ShowUI();
Gameillustration();
Console.WriteLine("\n");
Console.WriteLine("按任意键开始游戏...");
Console.WriteLine("* *");
Console.WriteLine("* 骑 士 飞 行 棋 *");
{
if (name[1] == "")
{
Console.WriteLine("名字不能为空,请重新输入:");
name[1] = Console.ReadLine();
Console.WriteLine(" \t时空隧道 :可以前进10格\n");
Console.WriteLine(" \t追 踩 :被踩到的退回开始位置");
}//游戏说明--
static void InitialMap()
#endregion
static void Main(string[] args)
{
#region 用户注册
ShowUI();
Console.WriteLine("请输入玩家A的姓名:");
Map[pos] = 2;
}
for (int i = 0; i < pause.Length; i++)
{
int pos = pause[i];
Map[pos] = 3;
Map[pos] = 1;
}
for (int i = 0; i < landMine.Length; i++)
{
int pos = landMine[i];
Console.WriteLine("* *");
Console.WriteLine("********************************************************************");
{
int[] lunkTurn = { 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
for (int i = 0; i < lunkTurn.Length; i++)
{
int pos = lunkTurn[i];
#region 正式游戏
ShowUI(); //绘制欢迎界面--
InitialMap();//初始化地图--
DrawMap();//绘制地图
Console.WriteLine();
}
else
{
Console.WriteLine("您输入的名字已被玩家A【{0}】注册,请重新输入:", name[0]);
name[1] = Console.ReadLine();
}
for (int i = 0; i < timeTunnel.Length; i++)
{
int pos = timeTunnel[i];
Map[pos] = 4;
#region
static void ShowUI()
{
Console.WriteLine("********************************************************************");
}
Console.WriteLine("请输入玩家B的姓名:");
name[1] = Console.ReadLine();
while (name[1] == "" || name[1] == name[0])
Console.WriteLine(" \t幸运轮盘 :1.可以和对手交换位置 2.可以轰炸对手\n");
Console.WriteLine(" \t地 雷 :踩到地雷倒退6格\n");
Console.WriteLine(" \t暂 停 :不能掷骰子\n");
Console.Write("¤地雷 ");
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.Write("▲暂停 ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
static Random r = new Random();//产生一个随机数
static int temp = r.Next(1, 7);//数的范围在(1<=temp<7)
static int input;//接收幸运轮盘的选择项
static string msg = "";//用于返回掷完骰子后的情况
Console.WriteLine("\n");
}//欢迎界面--
static void Gameillustration()
{
Console.WriteLine(" \t\t\t游戏说明\n\n");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 飞行棋
{
class Program
{
#region 程序变量定义
Console.WriteLine("卍时空隧道 ");
Console.WriteLine();
static int[] Map = new int[100];//定义了一个100格的地图
static int[] playerPos = { 0, 0 };//记录玩家的格子数
static string[] name = new string[2];//接收玩家姓名
name[0] = Console.ReadLine();
wh
Console.WriteLine("名字不能为空,请重新输入:");
name[0] = Console.ReadLine();
Start();//开始游戏
#endregion
Console.ReadKey();
}
//-------------------------------------------游戏调用的函数-------------------------------------------------
Console.ReadKey(true);
Console.Clear();
#endregion
//--------------------------------------说明文档演示完毕------------------------------------------------
相关文档
最新文档