码迷,mamicode.com
首页 > Windows程序 > 详细

13、C#简易版 推箱子游戏(请高手指点)

时间:2014-12-21 20:41:13      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:

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#简易版 推箱子游戏(请高手指点)

标签:

原文地址:http://www.cnblogs.com/XMH1217423419/p/4176966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!