Exemple #1
0
        public void PrintListWithScore_ShouldReturnCorrectScore()
        {
            //Arrange
            Mock <IDiceHolder> mockDiceHolder     = new Mock <IDiceHolder>();
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(mockDiceHolder.Object, mockGameHelper.Object, scoreParserFactory);

            Dictionary <string, int> scoreList = new Dictionary <string, int>();

            scoreList.Add("Ones", 4);
            scoreList.Add("Twos", 6);
            scoreList.Add("Threes", 3);
            scoreList.Add("Fours", 8);
            scoreList.Add("Fives", 15);
            scoreList.Add("Sixes", 6);
            scoreList.Add("ThreeOfAKind", 9);
            scoreList.Add("FourOfAKind", 12);
            scoreList.Add("FullHouse", 25);
            scoreList.Add("Straight", 20);
            scoreList.Add("Yatzy", 50);
            scoreList.Add("Chance", 10);
            mockGameHelper.Setup(x => x.GetScoreList()).Returns(scoreList);

            StringBuilder expectedListOutPut = new StringBuilder();

            foreach (KeyValuePair <string, int> score in scoreList)
            {
                expectedListOutPut.Append(score.Key + " " + score.Value + "\n");
            }

            //Act && Assert:

            Assert.AreEqual(expectedListOutPut.ToString(), gamePresenter.PrintListWithScore());
        }
Exemple #2
0
    private void Awake()
    {
        YouLose.gameObject.SetActive(false);
        InstanceCache.Flush();

        gameRepository   = InstanceCache.GetOrInstanciate <InMemoryGameRepository>(() => new InMemoryGameRepository());
        resultRepository = InstanceCache.GetOrInstanciate <InMemoryResultRepository>(() => new InMemoryResultRepository());
        scoreService     = InstanceCache.GetOrInstanciate <LocalScoreService>(() => new LocalScoreService());
        resultRepository.Clear();
        gameRepository.Clear();
        scoreService.Reset();

        gamePresenter = InstanceCache.GetOrInstanciate <GamePresenter>(
            () => {
            resultGenerator = new ResultGenerator(4, new AdditionOperator(), new RandomNumberGenerator(5, 15));
            return(new GamePresenter(
                       this,
                       new CreateGame(gameRepository,
                                      new FixedInitialNumber(),
                                      resultGenerator,
                                      resultRepository),
                       new Guess(gameRepository, resultRepository, resultGenerator, scoreService),
                       scoreService));
        });
    }
