Beispiel #1
0
        private void NewGame(GameState state)
        {
            this.state   = state;
            this.board   = new Board(state.Cells);
            board.Margin = new Thickness(20);
            board.SetValue(Grid.RowProperty, 0);
            board.SetValue(Grid.ColumnProperty, 0);
            this.root.Children.Add(board);
            IPlayer player1 = new Player(Reversi.BLACK, this);
            IPlayer player2 = null;

            if (state.GameMode == GameMode.OnePlayer)
            {
                int difficulty = Math.Max(0, Math.Min(state.Difficulty, 2));
                player2 = new Strategy(Reversi.WHITE, difficulty);
                this.difficultyLabel.Visibility = Windows.UI.Xaml.Visibility.Visible;
                this.difficultyValue.Text       = Reversi.DifficultyToString(difficulty);
                this.difficultyValue.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                player2 = new Player(Reversi.WHITE, this);
            }
            if (state.TimeStamp == null)
            {
                state.TimeStamp = DateTime.Now;
            }
            t0 = state.TimeStamp.Value;
            timer.Start();
            var game = new Game(board, player1, player2);

            game.Update   += boardUpdatedHandler;
            game.GameOver += gameOverHandler;
            game.Begin(state.Player != Reversi.WHITE ? player1 : player2);
        }