public NewGame(Microsoft.Xna.Framework.Game game) : base(game) { this.game = game; this.playing = false; this.ship = new Ship.Ship(300, 100); this.planets = new Planets(); this.world = new World(this.game.GraphicsDevice.Viewport.AspectRatio); this.network = new Network(); this.time = 0.0f; }
public NewGame(Microsoft.Xna.Framework.Game game) : base(game) { this.game = game; this.playing = false; this.ship = new Ship.Ship(); this.planets = new Planets(); this.world = new World(this.game.GraphicsDevice.Viewport.AspectRatio); this.network = new Network(); this.time = 0.0f; this.currentItem = MenuList.game; this.exitMenu = new ExitMenu.ExitMenu(); }
/// <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; }
/// <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); }