飞行棋主要是讲的方法怎么应用,充分的去理解方法和方法的调用,整体收获还是很大的。
我想的是说一下整体的思路。在编程的时间里,逻辑是最重要的,先干嘛后干嘛,对吧。
直接上个飞行棋的图,大家看看。
先从哪里下手呢?画图!对先画图,画图先画表头,还是用流程图来吧
画图画好了,那么就是怎么掷骰子,然后不用的样式的格子都是什么功能。
这个实现功能,是我认为最麻烦的,一大技术难点。
下面是掷骰子的方法 简单来说就是用了一个大的 if else判断语句,来判断走到哪里,执行什么操作。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | 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 ; CheckPos(); if (PlayerPos[playerPos] == PlayerPos[1- playerPos]) //如果相等就退6格子 { msg= string .Format ( "玩家{0}踩到了玩家{1},玩家{2}退6格" ,PlayerNames [playerPos], PlayerNames[1- playerPos], PlayerNames[1-playerPos]); PlayerPos[1- playerPos] -= 6; CheckPos(); } else { switch (Map[PlayerPos[playerPos]]) //判断格子的数字 { case 0: msg =( "行动完成" ); break ; case 1: msg = string .Format( "{0}走到幸运轮盘,1--交换位置,2--轰炸对方" , PlayerNames[playerPos]); int number = ReadInt(msg, 1, 2); if (number == 1) { int temp = 0; temp = PlayerPos[0]; PlayerPos[0] = PlayerPos[1]; PlayerPos[1] = 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格" ; PlayerPos[playerPos] -= 6; CheckPos(); break ; case 3: msg = "踩到暂停了" ; flag[playerPos ]= true ; break ; case 4: msg= "恭喜你,前进10格" ; PlayerPos[playerPos] += 10; CheckPos(); break ; } } //清空,重新加载地图 Console.Clear(); DrawMap(); Console.WriteLine(msg ); } //掷骰子 |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自学编程网。
- 本文固定链接: https://zxbcw.cn/post/217791/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)