Exemplo n.º 1
0
 /// <summary>
 /// initialize the board and the timers
 /// </summary>
 private void Initialize()
 {
     //init 2d array
     board         = new int[boardSize, boardSize];
     possibleMoves = new ArrayList();
     //fill the array with starting pos
     for (int y = 0; y < boardSize; y++)
     {
         for (int x = 0; x < boardSize; x++)
         {
             if ((y == 3 || y == 4) && (x == 3 || x == 4))
             {
                 board[x, y] = x == y ? 0 : 1;
             }
             else
             {
                 board[x, y] = -1;
             }
         }
     }
     timerBlack.Reset();
     timerWhite.Reset();
     currentPlayer = 1;
     timerBlack.Start();
 }
Exemplo n.º 2
0
        /// <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");
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// change the player who's playing right now
 /// </summary>
 public void changePlayer()
 {
     currentPlayer = currentPlayer == 1 ? 0 : 1;
     if (currentPlayer == 1)
     {
         timerWhite.Stop();
         timerBlack.Start();
     }
     else if (currentPlayer == 0)
     {
         timerBlack.Stop();
         timerWhite.Start();
     }
 }