예제 #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            _level = LevelParser.FromFile("Resources/Levels/Level0.txt");
            _game  = new GameImplementation(_level);

            _graphics.PreferredBackBufferWidth  = _level.Width * Size + 2;
            _graphics.PreferredBackBufferHeight = _level.Height * Size + 2;
            _graphics.ApplyChanges();

            base.Initialize();
        }
예제 #2
0
        private static void Main(string[] args)
        {
            var lines = File.ReadAllLines(@"Resources\Levels\level0.txt");
            var level = LevelParser.Parse(lines);
            var game  = new SokobanGame(level);

            while (true)
            {
                Console.Clear();
                Display(game.Level);

                if (game.HasWon())
                {
                    Console.WriteLine("\nYou won!\n");
                    return;
                }

                Console.WriteLine("\nWASD or arrow keys to move\nEsc to exit");

                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.W:
                case ConsoleKey.UpArrow:
                    game.MovePlayer(Direction.North);
                    break;

                case ConsoleKey.D:
                case ConsoleKey.RightArrow:
                    game.MovePlayer(Direction.East);
                    break;

                case ConsoleKey.S:
                case ConsoleKey.DownArrow:
                    game.MovePlayer(Direction.South);
                    break;

                case ConsoleKey.A:
                case ConsoleKey.LeftArrow:
                    game.MovePlayer(Direction.West);
                    break;
                }
            }
        }