示例#1
0
 /// <summary>
 /// Fires the move received event.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The <see cref="MoveReceivedEventArgs"/> instance containing the event data.</param>
 protected virtual void FireMoveReceived(object sender, MoveReceivedEventArgs args)
 {
     if (this.MoveReceived != null)
     {
         this.MoveReceived(sender, args);
     }
 }
示例#2
0
        /// <summary>
        /// Evaluates a received move and and sends the information if if it hit something.
        /// Sends a new MoveRequest to the other competitor.
        /// </summary>
        /// <param name="sender">The sender of the MoveReceived event.</param>
        /// <param name="args">The event arguments.</param>
        private void Competitor_MoveReceived(object sender, MoveReceivedEventArgs args)
        {
            Competitor competitor = (Competitor)sender;
            Competitor opponent   = this.Opponent(competitor);

            // Stop listening for incoming moves until the next request to this competitor is sent.
            competitor.MoveReceived -= this.Competitor_MoveReceived;

            Marker marker;
            bool   validMove;

            validMove = opponent.BattleField.AddMarker(args.Move, out marker);

            if (!validMove)
            {
                // Someone cheated.
                opponent.SendGameWon();
                competitor.Connection.Close();
                this.FireFinished(this, new FinishedArgs(this, opponent, competitor));
                return;
            }

            competitor.SendMoveReport(marker);
            opponent.SendOpponentsMove(marker);

            if (opponent.BattleField.Ships.Count == 0)
            {
                // Game finished.
                competitor.SendGameWon();
                opponent.SendGameLost();
                this.FireFinished(this, new FinishedArgs(this, competitor, opponent));
            }
            else
            {
                opponent.SendMoveRequest();
                opponent.MoveReceived += this.Competitor_MoveReceived;
            }
        }
示例#3
0
 /// <summary>
 /// Fires the <see cref="MoveReportReceived"/> event.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="args">The event arguments.</param>
 protected virtual void FireMoverReportReceived(object sender, MoveReceivedEventArgs args)
 {
     this.MoveReportReceived?.Invoke(sender, args);
 }
示例#4
0
 /// <summary>
 /// Firs the <see cref="OpponentMoveReceived"/> event.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="args">The event arguments.</param>
 protected virtual void FireOpponentMoveReceived(object sender, MoveReceivedEventArgs args)
 {
     this.OpponentMoveReceived?.Invoke(sender, args);
 }