Beispiel #1
0
        /// <summary>Runs a 1 player game.</summary>
        public override void RunGame()
        {
            SetUpMap temp = new SetUpMap(Player1, Advanced);

            temp.ManualSetUp("Player 1", ShipList, PlaneList);

            temp = new SetUpMap(Player2, Advanced);
            temp.RandomSetUpMap(ShipList, PlaneList);

            CurCool = RNG.Next(HitCoolExRange[0], HitCoolExRange[1]);
            for (int i = 0; i < Player1.Height * Player1.Width; i++)
            {
                PossibleList.Add(i);
            }
            SelectedShip = Player1.Ships[RNG.Next(0, Player1.Ships.Count())];
            foreach (int[] i in SelectedShip.BodyList())
            {
                AttackingList.Add(i[0] + i[1] * Player1.Width);
            }

            Turn t;

            do
            {
                if (Advanced)
                {
                    t = new AdvancedTurn(Bonus, Salvo, Player1, Player2);
                }
                else
                {
                    t = new Turn(Bonus, Salvo, Player1, Player2);
                }
                PauseGame("It's time for player 1 to play, press ESC to continue.");
                t.DoManualTurnSequence();
                if (Player2.hasLost())
                {
                    PauseGame("Player 1 has won the game, press ESC to return to main menu.");
                    return;
                }

                RandomTurnSequence();
                if (Player1.hasLost())
                {
                    PauseGame("Player 1 has lost the game, press ESC to return to main menu.");
                    return;
                }
            } while (true);
        }
Beispiel #2
0
        /// <summary>Preforms a random turn sequence for the AI</summary>
        /// <returns>A bool representing if the AI scored a hit on this turn</returns>
        public bool RandomTurn()
        {
            bool outp = false;

            int x = 0;
            int y = 0;

            CurCool--;
            do
            {
                int t = 0;
                if (CurCool <= 0 && AttackingList.Count > 0)
                {
                    t = RNG.Next(0, AttackingList.Count());
                    x = AttackingList[t];
                    AttackingList.RemoveAt(t);
                }
                else if (PossibleList.Count > 0)
                {
                    t = RNG.Next(0, PossibleList.Count());
                    x = PossibleList[t];
                    PossibleList.RemoveAt(t);
                }
                else
                {
                    x = 0;
                }
                y  = (int)(x / Player1.Width);
                x %= Player1.Width;
            }while (Player1.info[x, y] != Map.Tiles.Unknown);
            if (outp = Player1.AttemptFire(new int[] { x, y }))
            {
                if (SelectedShip.Destroyed && Player1.Ships.Count > 0)
                {
                    SelectedShip = Player1.Ships[RNG.Next(0, Player1.Ships.Count())];
                    foreach (int[] i in SelectedShip.BodyList())
                    {
                        AttackingList.Add(i[0] + i[1] * Player1.Width);
                    }
                }
            }
            if (CurCool <= 0)
            {
                CurCool = RNG.Next(HitCoolExRange[0], HitCoolExRange[1]);
            }
            return(outp);
        }
Beispiel #3
0
        /// <summary>Randomly adds ships to the map. Used for the AI</summary>
        /// <param name="InQ">The list of ships to add to the map.</param>
        public void RandomAddShips(List <Ship.Ship> InQ)
        {
            Random rng = new Random();

            foreach (Ship.Ship j in InQ)
            {
                Ship.Ship i = (Ship.Ship)j.Clone();

                do
                {
                    switch (rng.Next(0, 2))
                    {
                    case 0:
                        i.LocationDirection = Ship.Ship.Direction.East;
                        break;

                    case 1:
                        i.LocationDirection = Ship.Ship.Direction.South;
                        break;
                    }


                    i.Location[0] = rng.Next(0, i.LocationDirection == Ship.Ship.Direction.East ? Map.Width - i.BodyList().Length + 1 : Map.Width);
                    i.Location[1] = rng.Next(0, i.LocationDirection == Ship.Ship.Direction.South ? Map.Height - i.BodyList().Length + 1 : Map.Height);
                } while (!Map.CanPlace(i));
                Map.AddShip(i);
            }
        }
Beispiel #4
0
        /// <summary>Preforms a random turn sequence for the AI</summary>
        /// <returns>A bool representing if the AI scored a hit on this turn</returns>
        public bool RandomTurn()
        {
            bool outp = false;

            int x = 0;
            int y = 0;

            CurCool--;
            do
            {
                int t = 0;
                if (CurCool <= 0 && AttackingList.Count > 0)
                {
                    t = RNG.Next(0, AttackingList.Count());
                    x = AttackingList[t];
                    AttackingList.RemoveAt(t);
                }
                else if (PossibleList.Count > 0)
                {
                    t = RNG.Next(0, PossibleList.Count());
                    x = PossibleList[t];
                    PossibleList.RemoveAt(t);
                }
                else
                    x = 0;
                y = (int)(x / Player1.Width);
                x %= Player1.Width;
            }
            while (Player1.info[x, y] != Map.Tiles.Unknown);
            if (outp = Player1.AttemptFire(new int[] { x, y })) {
                if (SelectedShip.Destroyed && Player1.Ships.Count > 0) {
                    SelectedShip = Player1.Ships[RNG.Next(0, Player1.Ships.Count())];
                    foreach (int[] i in SelectedShip.BodyList())
                        AttackingList.Add(i[0] + i[1] * Player1.Width);
                }

            }
            if (CurCool <= 0)
                CurCool = RNG.Next(HitCoolExRange[0], HitCoolExRange[1]);
            return outp;
        }
Beispiel #5
0
        /// <summary>Runs a 1 player game.</summary>
        public override void RunGame()
        {
            SetUpMap temp = new SetUpMap(Player1, Advanced);
            temp.ManualSetUp("Player 1", ShipList, PlaneList);

            temp = new SetUpMap(Player2, Advanced);
            temp.RandomSetUpMap(ShipList, PlaneList);

            CurCool = RNG.Next(HitCoolExRange[0], HitCoolExRange[1]);
            for (int i = 0; i < Player1.Height * Player1.Width; i++)
                PossibleList.Add(i);
            SelectedShip = Player1.Ships[RNG.Next(0, Player1.Ships.Count())];
            foreach (int[] i in SelectedShip.BodyList())
                AttackingList.Add(i[0] + i[1] * Player1.Width);

            Turn t;
            do
            {
                if (Advanced)
                    t = new AdvancedTurn(Bonus, Salvo, Player1, Player2);
                else
                    t = new Turn(Bonus, Salvo, Player1, Player2);
                PauseGame("It's time for player 1 to play, press ESC to continue.");
                t.DoManualTurnSequence();
                if (Player2.hasLost())
                {
                    PauseGame("Player 1 has won the game, press ESC to return to main menu.");
                    return;
                }

                RandomTurnSequence();
                if (Player1.hasLost())
                {
                    PauseGame("Player 1 has lost the game, press ESC to return to main menu.");
                    return;
                }
            } while (true);
        }