zoukankan      html  css  js  c++  java
  • 推箱子

    推箱子
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Class1
        {
            public static void Main(string[] args)
            {
                //0 空地,1小人,2箱子,-1墙,3-目的地
                int[,] map = new int[5, 5]
                {
                    {-1,-1,-1,-1,-1},
                    {-1,0,0,0,-1},
                    {-1,1,2,3,-1},
                    {-1,0,0,0,-1},
                    {-1,-1,-1,-1,-1}
                };
                int okx = 2, oky = 3;
                int x=2, y=1; //小人的当前位置
                for (; ; )
                {
                    Console.Clear();//清屏
                    //显示出来
                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            if (map[i, j] == 1)
                            {
                                Console.Write("");
                            }
                            else if (map[i, j] == 2)
                            {
                                Console.Write("");
                            }
                            else if (map[i, j] == -1)
                            {
                                Console.Write("");
                            }
                            else if (map[i, j] == 3)
                            {
                                Console.Write("");
                            }
                            else
                            {
                                Console.Write("  ");
                            }
                        }
                        Console.WriteLine();
                    }
                    //等待按键
                    ConsoleKeyInfo info = Console.ReadKey();
                    if (info.Key == ConsoleKey.RightArrow)
                    {
                        if (y + 1 > 4)
                        {
                            Console.Write("a");
                            continue;
                        }
                        if (map[x, y + 1] != -1 )
                        {
                            if (map[x, y + 1] == 2)
                            {
                                if (map[x, y + 2] == -1)
                                {
                                    Console.Write("a");
                                    continue;
                                }
                                if (map[x, y + 2] == 3)
                                {
                                    Console.Clear();
                                    Console.WriteLine("成功");
                                    break;
                                }
                                //箱子动
                                int t = map[x, y + 1];
                                map[x, y + 1] = map[x, y + 2];
                                map[x, y + 2] = t;
                                
                            }
                            //人动
                            int temp = map[x, y];
                            map[x, y] = map[x, y + 1];
                            map[x, y + 1] = temp;
    
                            y++;
                            
                        }
                        else
                        {
                            Console.Write("a");
                        }
                    }
                    else if (info.Key == ConsoleKey.UpArrow)
                    {
    
                    }
                    else if (info.Key == ConsoleKey.LeftArrow)
                    {
                        if (y - 1 < 0)
                        {
                            Console.Write("a");
                            continue;
                        }
                        if (map[x, y - 1] != -1 )
                        {
                            int temp = map[x, y];
                            map[x, y] = map[x, y - 1];
                            map[x, y - 1] = temp;
    
                            y--;
                        }
                        else
                        {
                            Console.Write("a");
                        }
                    }
                    else if (info.Key == ConsoleKey.DownArrow)
                    {
    
                    }
                }
            }
        }
    }
  • 相关阅读:
    使用telnet模拟http请求
    07_Python变量内存地址、小数据池
    04_Linux命令
    03_Linux文件和目录
    06_Python Encoded
    05_Python Format Operation
    04_Python Data Structures
    02_Python基本数据类型
    01_软件开发流程
    03_线性表应用一:栈
  • 原文地址:https://www.cnblogs.com/languang/p/4535363.html
Copyright © 2011-2022 走看看