• 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("
    ");
                    }
                    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();
            }
        }
    }
  • 相关阅读:
    Linux0.11之初识Makefile/build.c
    主机(windows10)虚拟机(ubuntu18)arm板(linux3.4)相互ping通
    windows上利用dhcpsrv搭建DHCP服务器
    《剑指offer》面试题27 二叉搜索树与双向链表 Java版
    《剑指offer》面试题26 复杂链表的复制 Java版
    《剑指offer》面试题25 二叉树中和为某一值的路径 Java版
    《剑指offer》面试题24 二叉搜索树的后序遍历序列 Java版
    异常处理
    三元表达式、列表推导式、生成器表达式、匿名函数、内置函数、递归调用与二分法的简单认识
    迭代器与生成器
  • 原文地址:https://www.cnblogs.com/XMH1217423419/p/4176966.html
Copyright © 2020-2023  润新知