public override void Render(Board board)
 {
     Console.WriteLine("Das ist mein Feld: ");
     ConsoleOutput.CreateMatchField(board, true);
 }
Пример #2
0
        public static void Main()
        {
            //menu
            var menu          = ConsoleOutput.Greeting();
            var rendererEnemy = new GameRendererEnemy();
            var rendererKI    = new GameRendererBase();
            var rendererMine  = new GameRendererMine();

            switch (menu)
            {
            case "Mensch":
                var      boardHu = Initialize.Start(ConsoleOutput.SizeMatchField());
                GameBase playHu  = new HumanPlayer(boardHu);
                //Spiel starten
                while (playHu.board.shipfields > 0)
                {
                    playHu.Render(new GameRendererEnemy());
                    playHu.Start();
                    Console.Clear();
                }
                //playHu.Render(rendererEnemy);
                playHu.GameWon();
                break;

            case "Ki":
                var      boardAi = Initialize.Start(ConsoleOutput.SizeMatchField());
                GameBase playAi  = new AIPlayer(boardAi);
                //Spiel starten
                while (playAi.board.shipfields > 0)
                {
                    playAi.Render(new GameRendererEnemy());
                    Console.ReadLine();
                    playAi.Start();
                }
                playAi.GameWon();
                break;

            case "Mensch vs KI":
                var size = ConsoleOutput.SizeMatchField();

                var      boardAi2 = Initialize.Start(size);
                GameBase playAi2  = new AIPlayer(boardAi2);

                var      boardHu2 = Initialize.Start(size);
                GameBase playHu2  = new HumanPlayer(boardHu2);

                var playHuVsKi = new VersusPlay(playAi2, playHu2);
                playHuVsKi.start();
                break;

            case "Mensch vs Mensch":
                var size2 = ConsoleOutput.SizeMatchField();

                var      boardHu3 = Initialize.Start(size2);
                GameBase playHu3  = new HumanPlayer(boardHu3);

                var      boardHu4 = Initialize.Start(size2);
                GameBase playHu4  = new HumanPlayer(boardHu4);

                var playHuVsHu = new VersusPlay(playHu3, playHu4);
                playHuVsHu.start();
                break;
            }
            Console.ReadLine();
        }
Пример #3
0
 public override void GameWon(int winner = 0)
 {
     ConsoleOutput.GameWonHu(board.countTry);
 }
Пример #4
0
 public override void ShipIsSunk()
 {
     ConsoleOutput.ShipIsSunk();
 }
        public Board PlaceShips(Board data)
        {
            //Es Wird eine Liste erstellt mit Schiffen einer bestimmten Größen
            List <int> ships = new List <int> {
                5, 4, 4, 3, 3, 3, 2, 2, 2, 2
            };

            //Es wird die Größe des Spielfeldes ermittelt
            var size = data.Matchfield.GetLength(0);

            //eine Variable zum zählen der Schiffe wird erstellt
            int shipsplaced = 0;

            //Die Liste der Schiffe wird gemischt
            Shuffle.List(ships);

            //Für jedes Schiff werden die folgenden Schritte durchgeführt
            foreach (int ship in ships)
            {
                var allowedToPlace = false;
                int xPositionStart = 0;
                int yPositionStart = 0;
                int directory      = 0;
                int trytobuild     = 0;
                while (!allowedToPlace && trytobuild < 10000)
                {
                    trytobuild++;
                    Random random = new Random();
                    xPositionStart = random.Next(0, size);
                    yPositionStart = random.Next(0, size);
                    directory      = random.Next(0, 2);
                    if ((directory == 0 && (xPositionStart + ship > size)) || (directory == 1 && (yPositionStart + ship > size)))
                    {
                        allowedToPlace = false;
                    }
                    else
                    {
                        for (int i = 0; i < ship; i++)
                        {
                            var xPositionCheck = xPositionStart;
                            var yPositioncheck = yPositionStart;
                            if (directory == 0)
                            {
                                xPositionCheck += i;
                            }
                            else
                            {
                                yPositioncheck += i;
                            }
                            if (data.Matchfield[xPositionCheck, yPositioncheck].Placing)
                            {
                                allowedToPlace = true;
                            }
                            else
                            {
                                allowedToPlace = false;
                            }
                            if (!allowedToPlace)
                            {
                                break;
                            }
                        }
                    }
                }
                if (trytobuild == 10000)
                {
                    ConsoleOutput.CantPlaceAllShips(shipsplaced);
                    return(data);
                }
                int xPosition = xPositionStart;
                int yPosition = yPositionStart;
                for (int i = 0; i < ship; i++)
                {
                    if (directory == 0)
                    {
                        xPosition = xPositionStart + i;
                    }
                    else
                    {
                        yPosition = yPositionStart + i;
                    }
                    data.Matchfield[xPosition, yPosition].Ship = true;
                }
                shipsplaced++;
                setProhibitedFields(data, size);
            }
            return(data);
        }
Пример #6
0
 public override void Render(Board board)
 {
     Console.WriteLine("Das ist das Gegner Feld: ");
     ConsoleOutput.CreateMatchField(board);
 }