标签:style blog http color ar for sp div on
1 /// <summary> 2 /// 基本地图, 3 /// </summary> 4 /// <param name="s"></param> 5 //public void ditu(int tu1)//本想做个函数,可是怎么做都不对,只能先放放 6 //{ 7 // string[,] tu = new string[11, 11]; 8 // for (int i = 0; i <= 10; i++) 9 // { 10 // for (int j = 0; j <= 10; j++) 11 // { 12 // if (i == 0) { tu[0, j] = "※"; if (j == 10) { tu[0, 10] = "\n"; } } 13 // if (i == 9) { tu[9, j] = "※"; if (j == 10) { tu[9, 10] = "\n"; } } 14 // if (j == 0 && i > 0 && i < 9) { tu[i, 0] = "※"; } 15 // if (j == 9 && i > 0 && i < 9) { tu[i, 9] = "※"; } 16 // if (j == 10 && i > 0 && i < 9) { tu[i, 10] = "\n"; } 17 // if (i > 0 && i < 9 && j > 0 && j < 9) { tu[i, j] = " "; } 18 // } 19 // } 20 //} 21 static void Main(string[] args) 22 { 23 string[,] tu = new string[10, 11]; 24 for (int i = 0; i <= 10; i++) 25 { 26 for (int j = 0; j <= 10; j++) 27 { 28 if (i == 0) { tu[0, j] = "※"; if (j == 10) { tu[0, 10] = "\n"; } }//画出地图北墙 29 if (i == 9) { tu[9, j] = "※"; if (j == 10) { tu[9, 10] = "\n"; } }//画出地图南墙 30 if (j == 0 && i > 0 && i < 9) { tu[i, 0] = "※"; }//画出地图西墙 31 if (j == 9 && i > 0 && i < 9) { tu[i, 9] = "※\n"; }//画出地图东墙 32 if (i > 0 && i < 9 && j > 0 && j < 9) { tu[i, j] = " "; }//画出地图中间,这里暂时只有空地 33 } 34 } 35 int x = 1, y = 1; 36 string biao = "壹";//这个光标 37 tu[x, y] = biao;//这里代表光标的起始位置, 38 tu[8, 8] = "出";//这里是地图的出口。 39 string zhong = " "; 40 foreach(string s in tu)//打印出地图 41 { 42 Console.Write(s); 43 } 44 for (int p = 0; p >= 0; p++)//定义一个无限循环,只有当达到一定条件时才会break;跳出 45 { 46 Console.WriteLine("请输入w(上移),s(下移),a(左移),d(右移):"); 47 string shuru = Console.ReadLine(); 48 if (shuru == "d")//这里有4个if分别是w,a,s,d的判断,略显麻烦,也许用结构体更简单点 49 {//但是由于时间关系,没有来得及改动。 50 tu[x, y] = zhong; 51 y = y + 1; 52 if ( y < 9)//这里的if定义光标移动的范围, 53 { 54 tu[x, y] = biao; 55 Console.Clear(); 56 foreach (string s in tu) { Console.Write(s); } 57 } 58 if (y >= 9 )//这里的if是为了防止跑到地图以外。 59 { 60 y = 8; 61 Console.WriteLine("你撞墙了!"); 62 } 63 if (x == 8 && y == 8) { break; }//当光标移动到出口位置,过关 64 } 65 else if (shuru == "s") 66 { 67 tu[x, y] = zhong; 68 x = x + 1; 69 if ( x < 9) 70 { 71 tu[x, y] = biao; 72 Console.Clear(); 73 foreach (string s in tu) { Console.Write(s); } 74 } 75 if (x >= 9) 76 { 77 x = 8; 78 Console.WriteLine("你撞墙了!"); 79 } 80 if (x == 8 && y == 8) { break; } 81 } 82 else if (shuru == "w") 83 { 84 tu[x, y] = zhong; 85 x = x - 1; 86 if (x > 0) 87 { 88 tu[x, y] = biao; 89 Console.Clear(); 90 foreach (string s in tu) { Console.Write(s); } 91 } 92 if (x <= 0) 93 { 94 x = 1; 95 Console.WriteLine("你撞墙了!"); 96 } 97 } 98 else if (shuru == "a") 99 { 100 tu[x, y] = zhong; 101 y = y - 1; 102 if (y > 0) 103 { 104 tu[x, y] = biao; 105 Console.Clear(); 106 foreach (string s in tu) { Console.Write(s); } 107 } 108 if (y <= 0) 109 { 110 y = 1; 111 Console.WriteLine("你撞墙了!"); 112 } 113 } 114 } 115 Console.WriteLine("恭喜你,过关了!!"); 116 Console.ReadLine();
标签:style blog http color ar for sp div on
原文地址:http://www.cnblogs.com/Tirisfal/p/4051357.html