コード例 #1
0
        public void Step(Labirint lab, Direction direction)
        {
            switch (direction)
            {
            case Direction.Up:
            {
                var currCell = lab[_hero.X, _hero.Y - 1];
                TryToStepInCurrentCell(lab, currCell);
                break;
            }

            case Direction.Down:
            {
                var currCell = lab[_hero.X, _hero.Y + 1];
                TryToStepInCurrentCell(lab, currCell);
                break;
            }

            case Direction.Left:
            {
                var currCell = lab[_hero.X - 1, _hero.Y];
                TryToStepInCurrentCell(lab, currCell);
                break;
            }

            case Direction.Right:
            {
                var currCell = lab[_hero.X + 1, _hero.Y];
                TryToStepInCurrentCell(lab, currCell);
                break;
            }
            }
        }
コード例 #2
0
        public void StartGame()
        {
            generator = new LabGenerator(20, 15);
            lab       = generator.GetLabirint();
            ConsoleKeyInfo key;

            hero = Hero.GetHero;
            while (true)
            {
                Drawer.Draw(lab);

                CheckOnAnyCoins();

                key = Console.ReadKey();
                switch (key.Key)
                {
                case ConsoleKey.W:
                case ConsoleKey.UpArrow:
                {
                    hero.Step(lab, Direction.Up);
                    break;
                }

                case ConsoleKey.D:
                case ConsoleKey.RightArrow:
                {
                    hero.Step(lab, Direction.Right);
                    break;
                }

                case ConsoleKey.S:
                case ConsoleKey.DownArrow:
                {
                    hero.Step(lab, Direction.Down);
                    break;
                }

                case ConsoleKey.A:
                case ConsoleKey.LeftArrow:
                {
                    hero.Step(lab, Direction.Left);
                    break;
                }

                case ConsoleKey.R:
                {
                    StartNewGame();
                    break;
                }

                case ConsoleKey.Escape:
                {
                    return;
                }

                default: break;
                }
            }
        }
コード例 #3
0
 private void TryToStepInCurrentCell(Labirint lab, BaseConsoleCell currCell)
 {
     if (currCell != null && currCell.TryToStep)
     {
         if (currCell is Coin)
         {
             lab.Cells = lab.Cells.Select(cell => cell.X == currCell.X && cell.Y == currCell.Y ? new Ground(currCell.X, currCell.Y) : cell).ToList();
         }
         _hero.X = currCell.X;
         _hero.Y = currCell.Y;
     }
 }
コード例 #4
0
        public Labirint GetLabirint()
        {
            if (labirint != null)
            {
                labirint = new Labirint(labirint.Width, labirint.Height);

                GetReadyLabirint(labirint.Cells.First());
            }

            CreateCoins();

            return(labirint);
        }
コード例 #5
0
ファイル: Drawer.cs プロジェクト: alfredq6/LabirintEPAM2019
        public static void Draw(Labirint labirint)
        {
            Console.Clear();
            var hero = Hero.GetHero;

            for (int i = 0; i < labirint.Width + 2; i++)
            {
                WriteSide();
            }

            Console.WriteLine();


            for (int y = 0; y < labirint.Height; y++)
            {
                WriteSide();

                for (int x = 0; x < labirint.Width; x++)
                {
                    var currentCell = labirint[x, y];

                    if (hero.X == currentCell.X && hero.Y == currentCell.Y)
                    {
                        hero.Write();
                    }
                    else
                    {
                        currentCell.Write();
                    }
                }

                WriteSide();
                Console.WriteLine();
            }

            for (int i = 0; i < labirint.Width + 2; i++)
            {
                WriteSide();
            }
            Console.WriteLine();
            Console.WriteLine("Left to collect coin:" + labirint.Cells.OfType <Coin>().Count());
        }
コード例 #6
0
 private void StartNewGame()
 {
     lab    = generator.GetLabirint();
     hero.X = 0;
     hero.Y = 0;
 }
コード例 #7
0
 public LabGenerator(int _width, int _height)
 {
     labirint = new Labirint(_width, _height);
 }