/// <summary> /// load a game from a given file /// </summary> /// <param name="filename"></param> public void LoadBoard(String filename) { if (File.Exists(filename)) { Stream TestFileStream = File.OpenRead(filename); BinaryFormatter deserializer = new BinaryFormatter(); State s = (Othello.State)deserializer.Deserialize(TestFileStream); TestFileStream.Close(); if (s != null) { this.board = s.Board; this.currentPlayer = s.CurrentPlayer; this.timerBlack = new SettableStopWatch(s.BlackTimeSpanOffset); this.timerWhite = new SettableStopWatch(s.WhiteTimeSpanOffset); if (currentPlayer == 1) { timerBlack.Start(); } else if (currentPlayer == 0) { timerWhite.Start(); } OnPropertyChanged("blackScore"); OnPropertyChanged("whiteScore"); } } }
/// <summary> /// a constructor which instanciate the timers and initialize the board /// </summary> public Game() { globTimer = new DispatcherTimer(); timerWhite = new SettableStopWatch(new TimeSpan(0, 0, 0)); timerBlack = new SettableStopWatch(new TimeSpan(0, 0, 0)); globTimer.Interval = TimeSpan.FromSeconds(1); globTimer.Tick += GlobTimerTick; globTimer.Start(); Initialize(); }