コード例 #1
0
        /// <summary>
        /// Check if this is a winning set
        /// </summary>
        /// <returns>True if winner</returns>
        private bool checkWinnerRow(int a, int b, int c)
        {
            if (_model.Turn == _model.GetBoardPosition(a)
             && _model.Turn == _model.GetBoardPosition(b)
             && _model.Turn == _model.GetBoardPosition(c))
            {
                //Stop game, disables timer and board
                _model.Status = GameModel.GameStatus.Ended;

                //Notify winner
                _model.WinningPositions = new int[] { a, b, c };

                //Save results on another thread
                new Thread(() =>
                {
                    var record = new GameRecord()
                    {
                        Timestamp = DateTime.Now,
                        Winner = _model.Turn == GameModel.X ? "x" : "o",
                        Duration = _model.Duration
                    };
                    var dbHelper = new GameRecordsDatabaseHelper();
                    dbHelper.Open();
                    dbHelper.Save(record);
                    dbHelper.Close();
                }).Start();

                return true;
            }
            else return false;
        }
コード例 #2
0
 public void Save(GameRecord record)
 {
     records.Add(record);
 }