Ejemplo n.º 1
0
        public void TestStartGame()
        {
            // Arrange
            var conf       = new MockGameConfiguration();
            var queue      = new BufferBlock <Message>();
            var lifetime   = Mock.Of <IApplicationLifetime>();
            var client     = new TcpSocketClient <Message, Message>(logger);
            var gameMaster = new GM(lifetime, conf, queue, client, logger);
            var players    = gameMaster.GetValue <GM, Dictionary <int, GMPlayer> >("players");

            for (int idRed = 0; idRed < conf.NumberOfPlayersPerTeam; ++idRed)
            {
                var player = new GMPlayer(idRed, conf, client, Team.Red, logger);
                players.Add(idRed, player);

                int idBlue = idRed + conf.NumberOfPlayersPerTeam;
                player = new GMPlayer(idBlue, conf, client, Team.Blue, logger);
                players.Add(idBlue, player);
            }
            gameMaster.Invoke("InitGame");

            // Act
            var task = gameMaster.Invoke <GM, Task>("StartGame", CancellationToken.None);

            task.Wait();

            // Assert
            Assert.True(gameMaster.WasGameStarted);

            // TODO create mock of socket and check if GM sends messages
        }
Ejemplo n.º 2
0
        public bool MoveHere(GMPlayer player)
        {
            if (whosHere == null && player != null)
            {
                player.Position = this;
                whosHere        = player;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public override bool PickUp(GMPlayer player)
        {
            if (this.ContainsPieces())
            {
                var piece = Pieces.First();
                player.Holding = piece;
                Pieces.Remove(piece);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public void PickUpTaskTest(int numPut, int numPick, bool expected)
        {
            // Arrange
            var       conf         = Mock.Of <GameConfiguration>();
            var       socketClient = new TcpSocketClient <Message, Message>(logger);
            GMPlayer  gmPlayer     = new GMPlayer(1, conf, socketClient, Shared.Enums.Team.Red, logger);
            TaskField taskField    = new TaskField(2, 2);

            for (int i = 0; i < numPut; i++)
            {
                taskField.Put(new NormalPiece());
            }
            bool result = false;

            // Act
            for (int i = 0; i < numPick; i++)
            {
                result = taskField.PickUp(gmPlayer);
            }

            // Assert
            Assert.Equal(expected, result);
        }
Ejemplo n.º 5
0
 public override bool PickUp(GMPlayer player)
 {
     return(false);
 }
Ejemplo n.º 6
0
 public abstract bool PickUp(GMPlayer player);
Ejemplo n.º 7
0
 public void Leave(GMPlayer player)
 {
     whosHere = null;
 }