首页 > 代码库 > 13、C#简易版 推箱子游戏(请高手指点)
13、C#简易版 推箱子游戏(请高手指点)
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 推箱子2._0{ class Program { static void Main(string[] args) { #region//1 int y = 5, x = 5; string[,] a = new string[10, 11]{ {"■","■","■","■","■","■","■","■","■","■","■"}, {"■","■","■","■","■","■","■","■","■","■","■"}, {"■","■","■","■","■","■","■","■","■","■","■"}, {"■","■","■","推","箱","子","游","戏","■","■","■"}, {"■","■","■","■","■","■","■","■","■","■","■"}, {"■","■","■","■","■","■","■","■","■","■","■"}, {"■","■","■","■","■","■","■","■","■","■","■"}, {"■","■","■","■","■","■","■","■","■","■","■"}, {"■","■","■","■","■","■","■","■","■","■","■"}, {"■","■","■","■","■","■","■","■","■","■","■"} }; #endregion for (; ; ) { #region//1 if (a[0, 0] == "1 ") { if (a[4, 2] == " ") { a[4, 2] = "☆"; } if (a[7, 4] == " ") { a[7, 4] = "☆"; } if (a[2, 5] == " ") { a[2, 5] = "☆"; } if (a[5, 7] == " ") { a[5, 7] = "☆"; } }#endregion #region//2 if (a[0, 0] == "2 ") { if (a[3, 7] == " ") { a[3, 7] = "☆"; } if (a[4, 7] == " ") { a[4, 7] = "☆"; } if (a[5, 7] == " ") { a[5, 7] = "☆"; } } #endregion #region//3 if (a[0, 0] == "3 ") { if (a[5, 2] == " ") { a[5, 2] = "☆"; } if (a[5, 3] == " ") { a[5, 3] = "☆"; } if (a[6, 2] == " ") { a[6, 2] = "☆"; } if (a[6, 3] == " ") { a[6, 3] = "☆"; } } #endregion #region//4 if (a[0, 0] == "4 ") { if (a[6, 2] == " ") { a[6, 2] = "☆"; } if (a[7, 2] == " ") { a[7, 2] = "☆"; } if (a[7, 3] == " ") { a[7, 3] = "☆"; } if (a[7, 4] == " ") { a[7, 4] = "☆"; } if (a[7, 5] == " ") { a[7, 5] = "☆"; } } #endregion #region//5 if (a[0, 0] == "5 ") { if (a[5, 2] == " ") { a[5, 2] = "☆"; } if (a[6, 2] == " ") { a[6, 2] = "☆"; } if (a[7, 2] == " ") { a[7, 2] = "☆"; } } #endregion #region//6 if (a[0, 0] == "6 ") { if (a[7,1] == " ") { a[7, 1] = "☆"; } if (a[7,2] == " ") { a[7,2] = "☆"; } if (a[7,3] == " ") { a[7,3] = "☆"; } if (a[7,4] == " ") { a[7,4] = "☆"; } if (a[7,5] == " ") { a[7,5] = "☆"; } } #endregion #region//7 if (a[0, 0] == "7 ") { if (a[4, 1] == " ") { a[4, 1] = "☆"; } if (a[5, 1] == " ") { a[5, 1] = "☆"; } if (a[3, 2] == " ") { a[3, 2] = "☆"; } if (a[4, 2] == " ") { a[4, 2] = "☆"; } if (a[5, 2] == " ") { a[5, 2] = "☆"; } } #endregion #region//8 if (a[0, 0] == "8 ") { if (a[5, 4] == " ") { a[5, 4] = "☆"; } if (a[5, 5] == " ") { a[5, 5] = "☆"; } if (a[5, 6] == " ") { a[5, 6] = "☆"; } if (a[6, 4] == " ") { a[6, 4] = "☆"; } if (a[6, 5] == " ") { a[6, 5] = "☆"; } if (a[6, 6] == " ") { a[6, 6] = "☆"; } } #endregion #region for (int m = 0; m < 10; m++) { for (int n = 0; n < 11; n++) { Console.Write(a[m, n]); } Console.Write("\n"); } Console.WriteLine("请用wasd控制‘人‘移动,把■推到☆即可"); #endregion #region//wasd string b = Console.ReadKey().KeyChar.ToString(); string[,] sh = new string[10, 11]; #region//w if (b == "w") { y = y - 1; if (a[y, x] == "□") { #region Console.WriteLine("撞墙了"); y = y + 1; Console.Clear(); #endregion } else if (a[y, x] == "■") { #region if (a[y - 1, x] == "□") { Console.WriteLine("撞墙了"); y = y + 1; Console.Clear(); } else if (a[y - 1, x] == "☆") { Console.Clear(); a[y - 1, x] = "■"; a[y, x] = "人"; a[y + 1, x] = " "; } else if (a[y - 1, x] == "■") { y = y + 1; Console.Clear(); } else { Console.Clear(); a[y - 1, x] = "■"; a[y + 1, x] = " "; a[y, x] = "人"; } #endregion } else if (a[y, x] == "☆") { #region Console.Clear(); a[y, x] = "人"; a[y + 1, x] = " "; #endregion } else if (a[y + 1, x] == "☆" && a[y, x] == "人") { #region Console.Clear(); a[y + 1, x] = "☆"; a[y, x] = "人"; #endregion } else { #region Console.Clear(); a[y, x] = "人"; a[y + 1, x] = " "; #endregion } } #endregion #region//a else if (b == "a") { x = x - 1; if (a[y, x] == "□") { #region Console.WriteLine("撞墙了"); x = x + 1; Console.Clear(); #endregion } else if (a[y, x] == "■") { #region if (a[y, x - 1] == "□") { Console.WriteLine("撞墙了"); x = x + 1; Console.Clear(); } else if (a[y, x - 1] == "☆") { Console.Clear(); a[y, x - 1] = "■"; a[y, x] = "人"; a[y, x + 1] = " "; } else if (a[y, x - 1] == "■") { Console.Clear(); x = x + 1; } else { Console.Clear(); a[y, x - 1] = "■"; a[y, x + 1] = " "; a[y, x] = "人"; } #endregion } else if (a[y, x] == "☆") { #region Console.Clear(); a[y, x] = "人"; a[y, x + 1] = " "; #endregion } else { #region Console.Clear(); a[y, x] = "人"; a[y, x + 1] = " "; #endregion } } #endregion #region//s else if (b == "s") { y = y + 1; if (a[y, x] == "□") { #region Console.WriteLine("撞墙了"); y = y - 1; Console.Clear(); #endregion } else if (a[y, x] == "■") { #region if (a[y + 1, x] == "□") { Console.WriteLine("撞墙了"); y = y - 1; Console.Clear(); } else if (a[y + 1, x] == "☆") { Console.Clear(); a[y + 1, x] = "■"; a[y, x] = "人"; a[y - 1, x] = " "; } else if (a[y + 1, x] == "■") { Console.Clear(); y = y - 1; } else { Console.Clear(); a[y + 1, x] = "■"; a[y - 1, x] = " "; a[y, x] = "人"; } #endregion } else if (a[y, x] == "☆") { #region Console.Clear(); a[y, x] = "人"; a[y - 1, x] = " "; #endregion } else { #region Console.Clear(); a[y, x] = "人"; a[y - 1, x] = " "; #endregion } } #endregion #region//d else if (b == "d") { x = x + 1; if (a[y, x] == "□") { #region Console.WriteLine("撞墙了"); x = x - 1; Console.Clear(); #endregion } else if (a[y, x] == "■") { #region if (a[y, x + 1] == "□") { Console.WriteLine("撞墙了"); x = x - 1; Console.Clear(); } else if (a[y, x + 1] == "☆") { Console.Clear(); a[y, x + 1] = "■"; a[y, x] = "人"; a[y, x - 1] = " "; } else if (a[y, x + 1] == "■") { Console.Clear(); x = x - 1; } else { Console.Clear(); a[y, x + 1] = "■"; a[y, x - 1] = " "; a[y, x] = "人"; } #endregion } else if (a[y, x] == "☆") { #region Console.Clear(); a[y, x] = "人"; a[y, x - 1] = " "; #endregion } else { #region Console.Clear(); a[y, x] = "人"; a[y, x - 1] = " "; #endregion } } #endregion else { #region if (b == "1") { a[5, 7] = "■" ; a[7, 8] = "■"; } else if(b=="2") { a[4, 2] = "■" ; a[7, 4] = "■" ; a[2, 5] = "■" ; a[5, 7] = "■"; } else if (b=="3") { a[3, 7] = "■"; a[4, 7] = "■"; a[5, 7] = "■"; } else if (b == "4") { a[5, 2] = "■"; a[5, 3] = "■"; a[6, 2] = "■"; a[6, 3] = "■"; } else if (b == "5") { a[6, 2] = "■"; a[7, 2] = "■"; a[7, 3] = "■"; a[7, 4] = "■"; a[7, 5] = "■"; } else if (b == "6") { a[5, 2] = "■"; a[6, 2] = "■"; a[7, 2] = "■"; } else if (b == "7") { a[7, 1] = "■"; a[7, 2] = "■"; a[7, 3] = "■"; a[7, 4] = "■"; a[7, 5] = "■"; } else if (b == "8") { a[4, 1] = "■"; a[5, 1] = "■"; a[3, 2] = "■"; a[4, 2] = "■"; a[5, 2] = "■"; } else { Console.WriteLine("输入错误!"); } #endregion } #endregion #region//1 if (a[5, 7] == "■" && a[7, 8] == "■") { Console.Clear(); a = new string[10, 11]{ {"1 "," "," "," "," "," "," "," "," "," "," "}, {" "," "," "," ","□","□","□"," "," "," "," "}, {" "," "," "," ","□","☆","□"," "," "," "," "}, {" ","□","□","□","□"," ","□"," "," "," "," "}, {" ","□","☆","■"," ","■","□","□","□"," "," "}, {" ","□","□","□","人","■"," ","☆","□"," "," "}, {" "," "," ","□","■","□","□","□","□"," "," "}, {" "," "," ","□","☆","□"," "," "," "," "," "}, {" "," "," ","□","□","□"," "," "," "," "," "}, {" "," "," "," "," "," "," "," "," "," "," "} }; y = 5; x = 4; } #endregion #region//2 else if (a[4, 2] == "■" && a[7, 4] == "■" && a[2, 5] == "■" && a[5, 7] == "■") { Console.Clear(); a = new string[10, 11]{ {"2 ","□","□","□","□"," "," "," "," "," "," "}, {"□","人"," "," ","□"," "," "," "," "," "," "}, {"□"," ","■","■","□"," ","□","□","□"," "," "}, {"□"," ","■"," ","□"," ","□","☆","□"," "," "}, {"□","□","□"," ","□","□","□","☆","□"," "," "}, {" ","□","□"," "," "," "," ","☆","□"," "," "}, {" ","□"," "," "," ","□"," "," ","□"," "," "}, {" ","□"," "," "," ","□","□","□","□"," "," "}, {" ","□","□","□","□","□"," "," "," "," "," "}, {" "," "," "," "," "," "," "," "," "," "," "} }; y = 1; x = 1; } #endregion #region//3 else if (a[3, 7] == "■" && a[4, 7] == "■" && a[5,7] == "■") { Console.Clear(); a = new string[10, 11]{ {"3 "," "," "," "," "," "," "," "," "," "," "}, {" ","□","□","□","□","□","□","□"," "," "," "}, {" ","□"," "," "," "," "," ","□","□","□"," "}, {"□","□","■","□","□","□"," "," "," ","□"," "}, {"□"," ","人"," ","■"," "," ","■"," ","□"," "}, {"□"," ","☆","☆","□"," ","■"," ","□","□"," "}, {"□","□","☆","☆","□"," "," "," ","□"," "," "}, {" ","□","□","□","□","□","□","□","□"," "," "}, {" "," "," "," "," "," "," "," "," "," "," "}, {" "," "," "," "," "," "," "," "," "," "," "} }; y = 4; x = 2; } #endregion #region//4 else if (a[5, 2] == "■" && a[5, 3] == "■" && a[6, 2] == "■" && a[6, 3] == "■") { Console.Clear(); a = new string[10, 11]{ {"4 "," "," "," "," "," "," "," "," "," "," "}, {" "," ","□","□","□","□"," "," "," "," "," "}, {" ","□","□"," "," ","□"," "," "," "," "," "}, {" ","□","人","■"," ","□"," "," "," "," "," "}, {" ","□","□","■"," ","□","□"," "," "," "," "}, {" ","□","□"," ","■"," ","□"," "," "," "," "}, {" ","□","☆","■"," "," ","□"," "," "," "," "}, {" ","□","☆","☆","■","☆","□"," "," "," "," "}, {" ","□","□","□","□","□","□"," "," "," "," "}, {" "," "," "," "," "," "," "," "," "," "," "} }; y = 3; x = 2; } #endregion #region//5 else if (a[6, 2] == "■" && a[7, 2] == "■" && a[7, 3] == "■" && a[7, 4] == "■" && a[7, 5] == "■") { Console.Clear(); a = new string[10, 11]{ {"5 "," "," "," "," "," "," "," "," "," "," "}, {" "," ","□","□","□","□","□"," "," "," "," "}, {" "," ","□","人"," ","□","□","□"," "," "," "}, {" "," ","□"," ","■"," "," ","□"," "," "," "}, {" ","□","□","□"," ","□"," ","□","□"," "," "}, {" ","□","☆","□"," ","□"," "," ","□"," "," "}, {" ","□","☆","■"," "," ","□"," ","□"," "," "}, {" ","□","☆"," "," "," ","■"," ","□"," "," "}, {" ","□","□","□","□","□","□","□","□"," "," "}, {" "," "," "," "," "," "," "," "," "," "," "} }; y = 2; x = 3; } #endregion #region//6 else if (a[5, 2] == "■" && a[6, 2] == "■" && a[7, 2] == "■") { Console.Clear(); a = new string[10, 11]{ {"6 "," "," "," "," "," "," "," "," "," "," "}, {" "," "," ","□","□","□","□","□","□","□"," "}, {" "," ","□","□"," "," ","□"," ","人","□"," "}, {" "," ","□"," "," "," ","□"," "," ","□"," "}, {" "," ","□","■"," ","■"," ","■"," ","□"," "}, {" "," ","□"," ","■","□","□"," "," ","□"," "}, {"□","□","□"," ","■"," ","□"," ","□","□"," "}, {"□","☆","☆","☆","☆","☆"," "," ","□"," "," "}, {"□","□","□","□","□","□","□","□","□"," "," "}, {" "," "," "," "," "," "," "," "," "," "," "} }; y = 2; x = 8; } #endregion #region//7 else if (a[7, 1] == "■" && a[7, 2] == "■" &&a[7, 3] == "■" &&a[7, 4] == "■" &&a[7, 5] == "■" ) { Console.Clear(); a = new string[10, 11]{ {"7 "," "," "," "," "," "," "," "," "," "," "}, {" "," "," ","□","□","□","□","□","□"," "," "}, {" ","□","□","□"," "," "," "," ","□"," "," "}, {"□","□","☆"," ","■","□","□"," ","□","□"," "}, {"□","☆","☆","■"," ","■"," "," ","人","□"," "}, {"□","☆","☆"," ","■"," ","■"," ","□","□"," "}, {"□","□","□","□","□","□"," "," ","□"," "," "}, {" "," "," "," "," ","□","□","□","□"," "," "}, {" "," "," "," "," "," "," "," "," "," "," "}, {" "," "," "," "," "," "," "," "," "," "," "} }; y = 4; x = 8; } #endregion #region//8 else if (a[4, 1] == "■" && a[5, 1] == "■" && a[3, 2] == "■" && a[4, 2] == "■" && a[5, 2] == "■") { Console.Clear(); a = new string[10, 11]{ {"8 "," "," "," "," "," "," "," "," "," "," "}, {" ","□","□","□","□","□","□","□","□","□"," "}, {" ","□"," "," ","□","□"," "," "," ","□"," "}, {" ","□"," "," "," ","■"," "," "," ","□"," "}, {" ","□","■"," ","□","□","□"," ","■","□"," "}, {" ","□"," ","□","☆","☆","☆","□"," ","□"," "}, {"□","□"," ","□","☆","☆","☆","□"," ","□","□"}, {"□"," ","■"," "," ","■"," "," ","■"," ","□"}, {"□"," "," "," "," "," ","□"," ","人"," ","□"}, {"□","□","□","□","□","□","□","□","□","□","□"} }; y = 8; x = 8; } #endregion #region else { if (a[5, 4] == "■" && a[5, 5] == "■" && a[5, 6] == "■" && a[6, 4] == "■" && a[6, 5] == "■" && a[6, 6] == "■") { break; } } #endregion } Console.WriteLine("恭喜过关!"); Console.ReadLine(); } }}
13、C#简易版 推箱子游戏(请高手指点)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。