Exemplo n.º 1
0
        private void InitializePlayers(int dimension, PlayerInfoViewModel player1, PlayerInfoViewModel player2)
        {
            if (!string.IsNullOrEmpty(player1.Name.Value.Trim()))
            {
                ReversiGame.Value.CurrentPlayer.Name = player1.Name.Value;
            }
            else
            {
                ReversiGame.Value.CurrentPlayer.Name = "Player 1";
            }
            if (!string.IsNullOrEmpty(player2.Name.Value.Trim()))
            {
                ReversiGame.Value.CurrentPlayer.OtherPlayer.Name = player2.Name.Value;
            }
            else
            {
                ReversiGame.Value.CurrentPlayer.OtherPlayer.Name = "Player 2";
            }

            ReversiGame.Value.CurrentPlayer.Color             = player1.Color.Value;
            ReversiGame.Value.CurrentPlayer.OtherPlayer.Color = player2.Color.Value;

            Player1 = new PlayerViewModel(this, ReversiGame.Value.CurrentPlayer, dimension);
            Player2 = new PlayerViewModel(this, ReversiGame.Value.CurrentPlayer.OtherPlayer, dimension);
        }
Exemplo n.º 2
0
 public StartViewModel()
 {
     Player1         = new PlayerInfoViewModel("Player 1", "Black");
     Player2         = new PlayerInfoViewModel("Player 2", "White");
     Dimension       = Cell.Create(8);
     DimensionString = Cell.Derive(Dimension, dim => dim.ToString() + " x " + dim.ToString());
 }
Exemplo n.º 3
0
        public BoardViewModel(int dimension, PlayerInfoViewModel player1, PlayerInfoViewModel player2)
        {
            ReversiGame = Cell.Create(new ReversiGame(dimension, dimension));
            InitializePlayers(dimension, player1, player2);

            IsGameOver      = Cell.Derive(ReversiGame, g => g.IsGameOver);
            Winner          = Cell.Derive(ReversiGame, g => GetWinner(g));
            GameOverMessage = Cell.Derive(ReversiGame, g => CreateGameOverMessage(g));

            Rows = Enumerable.Range(0, ReversiGame.Value.Board.Height).Select(i => new BoardRowViewModel(ReversiGame, i)).ToList().AsReadOnly();
        }