c#推箱子

it2022-05-07  32

  string[,] map = new string[10, 10]            {        {"■","■","■","■","■","■","■","■","■","■", },        {"■"," "," "," "," "," "," "," ","☆","■", },        {"■"," "," "," "," "," "," "," "," ","■", },        {"■"," "," "," "," "," "," "," "," ","■", },        {"■"," "," "," "," "," "," "," "," ","■", },        {"■"," "," "," "," "," "," "," "," ","■", },        {"■"," "," ","□"," "," "," "," "," ","■", },        {"■"," "," "," "," "," "," "," "," ","■", },        {"■","♀"," "," "," "," "," "," "," ","■", },        {"■","■","■","■","■","■","■","■","■","■", } };            int x = 1;            int y = 8;            int endx1 = 1, endy1 = 8;            while (true)            {                Console.Clear();                #region 打印地图                for (int i = 0; i < 10; i++)            {                for (int j = 0; j < 10; j++)                {                    Console.Write(map[i, j]);                }Console.WriteLine();               }            #endregion                           if(map[endx1,endy1]== "★")                {                    Console.WriteLine("恭喜你,过关!");                    break;                }                          ConsoleKeyInfo key = Console.ReadKey();                     if (key.Key.ToString() == "UpArrow")            {                    if(map[y-1,x]== "■")                    {                    }                    else {                        if(map[y-1,x]== "□"&&map[y-2,x]!= "■")                        {                            if(map[y-2,x]== "☆") {                                map[y - 2, x] = "★";                                map[y - 1, x] = " ";                                string temp = map[y, x];                                map[y, x] = map[y - 1, x];                                map[y - 1, x] = temp;                                y--;                            }                            else if(map[y-2,x]==" ")                            {                                string temp = map[y - 1, x];                                map[y - 1, x] = map[y - 2, x];                                map[y - 2, x] = temp;                                temp = map[y, x];                                map[y, x] = map[y - 1, x];                                map[y - 1, x] = temp;                                y--;                            }                                                   }                                               else if(map[y-1,x]==" ")                        {                            string temp = map[y, x];                            map[y, x] = map[y - 1, x];                            map[y - 1, x] = temp;                            y--;                        }                    }                               }            else if (key.Key.ToString() == "DownArrow")            {                    if (map[y + 1, x] == "■")                    {                    }                    else                    {                        if (map[y + 1, x] == "□" && map[y + 2, x] != "■")                        {                            if (map[y + 2, x] == "☆")                            {                                map[y + 2, x] = "★";                                map[y + 1, x] = " ";                                string temp = map[y, x];                                map[y, x] = map[y + 1, x];                                map[y + 1, x] = temp;                                y++;                            }                            else if (map[y + 2, x] == " ")                            {                                string temp = map[y + 1, x];                                map[y + 1, x] = map[y + 2, x];                                map[y + 2, x] = temp;                                temp = map[y, x];                                map[y, x] = map[y + 1, x];                                map[y + 1, x] = temp;                                y++;                            }                        }                        else if (map[y + 1, x] == " ")                        {                            string temp = map[y, x];                            map[y, x] = map[y + 1, x];                            map[y + 1, x] = temp;                            y++;                        }                    }                                   }            else if (key.Key.ToString() == "LeftArrow")            {                    if (map[y, x-1] == "■")                    {                    }                    else                    {                        if (map[y, x-1] == "□" && map[y, x-2] != "■")                        {                            if (map[y, x-2] == "☆")                            {                                map[y , x-2] = "★";                                map[y, x-1] = " ";                                string temp = map[y, x];                                map[y, x] = map[y, x-1];                                map[y , x-1] = temp;                                x--;                            }                            else if (map[y , x-2] == " ")                            {                                string temp = map[y, x-1];                                map[y, x-1] = map[y, x-2];                                map[y , x-2] = temp;                                temp = map[y, x];                                map[y, x] = map[y, x-1];                                map[y , x-1] = temp;                               x--;                            }                        }                        else if (map[y, x-1] == " ")                        {                            string temp = map[y, x];                            map[y, x] = map[y , x-1];                            map[y , x-1] = temp;                           x--;                        }                    }                                   }            else if (key.Key.ToString() == "RightArrow")            {                    if (map[y, x+1] == "■")                    {                    }                    else                    {                        if (map[y, x+1] == "□" && map[y , x+2] != "■")                        {                            if (map[y, x +2] == "☆")                            {                                map[y, x + 2] = "★";                                map[y , x+1] = " ";                                string temp = map[y, x];                                map[y, x] = map[y, x + 1];                                map[y, x + 1] = temp;                                x++;                            }                            else if (map[y, x + 2] == " ")                            {                                string temp = map[y, x + 1];                                map[y, x + 1] = map[y, x + 2];                                map[y, x + 2] = temp;                                temp = map[y, x];                                map[y, x] = map[y, x + 1];                                map[y, x + 1] = temp;                                x++s;                            }                        }                        else if (map[y , x+1] == " ")                        {                            string temp = map[y, x];                            map[y, x] = map[y, x+1];                            map[y , x+1] = temp;                            x++;                        }                    }                }            else {                Console.WriteLine("输入错误");            }            }            Console.ReadKey();

转载于:https://www.cnblogs.com/sistrong-5880558/p/7805933.html

相关资源:C#推箱子小游戏

最新回复(0)