The base class for any event created in the MBC core framework. Provides a message string that describes the generated event.
Ejemplo n.º 1
0
 private void PlaceShips(Event ev)
 {
     while (!ShipList.AreShipsPlaced(Player.Ships))
     {
         ShipList.PlaceShip(Player.Ships, RandomCoordinates(), RandomShipOrientation());
     }
 }
Ejemplo n.º 2
0
 private void HandlePlayerAdd(Event ev)
 {
     MatchAddPlayerEvent evCasted = (MatchAddPlayerEvent)ev;
     Player plr = evCasted.Player;
     HookPlayerEvents(plr);
     oldController.Registers.Add(plr.ID, new Register(plr.ID, plr.Name));
 }
Ejemplo n.º 3
0
 private void CreateShots(Event ev)
 {
     shotsRemain = new List<Shot>();
     foreach (Player opponent in Player.Match.Players)
     {
         if (opponent == Player) continue;
         QueueShotsPlayer(opponent);
     }
 }
Ejemplo n.º 4
0
 private void HandlePlayerLose(Event ev)
 {
     Player plr = ((PlayerLostEvent)ev).Player;
     if (plr == myPlayer)
     {
         oldController.RoundLost();
     }
     else
     {
         oldController.OpponentDestroyed(plr.ID);
     }
 }
Ejemplo n.º 5
0
        private void shipHit(Event ev)
        {
            ShipHitEvent shipHitEvent = (ShipHitEvent)ev;

            Player owner = shipHitEvent.Ship.Owner;
            if (owner != Player) {

                bool sink = shipHitEvent.Ship.IsSunk();
                Coordinates coords = shipHitEvent.HitCoords;

                bot.shipHit(coords, sink);
            } else {
                //other player has made a hit
            }
        }
Ejemplo n.º 6
0
 private void HandlePlayerShot(Event ev)
 {
     PlayerShotEvent evCasted = (PlayerShotEvent)ev;
     Player plr = evCasted.Player;
     Shot shot = evCasted.Shot;
     if (plr == myPlayer)
     {
         Ship shipHit = ShipList.GetShipAt(shot);
         if (shipHit == null)
         {
             oldController.ShotMiss(shot);
         }
         else
         {
             oldController.ShotHit(shot, shipHit.IsSunk());
         }
     }
     else
     {
         oldController.OpponentShot(shot);
     }
 }
Ejemplo n.º 7
0
 private void Shoot(Event ev)
 {
     int shotIdx = rand.Next(shotsRemain.Count);
     Shot randShot = shotsRemain[shotIdx];
     shotsRemain.RemoveAt(shotIdx);
     Player.Shoot(randShot);
 }
Ejemplo n.º 8
0
 private void roundBeginEvent(Event ev)
 {
     RoundBeginEvent matchBeginEvent = (RoundBeginEvent)ev;
     this.newRound();
 }
Ejemplo n.º 9
0
 public void UpdateWinner(Event ev)
 {
     var playerWon = (PlayerWonEvent)ev;
     MessageBox.Show("The winner is " + playerWon.Player.Name + " in " + playerWon.Player.ShotsMade.Count + " shots!");
     if (playerWon.Player == user)
     {
         userScore++;
     }
     else
     {
         compScore++;
     }
     showStats();
 }
Ejemplo n.º 10
0
 private void matchBeginEvent(Event ev)
 {
     this.newMatch();
 }
Ejemplo n.º 11
0
 private void matchBeginEvent(Event ev)
 {
     MatchBeginEvent matchBeginEvent = (MatchBeginEvent)ev;
     this.newMatch();
 }
Ejemplo n.º 12
0
 private void HandleTurnBegin(Event ev)
 {
     Shot shotMade = oldController.MakeShot();
     shotMade.ReceiverPlr = myPlayer.Match.Players.Where(plr => plr.ID == shotMade.Receiver).First();
     myPlayer.Shoot(shotMade);
 }
Ejemplo n.º 13
0
 private void playerTurnBeginEvent(Event ev)
 {
     this.turnStart();
 }
Ejemplo n.º 14
0
 private void HandleTeamAdd(Event ev)
 {
     Team team = ((MatchTeamAddEvent)ev).Team;
     oldController.Teams.Add(team.ID, team);
 }
