public AttackResultMessage(AttackResult shot) { Value = shot.Value; Text = shot.Text; Row = shot.Row; Col = shot.Column; }
private void pbcD(object sender, EventArgs e) { if (sender.Equals(pbExit)){ Exit(); } else if (sender.Equals(pbConnect) && IsHost && pbConnect.Asset == "Graphics\\host"){ pbConnect.Asset = "Graphics\\disconnect"; pbConnect.LoadContent(Content, new Rectangle(0, 0, vp.Width, 4 * vp.Height / 12)); if (_networkManager.Running) _networkManager.Disconnect(); str = _networkManager.Running.ToString(); } else if (sender.Equals(pbConnect) && IsHost && pbConnect.Asset == "Graphics\\disconnect"){ pbConnect.Asset = "Graphics\\host"; pbConnect.LoadContent(Content, new Rectangle(0, 0, vp.Width, 4 * vp.Height / 12)); if (_networkManager.Running) _networkManager.Disconnect(); str = _networkManager.Running.ToString(); } else if (sender.Equals(pbConnect) && pbConnect.Asset == "Graphics\\connect"){ pbConnect.Asset = "Graphics\\disconnect"; pbConnect.LoadContent(Content, new Rectangle(0, 0, vp.Width, 4 * vp.Height / 12)); if (_networkManager.Running) _networkManager.Disconnect(); str = _networkManager.Running.ToString(); } else if (sender.Equals(pbConnect) && pbConnect.Asset == "Graphics\\disconnect"){ pbConnect.Asset = "Graphics\\connect"; pbConnect.LoadContent(Content, new Rectangle(0, 0, vp.Width, 4 * vp.Height / 12)); if (_networkManager.Running) _networkManager.Disconnect(); str = _networkManager.Running.ToString(); } else if (sender.Equals(pbViewHide) && pbViewHide.Asset == "Graphics\\view"){ // HIDE THE SHIPS pbViewHide.Asset = "Graphics\\hide"; pbViewHide.LoadContent(Content, new Rectangle(0, 0, vp.Width, 6 * vp.Height / 12)); player1.EnemyGrid.Cheat = false; } else if (sender.Equals(pbViewHide) && pbViewHide.Asset == "Graphics\\hide"){ // VIEW THE SHIPS pbViewHide.Asset = "Graphics\\view"; pbViewHide.LoadContent(Content, new Rectangle(0, 0, vp.Width, 6 * vp.Height / 12)); player1.EnemyGrid.Cheat = true; str = "This easter egg cheat isn't working properly! Sorry!"; } else if (sender.Equals(pbNewGame)){ pbNewGame.Texture = Content.Load<Texture2D>("Graphics\\randomize"); player1.Reset(); str = "RANDOMIZING..."; newAttack = default(AttackResult); // SETS TO NULL } }
private void HandleVector(NetIncomingMessage im) { var message = new VectorMessage(im); int row = message.X; int col = message.Y; newAttack = player1.Shoot(row, col); TileView tileView = player1.ItemTileView(row, col); _networkManager.SendMessage(new TileViewMessage(row, col, tileView)); _networkManager.SendMessage(new PlayerStatsMessage(player1.Shots, player1.Hits, player1.Misses, player1.PlayerGrid.ShipsKilled)); _networkManager.SendMessage(new AttackResultMessage(newAttack)); if (newAttack.Value == ResultOfAttack.Destroyed) str = "Enemy destroyed your " + newAttack.Ship + "(" + (int)newAttack.Ship + ")" + "!"; else str = "Enemy " + newAttack.Text; shotCoordinate = (row + 1) + ", " + (col + 1); //change player turn if the last hit was a miss if (newAttack.Value != ResultOfAttack.ShotAlready){ currentPlayer = "YOUR TURN..."; ableToShoot = true; } else ableToShoot = false; }
private void HandleGameOver() { AttackResult ar = new AttackResult((ResultOfAttack) 1, " ", 0, 0); if (player1.AllDestroyed) ar = new AttackResult(ResultOfAttack.GameOver, ar.Ship, "WINS! GAME OVER!", shotRow, shotCol); str = "ENEMY " + ar.Text; }
private void HandleAttackResult(NetIncomingMessage im) { var message = new AttackResultMessage(im); AttackResult ar = new AttackResult((ResultOfAttack) 1, " ", 0, 0){ Value = message.Value, Text = message.Text, Row = message.Row, Column = message.Col }; if (_players[_otherPlayer].AllDestroyed){ ar = new AttackResult(ResultOfAttack.GameOver, ar.Ship, "WIN! GAME OVER!", shotRow, shotCol); _networkManager.SendMessage(new GameOverMessage()); } str = Player == player1 ? "YOU " : "ENEMY "; str += ar.Text; //change player if the last hit was a miss if (ar.Value != ResultOfAttack.ShotAlready) currentPlayer = "ENEMY'S TURN..."; else ableToShoot = true; }
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /// I N I T I A L I Z E I N I T I A L I Z E I N I T I A L I Z E I N I T I A L I Z E I N I /// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /// Allows the game to perform any initialization it needs to before starting to run. can query for required services and /// load any non-graphic related content. Calling base.Initialize will enumerate through any components and initialize them as well. protected override void Initialize() { vp = GraphicsDevice.Viewport.TitleSafeArea; shipList1 = new Dictionary<ShipName, Ship> { {ShipName.AircraftCarrier, new Ship(ShipName.AircraftCarrier)}, {ShipName.Battleship, new Ship(ShipName.Battleship)}, {ShipName.Destroyer, new Ship(ShipName.Destroyer)}, {ShipName.Submarine, new Ship(ShipName.Submarine)}, {ShipName.TugBoat, new Ship(ShipName.TugBoat)} }; shipList2 = new Dictionary<ShipName, Ship>{ {ShipName.AircraftCarrier, new Ship(ShipName.AircraftCarrier)}, {ShipName.Battleship, new Ship(ShipName.Battleship)}, {ShipName.Destroyer, new Ship(ShipName.Destroyer)}, {ShipName.Submarine, new Ship(ShipName.Submarine)}, {ShipName.TugBoat, new Ship(ShipName.TugBoat)} }; this.Window.Position = new Point(500, 500); if (IsHost) this.Window.Position = new Point(0, 0); _moveTestShip = new MoveableShip(); player1Grid = new Vector2(vp.Width / 14, 60); enemyGrid = new Vector2(8 * vp.Width / 13, 60); str = "Hit the CONNECT button to find an oppenent.\nThen hit the NEW GAME button to start playing!"; shotCoordinate = ""; currentPlayer = "BATTLESHIP"; newAttack = default(AttackResult); ableToShoot = false; easterEgg = false; _playerIndex = 0; _otherPlayer = (_playerIndex + 1) % 2; base.Initialize(); }