本帖最后由 782385854 于 2013-10-25 14:48 编辑
再写的过程中,写到那个幸运轮盘的时候,哦,总是出错·····死循环里面了···出不来了,可是找不到哪里错了,我先贴代码,到底哪里错了呢- class Program
- {
- static int[] map = new int[100];
- static int[] playerpost = {0,0};
- static void Main(string[] args)
- {
- int input = 0;
- Random r = new Random();//产生随机数
- int step = 0;//存放随机数
- showUI();
- string[] name = new string[2];
- Console.WriteLine("请输入玩家A的名字:");
- name[0] = Console.ReadLine();
- while (name[0] == "")
- {
- Console.WriteLine("输入不能为空,请重新输入:");
- name[0] = Console.ReadLine();
- }
- Console.WriteLine("请输入玩家B的名字:");
- name[1] = Console.ReadLine();
- while (name[1] == name[0] || name[1] == "")
- {
- if (name[1] == "")
- {
- Console.WriteLine("玩家B的名字不能为空,请重新输入");
- }
- if (name[1] == name[0])
- {
- Console.WriteLine("该用户名已存在,请重新输入");
- }
- name[1] = Console.ReadLine();
- }
- Console.Clear();
- showUI();
- Console.WriteLine("游戏开始......");
- Console.WriteLine("{0}的士兵表示A",name[0]);
- Console.WriteLine("{0}的士兵表示B", name[1]);
- inmap();
- DrowMap();
- Console.WriteLine();
- while (playerpost[0]<99&&playerpost[1]<99)
- {
- Console.WriteLine("请玩家{0}按任意键扔色子",name[0]);
- Console.ReadKey(true);
- step = r.Next(1, 9);
- Console.WriteLine("{0}扔出了{1}",name[0],step);
- Console.WriteLine("用户按任意键 开始行动");
- Console.ReadKey(true);
- playerpost[0] = playerpost[0] + step;
- checkbos();
- Console.Clear();
- DrowMap();
- Console.WriteLine();
- switch (map[playerpost[0]])
- {
- case 0 :
- //普通
- break;
- case 1:
- //幸运轮盘
- Console.Clear();
-
- DrowMap();
- Console.WriteLine("你走到了幸运轮盘,请选择运气···");
- Console.WriteLine("1:交换位置 2:轰炸对方");
- input = int.Parse(Console.ReadLine());
- input = Readint(1, 2);
- //int userselect = Readint(1, 2);
- if (input==1)
- {
- int temp = playerpost[0];
- playerpost[0] = playerpost[1];
- playerpost[1] = temp;
- }
- else
- {
- playerpost[1] = playerpost[1] - 6;
- checkbos();
- }
- break;
- case 2:
- //地雷
- playerpost[0] = playerpost[0] - 6;
- checkbos();
- break;
- case 3:
- //暂停
- break;
- case 4:
- playerpost[0] = playerpost[0] + 10;
- //时空隧道
- break;
- default:
- break;
- }
- }
- Console.Clear();
- DrowMap();
- Console.WriteLine("{0}扔出了{1}",name[0],step);
- Console.WriteLine("{0}的位置为{1}",name[0],playerpost[0]);
- Console.WriteLine("{0}的位置为{1}", name[1], playerpost[1]);
- Console.ReadKey();
-
- }
- static int Readint()
- {
- int i = Readint(int.MinValue, int.MaxValue);
- return i;
- }
- static int Readint(int min, int max)
- {
- while (true)
- {
- try
- {
- int number = Convert.ToInt32(Console.ReadLine());
- if (number<min||number>max)
- {
- Console.WriteLine("只能输入{0}-{1}之间的数",min,max);
- continue;
- }
- }
- catch
- {
- Console.WriteLine("只能输入数字,请重新输入```") ;
- }
- }
- }
- static void checkbos()
- {
- for (int i = 0; i < 2; i++)
- {
- if (playerpost[i]>99)
- {
- playerpost[i] = 99;
- }
- if (playerpost[i]<0)
- {
- playerpost[i] = 0;
- }
- }
- }
- static string GetmapString(int pos)
- {
- string result = "";
- if (playerpost[0] == pos && playerpost[1] == pos)
- {
- result = "><";
- }
- else if (playerpost[0] == pos)
- {
- result = "A";
- }
- else if (playerpost[1] == pos)
- {
- result = "B";
- }
- else
- {
- switch (map[pos])
- {
- case 0:
- Console.ForegroundColor = ConsoleColor.White;
- result = "□";
- break;
- case 1:
- Console.ForegroundColor = ConsoleColor.DarkMagenta;
- result ="◎";
- break;
- case 2:
- Console.ForegroundColor = ConsoleColor.Gray;
- result = "¤";
- break;
- case 3:
- Console.ForegroundColor = ConsoleColor.Magenta;
- result = "△";
- break;
- case 4:
- Console.ForegroundColor = ConsoleColor.Yellow;
- result = "卍";
- break;
- default:
- break;
- }
- }
- return result;
- }
- static void inmap()
- {
- //用于储存地图下标
- //❤表示幸运转盘
- // ¤表示地雷
- //卍表示时空隧道
- //△表示暂停
- //□表示普通
- int[] luckpanturn = { 6, 9, 23, 57, 34,89, 55 };//幸运转盘1
- int[] dilei = { 44, 46, 7, 47, 49 };//地雷2
- int[] pause = { 54, 56, 58,32,35,77, 71 };//暂停3
- int[] timesuidao = { 20, 22, 26, 28, 66 };//时空隧道 4
- for (int i = 0; i < luckpanturn.Length; i++)
- {
- map[luckpanturn[i]] = 1;
- }
- for (int i = 0; i < dilei.Length; i++)
- {
- map[dilei[i]] = 2;
- }
- for (int i = 0; i < pause.Length; i++)
- {
- map[pause[i]] = 3;
- }
- for (int i = 0; i < timesuidao.Length; i++)
- {
- map[timesuidao[i]] = 4;
- }
- }
- static void DrowMap()
- {
- Console.WriteLine("游戏规则: ◎表示幸运转盘 ¤表示地雷 卍表示时空隧道 △表示暂停 □表示普通");
- for (int i = 0; i < 30; i++)
- {
- Console.Write(GetmapString(i));
- }
- Console.WriteLine();
- for (int i = 30; i < 35; i++)
- {
- for (int j = 0; j < 29; j++)
- {
- Console.Write(" ");
- }
- Console.WriteLine(GetmapString(i));
- }
- for (int i = 64; i >= 35; i--)
- {
- Console.Write(GetmapString(i));
- }
- Console.WriteLine();
- for (int i = 65; i < 70; i++)
- {
- Console.WriteLine(GetmapString(i));
- }
- for (int i = 70; i < 100; i++)
- {
- Console.Write(GetmapString(i));
- }
- }
- public static void showUI()
- {
- Console.WriteLine("**************************************************************************");
- Console.WriteLine("***** ****");
- Console.WriteLine("***** 飞行骑士游戏 ****");
- Console.WriteLine("***** ****");
- Console.WriteLine("**************************************************************************");
- }
- }
复制代码 |