Exemple #1
0
        static void Main(string[] args)
        {
            Console.CursorVisible = false;

            Player p = new Player("Human");
            AI     a = new AI("Bot");

            GameEngine.DrawPlayerMap();
            GameEngine.DrawHiddenEnemyMap();

            GameEngine.ShowInstructions();


            a.CreatingAIMapAlgorithm(); // works almost always (95%)
            p.CreatingPlayerMap();



            while (p.Health > 0 && a.Health > 0)
            {
                a.Health = p.MakeStep(a.Health);
                GameEngine.DrawHiddenEnemyMap();
                p.Health = a.MakeStep(p.Health);
                GameEngine.DrawPlayerMap();
                GameEngine.ShowInfo(0, $"Player HP: {p.Health}\t\t AI HP {a.Health}");
            }

            if (p.Health > 0)
            {
                Console.WriteLine("\n Player winn!");
            }
            else
            {
                Console.WriteLine("\n AI winn!");
            }

            GameEngine.DrawEnemyMap();
            // TO DO NEXT11

            Console.ReadLine();
        }
Exemple #2
0
        public void CreatingPlayerMap()
        {
            int  currentCell_X = 2, currentCell_Y = 1;
            bool fixSharp = false;

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.SetCursorPosition(currentCell_X, currentCell_Y);
            Console.Write("@");

            int stage = 4;

            while (currentBoats <= 19)
            {
                if (currentBoats >= 4 && currentBoats < 10)
                {
                    stage = 3;
                }
                else if (currentBoats >= 10 && currentBoats < 16)
                {
                    stage = 2;
                }
                else if (currentBoats >= 16)
                {
                    stage = 1;
                }

                GameEngine.ShowInfo(stage, message);
                message = null;

                ConsoleKey direction = Console.ReadKey(true).Key;

                if (direction == ConsoleKey.LeftArrow || direction == ConsoleKey.A)
                {
                    if (currentCell_X > 2)
                    {
                        if (!fixSharp)
                        {
                            Console.SetCursorPosition(currentCell_X, currentCell_Y);
                            Console.Write('.');
                        }
                        GameEngine.DrawPlayerMap();
                        currentCell_X -= 2;
                        Console.SetCursorPosition(currentCell_X, currentCell_Y);
                        Console.Write("@");
                        fixSharp = false;
                    }
                }
                else if (direction == ConsoleKey.RightArrow || direction == ConsoleKey.D)
                {
                    if (currentCell_X < 20)
                    {
                        if (!fixSharp)
                        {
                            Console.SetCursorPosition(currentCell_X, currentCell_Y);
                            Console.Write('.');
                        }
                        GameEngine.DrawPlayerMap();
                        currentCell_X += 2;
                        Console.SetCursorPosition(currentCell_X, currentCell_Y);
                        Console.Write("@");
                        fixSharp = false;
                    }
                }
                else if (direction == ConsoleKey.UpArrow || direction == ConsoleKey.W)
                {
                    if (currentCell_Y > 1)
                    {
                        if (!fixSharp)
                        {
                            Console.SetCursorPosition(currentCell_X, currentCell_Y);
                            Console.Write('.');
                        }
                        GameEngine.DrawPlayerMap();
                        currentCell_Y--;
                        Console.SetCursorPosition(currentCell_X, currentCell_Y);
                        Console.Write("@");
                        fixSharp = false;
                    }
                }
                else if (direction == ConsoleKey.DownArrow || direction == ConsoleKey.S)
                {
                    if (currentCell_Y < 9)
                    {
                        if (!fixSharp)
                        {
                            Console.SetCursorPosition(currentCell_X, currentCell_Y);
                            Console.Write('.');
                        }
                        GameEngine.DrawPlayerMap();
                        currentCell_Y++;
                        Console.SetCursorPosition(currentCell_X, currentCell_Y);
                        Console.Write("@");
                        fixSharp = false;
                    }
                }
                else if (direction == ConsoleKey.Enter)
                {
                    ConsoleKey location = 0;
                    if (stage != 1)
                    {
                        location = Console.ReadKey(true).Key;
                    }

                    SetShip(stage, currentCell_X, currentCell_Y, location);
                    fixSharp = true;
                    GameEngine.DrawPlayerMap();
                }
            }
        }