博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c#推箱子
阅读量:4519 次
发布时间:2019-06-08

本文共 3231 字,大约阅读时间需要 10 分钟。

  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

你可能感兴趣的文章
动态规划位置hdu 4540 威威猫系列故事——打地鼠(动态规划)
查看>>
阿里巴巴卖空阿里巴巴入股新浪微博抑制投资者卖空行为
查看>>
分析打开hdu 3335 (最小路径覆盖)
查看>>
添加源ubuntu_x64 安装 Adobe Reader
查看>>
NFS-heartbeat-drbd模拟NFS高可用
查看>>
SQL Server性能调优:资源管理之内存管理篇(上)
查看>>
javaScript 基础知识
查看>>
接近开关,光耦
查看>>
基于visual Studio2013解决C语言竞赛题之1033数字交换
查看>>
给datalist加自动编号(解决博客的第XX楼)
查看>>
BZOJ3282: Tree (LCT模板)
查看>>
ES6中变量的解构赋值
查看>>
编译器C-Free V352注册算法分析
查看>>
数据绑定控件Reperter
查看>>
【codeforces】【比赛题解】#937 CF Round #467 (Div. 2)
查看>>
剑指Offer学习笔记(3)——解决面试题的思路
查看>>
.NET Framework基础知识(二)(转载)
查看>>
Yii DataProvider
查看>>
BestCoder Round #14 B 称号 Harry And Dig Machine 【TSP】
查看>>
hdu 1114 Piggy-Bank
查看>>