public GameViewModel() { if (IsInDesignMode) _game = new SticksGame(11, 1, new Player("Player"), new SticksAIPlayer("Bot", 0)); else { InitializeCommands(); RegisterToMessages(); _educatedAIPlayer = new SticksAIPlayer(BotNames.GetRandom(), 1000); } }
private void InitializeCommands() { NewGameCommand = new RelayCommand(() => { Messenger.Default.Send<Tokens, EducationViewModel>(Tokens.GameStarted); _game = new SticksGame(11, CollectionExtensions.GetRandomElement(0, 1), _humanPlayer, _educatedAIPlayer); _game.GameStateChanged += OnGameStateChanged; _game.GameEnded += OnGameEnded; _game.MoveRequested += OnMoveRequested; IsGameAlive = true; RaisePropertyChanged("HumanPlayerName"); RaisePropertyChanged("HumanPlayerWinsCount"); RaisePropertyChanged("EducatedAIPlayerName"); RaisePropertyChanged("EducatedAIPlayerWinsCount"); RaisePropertyChanged("IsFirstPlayerTurn"); RaisePropertyChanged("SticksCount"); (RemoveSticksCommand as RelayCommand<string>).RaiseCanExecuteChanged(); _game.Start(); }, () => { return _humanPlayer != null && _educatedAIPlayer != null; }); RemoveSticksCommand = new RelayCommand<string>((param) => { var sticksToRemoveCount = int.Parse(param); _game.CurrentPlayer.OnMoveMade(sticksToRemoveCount); }, (param) => { return _game != null ? _game.CurrentPlayer == _humanPlayer : false; }); }
private void RunEducationalGames() { var currentPlayerIndex = CollectionExtensions.GetRandomElement(0, 1); var game = new SticksGame(11, currentPlayerIndex, _firstAI, _secondAI); game.GameEnded += OnGameEnded; game.Start(); }