Ejemplo n.º 15
0
 private void HandleTeamRemove(Event ev)
 {
     Team team = ((MatchTeamRemoveEvent)ev).Team;
     oldController.Teams.Remove(team.ID);
 }
Ejemplo n.º 16
0
 private void HandleRoundBegin(Event ev)
 {
     oldController.NewRound();
     foreach (Ship ship in oldController.PlaceShips().ToList())
     {
         Ship existingShip = myPlayer.Ships.Where(x => x.Length == ship.Length && !x.IsPlaced).First();
         if (existingShip != null)
         {
             existingShip.Place(ship.Location, ship.Orientation);
         }
     }
 }
Ejemplo n.º 17
0
 private void HandlePlayerWin(Event ev)
 {
     oldController.RoundWon();
 }
Ejemplo n.º 18
0
 public static void EventGenerated(Event ev)
 {
     Console.WriteLine(ev.GetType().Name);
 }
Ejemplo n.º 19
0
        public void UpdateShipDestroyed(Event ev)
        {
            ShipDestroyedEvent des = (ShipDestroyedEvent) ev;

            if (des.Ship.Owner == user)
            {
                gridAI.SetCellState(lastHit, CellState.Sunk);
            }
            else
            {
                gridUser.SetCellState(lastHit, CellState.Sunk);
            }
        }
Ejemplo n.º 20
0
 private void HandleMatchBegin(Event ev)
 {
     oldController.NewMatch();
 }
Ejemplo n.º 21
0
 public void RoundEnd(Event ev)
 {
     reset_Board();
 }
Ejemplo n.º 22
0
 private void HandleMatchEnd(Event ev)
 {
     oldController.MatchOver();
 }
Ejemplo n.º 23
0
 private void roundBeginEvent(Event ev)
 {
     this.newRound();
 }
Ejemplo n.º 24
0
 public NetIncomingEvent(NetCom communicator, Event incomingEvent)
     : base(communicator)
 {
     ReceivedEvent = incomingEvent;
 }
 public InvalidEventException(Event ev, string message)
     : base(message)
 {
     InvalidEvent = ev;
 }
Ejemplo n.º 26
0
 public void UpdateShot(Event ev)
 {
     var playerShot = (PlayerShotEvent)ev;
     if (playerShot.Player == user)
     {
         gridUser.SetCellState(playerShot.Shot.Coordinates, CellState.Miss);
         gridUser.Invalidate();
     }
     else
     {
         gridAI.SetCellState(playerShot.Shot.Coordinates, CellState.Miss);
         gridAI.Invalidate();
     }
 }
Ejemplo n.º 27
0
 private void playerTurnBeginEvent(Event ev)
 {
     PlayerTurnBeginEvent playerTurnBeginEvent = (PlayerTurnBeginEvent)ev;
     this.turnStart();
 }
Ejemplo n.º 28
0
 private void HandlePlayerRemove(Event ev)
 {
     Player plr = ((MatchRemovePlayerEvent)ev).Player;
     UnhookPlayerEvents(plr);
     oldController.Registers.Remove(((MatchRemovePlayerEvent)ev).Player.ID);
 }
Ejemplo n.º 29
0
        private void shipHitEvent(Event ev)
        {
            ShipHitEvent shipHitEvent = (ShipHitEvent)ev;
            Player owner = shipHitEvent.Ship.Owner; //who owns the hit ship

            // We only care about hits on enemy ships
            if (owner != Player) {
                // An opponent's ship has been hit
                this.hit(shipHitEvent.HitCoords, shipHitEvent.Ship.IsSunk());
            }
        }
Ejemplo n.º 30
0
        public void UpdateShotHit(Event ev)
        {
            var shipHit = (ShipHitEvent)ev;
            if (shipHit.Ship.Owner == user)
            {
                gridAI.SetCellState(shipHit.HitCoords, CellState.Hit);
                gridAI.Invalidate();
            }
            else
            {
                gridUser.SetCellState(shipHit.HitCoords, CellState.Hit);
                gridUser.Invalidate();
            }

            lastHit = shipHit.HitCoords;
        }