Inheritance: System.Entity
 /// <summary>
 /// Populates the shotRemain list with all possible shots against a Player opponent
 /// </summary>
 /// <param name="opponent"></param>
 private void QueueShotsPlayer(Player opponent)
 {
     for (int x = 0; x < Player.Match.FieldSize.X; x++)
     {
         for (int y = 0; y < Player.Match.FieldSize.Y; y++)
         {
             shotsRemain.Add(new Shot(opponent, new Coordinates(x, y)));
         }
     }
 }
Exemple #2
0
        public void NewMatch()
        {
            this.player = this.controller.Player;
            this.match = this.player.Match;
            ShotHelper.MatchX = match.FieldSize.X - 1;
            ShotHelper.MatchY = match.FieldSize.Y - 1;

            this.shipLengths = this.match.StartingShips.Select(ship => ship.Length).ToArray();

            cellStateMap = new CellStateMap(match.FieldSize.X);

            historyMap = new HistoryMap(match.FieldSize.X, this.shipLengths, cellStateMap);
            placementMap = new PlacementMap(match.FieldSize.X, this.shipLengths, cellStateMap);
            huntingMap = new HuntingMap(match.FieldSize.X, this.shipLengths, cellStateMap);
        }
 private void HookPlayerEvents(Player plr)
 {
     plr.OnEvent += HandlePlayerShot;
     plr.OnEvent += HandlePlayerLose;
     if (plr == myPlayer)
     {
         plr.OnEvent += HandleTurnBegin;
         plr.OnEvent += HandlePlayerWin;
     }
 }
Exemple #4
0
 public virtual void PlayerRemove(Player plr)
 {
     InvokeEvent(new TeamRemovePlayerEvent(this, plr));
 }
Exemple #5
0
 public virtual void PlayerAdd(Player plr)
 {
     InvokeEvent(new TeamAddPlayerEvent(this, plr));
 }
        private void HandleAddPlayer(Event ev)
        {
            MatchAddPlayerEvent evCasted = (MatchAddPlayerEvent)ev;
            Player plr = evCasted.Player;
            if (plr != User)
                computer = plr;

            plr.OnEvent += HandleShot;
            foreach (Ship ship in plr.Ships)
            {
                ship.OnEvent += HandleShipMove;
                ship.OnEvent += HandleShipDestroyed;
            }
        }
Exemple #7
0
 /// <summary>
 /// Shoots against a player opponent at the specified X and Y coordinates.
 /// </summary>
 /// <param name="opponent"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public virtual void Shoot(Player opponent, int x, int y)
 {
     Shoot(new Shot(opponent, new Coordinates(x, y)));
 }
Exemple #8
0
 /// <summary>
 /// Creates a MatchRemovePlayerEvent from within the match and returns it. Invokes any event
 /// subscriptions to OnPlayerRemove.
 /// </summary>
 /// <param name="player"></param>
 /// <returns>The generated event</returns>
 /// <exception cref="InvalidEventException">Thrown when the event being created is not valid for the
 /// current state of the match.</exception>
 protected internal virtual void PlayerRemove(Player player)
 {
     InvokeEvent(new MatchRemovePlayerEvent(this, player));
 }
 /// <summary>
 /// Constructs the event with the player that lost.
 /// </summary>
 /// <param name="loser"></param>
 public PlayerDisqualifiedEvent(Player loser, string reason)
     : base(loser)
 {
     Reason = reason;
 }
 /// <summary>
 /// Constructs the event with the player that won.
 /// </summary>
 /// <param name="player"></param>
 public PlayerWonEvent(Player player)
     : base(player)
 {
 }
        /// <summary>
        /// This creates a new match.
        /// </summary>
        public void NewMatch()
        {
            match = new UserMatch(configuration);
            user = new Player(match, NAME);
            match.AddUser(user);

            var bots = ControllerSkeleton.LoadControllerFolder(Environment.CurrentDirectory + "\\..\\bots");
            foreach (ControllerSkeleton bot in bots)
                if (bot.Controller.Name == BOTNAME)
                {
                    computer = match.PlayerCreate(bot);
                    break;
                }

            match.OnEvent += UpdateShot;
            match.OnEvent += UpdateShotHit;
            match.OnEvent += UpdateWinner;
            match.OnEvent += RoundEnd;
            match.OnEvent += UpdateShipDestroyed;

            match.Play();
        }
 /// <summary>
 /// Constructs this event with the given player.
 /// </summary>
 /// <param name="player"></param>
 public PlayerEvent(Player player)
     : base(player)
 {
     Player = player;
 }
 /// <summary>
 /// Constructs this event with the given player.
 /// </summary>
 /// <param name="player"></param>
 public MatchAddPlayerEvent(Match match, Player player)
     : base(match)
 {
     Player = player;
 }
 /// <summary>
 /// Constructs the event with the player that lost.
 /// </summary>
 /// <param name="loser"></param>
 public PlayerLostEvent(Player loser)
     : base(loser)
 {
 }
Exemple #15
0
 /// <summary>
 /// To set the User as a player of the match.
 /// </summary>
 /// <param name="user">User controller</param>
 public void AddUser(Player user)
 {
     User = user;
     PlayerAdd(user);
 }
 private void UnhookPlayerEvents(Player plr)
 {
     plr.OnEvent -= HandlePlayerLose;
     plr.OnEvent -= HandlePlayerShot;
     plr.OnEvent -= HandlePlayerWin;
     plr.OnEvent -= HandleTurnBegin;
 }
Exemple #17
0
 /// <summary>
 /// Creates a MatchAddPlayerEvent from within the match and returns it. Invokes any event
 /// subscriptions to OnPlayerAdd.
 /// </summary>
 /// <param name="player"></param>
 /// <returns>The generated event</returns>
 /// <exception cref="InvalidEventException">Thrown when the event being created is not valid for the
 /// current state of the match.</exception>
 protected internal virtual void PlayerAdd(Player player)
 {
     InvokeEvent(new MatchAddPlayerEvent(this, player));
 }
 public TeamAddPlayerEvent(Team team, Player plr)
     : base(team)
 {
     Player = plr;
 }
 /// <summary>
 /// Constructs this event with the player and message it created.
 /// </summary>
 /// <param name="player"></param>
 /// <param name="message"></param>
 public PlayerMessageEvent(Player player, string message)
     : base(player)
 {
     Message = message;
 }
 public PlayerTurnBeginEvent(Player player)
     : base(player)
 {
 }
 public TeamRemovePlayerEvent(Team team, Player plr)
     : base(team)
 {
 }
 /// <summary>
 /// Constructs the event with the player who made the shot. No ship hit.
 /// </summary>
 /// <param name="player"></param>
 /// <param name="shot"></param>
 public PlayerShotEvent(Player player, Shot shot)
     : base(player)
 {
     Shot = shot;
 }
 /// <summary>
 /// Constructs the event with the player that switched their turn.
 /// </summary>
 public PlayerTurnEndEvent(Player player)
     : base(player)
 {
 }
 /// <summary>
 /// Constructs this event with the player being removed.
 /// </summary>
 /// <param name="player"></param>
 public MatchRemovePlayerEvent(Match match, Player player)
     : base(match)
 {
     Player = player;
 }