Example #1
0
 /// <summary>
 /// Tries to mark a specified point with specified mark and checks winning conditions.
 /// </summary>
 /// <param name="markPoint">Point to mark.</param>
 /// <param name="mark">Mark to put.</param>
 /// <returns>Returns true if point has been successfully marked, false otherwise.</returns>
 protected bool MarkPointIfPossible(Point markPoint, Mark mark)
 {
     SyncConext.Send((o) =>
     {
         if (mark == State.Current)
         {
             if (State.TicTacToeMap.MarkPoint(markPoint, mark))
             {
                 WinConditionMetEventArgs arg;
                 if ((arg = GetWinConditionMetEventArgs(markPoint, mark)) != null)
                 {
                     timing?.Stop();
                     WinConditionMet?.Invoke(this, arg);
                 }
                 else
                 {
                     State.ChangeCurrentMark();
                     timing?.Restart();
                     State.GetPlayerFromMark(State.Current).MakeMove();
                 }
             }
         }
     }, this);
     try
     {
         return(State.TicTacToeMap.GetMarkOnPoint(markPoint) == mark);
     }
     catch
     {
         return(false);
     }
 }
Example #2
0
 /// <summary>
 /// Handles <see cref="ITiming.TimePassed"/> event.
 /// </summary>
 /// <param name="sender">Event source.</param>
 /// <param name="e">An EventArgs containing event data.</param>
 private void Timing_TimePassed(object sender, EventArgs e)
 {
     SyncConext.Post((o) =>
     {
         State.ChangeCurrentMark();
         State.GetPlayerFromMark(State.Current).MakeMove();
     }, this);
 }