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)
                    {
    
                    }
                }
            }
        }
    }
  • 相关阅读:
    Genymotion安装与集成开发指南
    近期遇到的Android问题解决与总结
    关于Android Studio乱码的解决办法
    菜鸟程序员如何才能快速提高自己的技术
    android不能调试解决方法
    导入工程出现@Override错误
    读取本地文件的权限问题
    混合app开发
    JNI 实战全面解析
    Android性能优化
  • 原文地址:https://www.cnblogs.com/languang/p/4535363.html
Copyright © 2011-2022 走看看