Exemple #3
0
        public void ChooseScoreParser_ShouldSetScoreParserOrThrowIfInvalidInput()
        {
            //Arrange
            GameHelper gamehelper = new GameHelper();
            DiceHolder diceHolder = new DiceHolder();
            Mock <ScoreParserFactory> mockScoreParserFactory = new Mock <ScoreParserFactory>();
            string funInput = "Fun";

            mockScoreParserFactory.Setup(x => x.GetScoreParser("FunScoreParser", diceHolder)).Returns(new FunScoreParser(diceHolder));



            GamePresenter gamePresenter = new GamePresenter(diceHolder, gamehelper, mockScoreParserFactory.Object);

            //Assert scoreparser is null before choosing
            Assert.IsNull(gamePresenter.ScoreParser);
            gamePresenter.ChooseScoreParser(funInput);


            //Assert scoreparser implements IScoreParser
            Assert.IsTrue(gamePresenter.ScoreParser is IScoreParser);
            gamePresenter = new GamePresenter(diceHolder, gamehelper, mockScoreParserFactory.Object);

            //Assert throw if invalid input
            Assert.Throws <InvalidOperationException>(() => gamePresenter.ChooseScoreParser("NotValid"));
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the Game Of Life.
 /// </summary>
 public GameOfLife()
 {
     worlds        = new List <World>();
     displayWorlds = new int[0];
     gamePresenter = new GamePresenter();
     gameSaver     = new GameSaver("game.json");
 }
Exemple #5
0
        public GameViewer GameContainer()
        {
            GameViewer game = resourcesManager.GamePrefabs.GameContainer(managerCanvas.CurrentСanvas.transform);

            GamePresenter presenter = new GamePresenter(game, _gameModel);

            return(game);
        }
 private void OnDestroy()
 {
     _presenter.Detach();
     _presenter = null;
     _model.Destroy();
     _model   = null;
     _network = null;
 }
        public void ItWritesNoArrowsWhenThereAreZeroArrows()
        {
            var console = Substitute.For<Display>();
            var presenter = new GamePresenter(console);

            presenter.DisplayArrowStatus(0);

            console.Received().WriteMessage("You have no arrows.");
        }
        public void ItWritesTheMessageForOneArrow()
        {
            var console = Substitute.For<Display>();
            var presenter = new GamePresenter(console);

            presenter.DisplayArrowStatus(1);

            console.Received().WriteMessage("You have 1 arrow.");
        }
 public GameDriver()
 {
     Display = new MockDisplay();
     Presenter = new GamePresenter(Display);
     Map = new Map();
     WumpusGame = new Game(Presenter, Map);
     Editor = new MapEditor(Map);
     Presenter.Game = WumpusGame;
 }
Exemple #10
0
        public GameForm(GamePresenter presenter, String User, int numBot, String difficulty)
        {
            InitializeComponent();

            _gamePresenter    = presenter;
            _mouseClickPlayer = new System.Media.SoundPlayer(Properties.Resources.dicesRollSound);

            _rollButton.Click          += new EventHandler(_gamePresenter.OnRollButtonClick);
            _rollButton.MouseDown      += new MouseEventHandler(RollButtonDown);
            _rollButton.MouseUp        += new MouseEventHandler(RollButtonUp);
            _rollButton.EnabledChanged += new EventHandler(RollButtonEnabledChanged);

            _ffButton.MouseEnter += new EventHandler(OnMouseOverFFButton);
            _ffButton.MouseLeave += new EventHandler(OnMouseLeaveFFButton);
            _ffButton.MouseDown  += new MouseEventHandler(FFButtonDown);
            _ffButton.MouseUp    += new MouseEventHandler(FFButtonUp);
            _ffButton.Click      += new EventHandler(FFButtonClick);

            MouseEventHandler checkChanges = new MouseEventHandler(_gamePresenter.OnDiceClick);

            _dice1.MouseClick += checkChanges;
            _dice2.MouseClick += checkChanges;
            _dice3.MouseClick += checkChanges;
            _dice4.MouseClick += checkChanges;
            _dice5.MouseClick += checkChanges;

            // List of dices pictureboxes
            _dices    = new PictureBox[5];
            _dices[0] = _dice1;
            _dices[1] = _dice2;
            _dices[2] = _dice3;
            _dices[3] = _dice4;
            _dices[4] = _dice5;

            _locks    = new PictureBox[5];
            _locks[0] = _lock1;
            _locks[1] = _lock2;
            _locks[2] = _lock3;
            _locks[3] = _lock4;
            _locks[4] = _lock5;

            // ToolTip
            // Create the ToolTip and associate with the Form container.
            ToolTip toolTip1 = new ToolTip();

            // Set up the delays for the ToolTip.
            toolTip1.AutoPopDelay = 5000;
            toolTip1.InitialDelay = 750;
            toolTip1.ReshowDelay  = 500;
            toolTip1.ShowAlways   = true;
            toolTip1.SetToolTip(_rollsLeft, "Rolls left");

            _previewFont = new Font("Ebrima", 9, FontStyle.Bold);
            _usedFont    = new Font("Ebrima", 12, FontStyle.Bold);

            _rollsLeft.Image = Properties.Resources._3_throws_left;
        }
Exemple #11
0
        public MainWindow()
        {
            InitializeComponent();

            CreateWindowControls();
            groupBox1.Visibility = Visibility.Hidden;

            gamePresenter = new GamePresenter(this);
        }
    private void Awake()
    {
        DataLibrary.Insert(AssetLibrary.GetTextByPath("Configs/Resources.json").text);

        _network   = new GameNetworkMock();
        _model     = new GameModel(_network);
        _presenter = new GamePresenter(_model);
        _presenter.Attach(_view);
    }
		public MainWindow()
		{
			InitializeComponent();

			CreateWindowControls();
			groupBox1.Visibility = Visibility.Hidden;

			gamePresenter = new GamePresenter(this);
		}
        public void ItCommandsShootingAnArrowInTheRightDirection()
        {
            var console = Substitute.For<Display>();
            var game = Substitute.For<GameController>();
            var presenter = new GamePresenter(console) {Game = game};

            presenter.CommandPlayer("shoot e");

            game.Received().Command(Arg.Is<Command>(com => com.Direction == Command.Directions.East));
        }
        public void IsNumericParameters_Returns_False_When_Velocity_Is_Not_Numeric()
        {
            //arrange
            IGamePresenter gamePresenter = new GamePresenter(null);

            //act
            bool isNumericParameters = gamePresenter.IsNumericParameters(0.ToString(), "aaa");

            //assert
            Assert.IsFalse(isNumericParameters);
        }
        public void IsNumericParameters_Returns_True_When_Velocity_And_Position_Are_Numeric()
        {
            //arrange
            IGamePresenter gamePresenter = new GamePresenter(null);

            //act
            bool isNumericParameters = gamePresenter.IsNumericParameters(0.ToString(), 0.ToString());

            //assert
            Assert.IsTrue(isNumericParameters);
        }
        public void IsNumericParameters_Returns_False_When_Velocity_And_Position_Are_Not_Numeric()
        {
            //arrange
            IGamePresenter gamePresenter = new GamePresenter(null);

            //act
            bool isNumericParameters = gamePresenter.IsNumericParameters("aaa", "aaa");

            //assert
            Assert.IsFalse(isNumericParameters);
        }
Exemple #18
0
        public void StartGame()
        {
            _gameHelper         = new GameHelper();
            _scoreParserFactory = new ScoreParserFactory();
            Die die1 = new Die();
            Die die2 = new Die();
            Die die3 = new Die();
            Die die4 = new Die();
            Die die5 = new Die();

            List <IDie> diceList = new List <IDie>
            {
                die1,
                die2,
                die3,
                die4,
                die5
            };

            _diceHolder = new DiceHolder(diceList);
            _presenter  = new GamePresenter(_diceHolder, _gameHelper, _scoreParserFactory);

            Console.WriteLine("Lets play some Yatzy! What rules do you want to play? write 'Fun' for the fun rules, and 'Boring' for the boring ones!");
            string scoreParserToUse = Console.ReadLine();

            _presenter.ChooseScoreParser(scoreParserToUse);

            int [] initialDiceToSave = new int[0];
            while (!_gameHelper.IsGameFinished)
            {
                _presenter.Roll(initialDiceToSave);

                //Simulates one Round with two rethrows
                for (int i = 0; i < 2; i++)
                {
                    Console.WriteLine("Rethrow " + (i + 1) + " Save the die by typing the die-numbers separated by a comma. E.g '4,1' saves the first and fourth die.\n" + _presenter.PrintDice());
                    string rerollDiceToSave = Console.ReadLine();
                    int[]  diceToSave       = _presenter.ParseDieSelection(rerollDiceToSave);

                    _presenter.Roll(diceToSave);
                }

                Console.WriteLine("Time to save the score: see the current list here, and type in what to save.");
                Console.WriteLine(_presenter.PrintDice());
                Console.WriteLine(_presenter.PrintListWithScore());

                string scoreToSave = Console.ReadLine();
                _presenter.SaveScore(scoreToSave);
                Console.WriteLine("Score saved: ");
                Console.WriteLine(_presenter.PrintListWithScore());
            }
            Console.WriteLine("Well done! Final score is: " + _gameHelper.Score);
        }
        public void Randomize_Set_View_With_Random_Valid_Initial_Parameters()
        {
            //arrange
            IGameView      gameView      = new GameView();
            IGamePresenter gamePresenter = new GamePresenter(gameView);

            //act
            gamePresenter.Randomize();

            //assert
            Assert.IsTrue(gamePresenter.IsNumericParameters(gameView.Position, gameView.Velocity));
        }
Exemple #20
0
        public void PrintDice_ShouldReturnDiceWithTheirScore(int inputDiceOne, int inputDiceTwo, int inputDiceThree, int inputDiceFour, int inputDiceFive)
        {
            //Arrange
            string             expected           = "Dice1: [" + inputDiceOne + "] Dice2: [" + inputDiceTwo + "] Dice3: [" + inputDiceThree + "] Dice4: [" + inputDiceFour + "] Dice5: [" + inputDiceFive + "]";
            Mock <IDiceHolder> mockDiceHolder     = GetMockDiceHolder(inputDiceOne, inputDiceTwo, inputDiceThree, inputDiceFour, inputDiceFive);
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(mockDiceHolder.Object, mockGameHelper.Object, scoreParserFactory);

            //Act & Assert
            Assert.AreEqual(expected, gamePresenter.PrintDice());
        }
Exemple #21
0
        public GameView(GameModel model)
        {
            _gameModel     = model;
            _gamePresenter = new GamePresenter(this, model);

            CorrectGuesses = new List <CorrectGuess>();

            SubscribeToEvents();

            Console.WriteLine("Welcome to the Animal guessing game. I'll ask questions, you answer with 'y' or 'n', and I'll try guess your animal.");

            _gamePresenter.AskQuestion();
        }
Exemple #22
0
        public void Initialize()
        {
            GDebug.Log("Application start", this, LogCategory.GAME_MANAGER);

            _gamePresenter = _gamePresenterFactory.Create();
            _gamePresenter.transform.position   = Vector3.zero;
            _gamePresenter.transform.localScale = Vector3.one;

            _disposables = new CompositeDisposable();

            Subscriptions();

            _onGamestartSignal.Fire();
        }
Exemple #23
0
        public void ParseDieSelection_ShouldCorrectlyUseDelimiterOrThrow()
        {
            //Arrange
            Mock <IDiceHolder> mockDiceHolder     = new Mock <IDiceHolder>();
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(mockDiceHolder.Object, mockGameHelper.Object, scoreParserFactory);
            string             input = "5,4,3";

            int[] expected = new int[] { 5, 4, 3 };

            //Act & Assert
            Assert.AreEqual(expected, gamePresenter.ParseDieSelection(input));
        }
Exemple #24
0
 public static void NewGame(GameMap map)
 {
     try
     {
         GameEngine.Game.StartNewGame(map);
         gamePresenter = new GamePresenter(startTime: new DateTime(1939, 5, 1), side: 0);
         gamePresenter.UpdateMap(map);
         RaiseGameReloaded();
     }
     catch (Exception e)
     {
         throw e; // todo remove this
     }
 }
 // Display End Game Messages
 public void DisplayEndGameMessage(GamePresenter.EndGameMessage message)
 {
     switch (message)
     {
         case GamePresenter.EndGameMessage.Winner:
             this.VictorMessage.SetActive(true);
             break;
         case GamePresenter.EndGameMessage.Defeated:
             this.DefeatMessage.SetActive(true);
             break;
         case GamePresenter.EndGameMessage.Draw:
             this.DrawMessage.SetActive(true);
             break;
     }
 }
Exemple #26
0
        public void SaveScore_ShouldSaveScoreInGameHelper(string chosenScoring, int inputDiceOne, int inputDiceTwo, int inputDiceThree, int inputDiceFour, int inputDiceFive, int expectedScore)
        {
            //Arrange
            Mock <IDiceHolder> mockDiceHolder     = GetMockDiceHolder(inputDiceOne, inputDiceTwo, inputDiceThree, inputDiceFour, inputDiceFive);
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(mockDiceHolder.Object, mockGameHelper.Object, scoreParserFactory);

            gamePresenter.ChooseScoreParser("Fun");

            //Act
            gamePresenter.SaveScore(chosenScoring);

            //Assert
            mockGameHelper.Verify(x => x.SaveScore(chosenScoring, expectedScore), Times.Once);
        }
Exemple #27
0
    private void Awake()
    {
        _configLoader = new ConfigLoader();
        _dataStorage  = new DataStorage.DataStorage(_configLoader);
        _dataStorage.Load(configPath);

        _cameraController.Init(_dataStorage.Data.cameraSettings);

        _game = new Game.GameModel(_dataStorage.Data);
        _game.Init(_dataStorage.Data.settings.playersCount);

        _gamePresenter = new GamePresenter(_game, _gameView);

        _presenters = new PlayerPresenter[_players.Length];
        for (var i = 0; i < _players.Length; i++)
        {
            _presenters[i] = new PlayerPresenter(_game, _game.GetPlayer(i), _players[i]);
        }
    }
Exemple #28
0
 public static void NewGame(string path)
 {
     try
     {
         GameEngine.Game.StartNewGame("..\\..\\Maps\\" + path);                                                        // загрузка карты из файла
         gamePresenter = new GamePresenter(startTime: new DateTime(1939, 5, 1), side: 0, bg: Game.MainMap.Background); // ???
         gamePresenter.UpdateMap(Game.MainMap);
         // НАПИСАЛ МИША, НАДО БЫЛО
         foreach (Unit unit in Game.MainMap.Units)
         {
             unit.UnitCommander = new AutomaticCommander("Vasya", CommanderType.Common, unit);
         }
         RaiseGameReloaded();
     }
     catch (Exception e)
     {
         throw e; // todo remove this
     }
 }
Exemple #29
0
        public void NewGame_ShouldResetAndNotHaveScoreParser()
        {
            //Arrange
            GameHelper         gamehelper         = new GameHelper();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            DiceHolder         diceHolder         = new DiceHolder();


            //Act
            GamePresenter gamePresenter = new GamePresenter(diceHolder, gamehelper, scoreParserFactory);

            Assert.AreEqual(gamehelper, gamePresenter.GameHelper);


            //Assert
            gamePresenter.NewGame();
            Assert.AreNotEqual(gamehelper, gamePresenter.GameHelper);
            Assert.IsNull(gamePresenter.ScoreParser);
        }
Exemple #30
0
 static void Main(string[] args)
 {
     try
     {
         int port  = int.Parse(args[0]);
         int count = int.Parse(args[1]);
         Console.WriteLine(args[0] + " " + args[1]);
         ServerPresenter.getInstance().Init(port, count);
         GamePresenter.getInstance().Init(count);
         while (!isEnd)
         {
             Thread.Sleep(100);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #31
0
        public void Roll_ShouldLockAndRollUnlockedDice()
        {
            //Arrange
            int[] diceToRoll = new int[2];
            diceToRoll[0] = 1;
            diceToRoll[1] = 4;

            Mock <IDie> mockDie1 = new Mock <IDie>();
            Mock <IDie> mockDie2 = new Mock <IDie>();
            Mock <IDie> mockDie3 = new Mock <IDie>();
            Mock <IDie> mockDie4 = new Mock <IDie>();
            Mock <IDie> mockDie5 = new Mock <IDie>();

            List <IDie> diceList = new List <IDie>
            {
                mockDie1.Object,
                mockDie2.Object,
                mockDie3.Object,
                mockDie4.Object,
                mockDie5.Object,
            };

            mockDie1.Setup(x => x.IsLocked).Returns(true);
            mockDie4.Setup(x => x.IsLocked).Returns(true);


            IDiceHolder        diceholder         = new DiceHolder(diceList);
            Mock <GameHelper>  mockGameHelper     = new Mock <GameHelper>();
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            GamePresenter      gamePresenter      = new GamePresenter(diceholder, mockGameHelper.Object, scoreParserFactory);


            //Act
            gamePresenter.Roll(diceToRoll);

            //assert
            mockDie1.Verify(x => x.Roll(), Times.Never());
            mockDie2.Verify(x => x.Roll(), Times.Once());
            mockDie3.Verify(x => x.Roll(), Times.Once());
            mockDie4.Verify(x => x.Roll(), Times.Never());
            mockDie5.Verify(x => x.Roll(), Times.Once());
        }
        public void Randomize_Set_View_With_Random_Initial_Parameters()
        {
            //arrange
            IGameView      gameView      = new GameView();
            IGamePresenter gamePresenter = new GamePresenter(gameView);

            gameView.Position = string.Empty;
            gameView.Velocity = string.Empty;

            string initialVelocity = gameView.Velocity;
            string initialPosition = gameView.Position;

            //act
            gamePresenter.Randomize();

            //assert
            Assert.AreEqual(string.Empty, initialVelocity);
            Assert.AreEqual(string.Empty, initialPosition);
            Assert.AreNotEqual(initialPosition, gameView.Position);
            Assert.AreNotEqual(initialVelocity, gameView.Velocity);
        }
        public void CallGetAllGamesSortedById_WhenOnGetDataEventIsRaised()
        {
            //Arrange
            var viewMock = new Mock <IGameView>();

            viewMock.Setup(v => v.Model).Returns(new GameViewModel());

            var games           = GetGames();
            var gameServiceMock = new Mock <IGameService>();

            gameServiceMock.Setup(c => c.GetAllGamesSortedById())
            .Returns(games);

            GamePresenter gamePresenter = new GamePresenter(viewMock.Object, gameServiceMock.Object);

            // Act
            viewMock.Raise(v => v.OnGetData += null, EventArgs.Empty);

            // Assert
            CollectionAssert.AreEquivalent(games, viewMock.Object.Model.Games); // TODO CHECK ORDER
        }
Exemple #34
0
 private void Awake()
 {
     collisionInstantiator = GameProvider.ProvideCollisionInstantiator();
     presenter             = GamePresenterProvider.Provide(this);
     mapEnemyViewModel     = GameProvider.ProvideMapEnemyViewModel();
 }
Exemple #35
0
 public static IGameView getInstance(GamePresenter presenter, String User, int numbot, String diff)
 {
     return(new GameForm(presenter, User, numbot, diff));
 }
 private void Start()
 {
     gamePresenter = InstanceCache.Get <GamePresenter>();
 }
 void Awake()
 {
     // Set singleton refere
     GamePresenter._instance = this;
 }