13、C#简易版 推箱子游戏

锺离德庸
2023-12-01
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();
        }
    }
}

 

转载于:https://www.cnblogs.com/XMH1217423419/p/4176966.html

 类似资料: