Exemplo n.º 1
0
        public BearViewModel(BearGameModel m)
        {
            Width       = 600;
            Height      = 600;
            GameTime    = 0;
            BasketCount = 0;
            _model      = m;
            BearFields  = new ObservableCollection <BearField>();

            _sizeChangeCommand   = new DelegateCommand(p => _model.GameSize = (GameSize)Convert.ToInt32(p));
            _newGameCommand      = new DelegateCommand(p => { _model.NewGame(); SetupBoard(); });
            _exitCommand         = new DelegateCommand(param => OnExitGame());
            _pauseCommand        = new DelegateCommand(param => OnPauseGame());
            _model.GameAdvanced += _model_GameAdvanced;
            _model.GameOver     += _model_GameOver;

            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(1000);
            _timer.Tick    += _timer_Tick;

            _model.NewGame();
            SetupBoard();

            _timer.Start();
        }
Exemplo n.º 2
0
        public void NewGameMediumTest()
        {
            _model.NewGame();

            Assert.AreEqual(0, _model.BasketCount);
            Assert.AreEqual(GameSize.Medium, _model.GameSize);

            int emptyFields = 0;
            int trees       = 0;
            int guards      = 0;
            int baskets     = 0;

            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    if (_model.Board[i, j] == 0)
                    {
                        emptyFields++;
                    }
                    else if (_model.Board[i, j] == 1)
                    {
                        trees++;
                    }
                    else if (_model.Board[i, j] == 2)
                    {
                        guards++;
                    }
                    else if (_model.Board[i, j] == 3)
                    {
                        baskets++;
                    }
                }
            }

            Assert.AreEqual(203, emptyFields);
            Assert.AreEqual(13, trees);
            Assert.AreEqual(3, guards);
            Assert.AreEqual(5, baskets);
        }