Пример #1
0
    public void Game_DestroyHexagons()
    {
        Game   game    = new Game();
        Client client1 = TestObjects.BuildClient();
        Client client2 = TestObjects.BuildClient();

        game.Players.Add(client1);
        game.Players.Add(client2);
        Schema.BoardState originalBoardState = game.Board.GetBoardState();
        game.Board.DestroyHexagon(0);
        Assert.IsTrue(game.Board.Hexagons[0].IsDestroyed);
        Assert.ThrowsException <System.ArgumentException>(() => { game.Board.DestroyHexagon(420); });
        game.Update(DateTime.Now);

        foreach (Client client in game.Players)
        {
            Assert.IsTrue(client.MessageLog.Last.Value.Is(Schema.BoardState.Descriptor));
            Schema.BoardState boardState = client.MessageLog.Last.Value.Unpack <Schema.BoardState>();
            Assert.AreEqual(1, boardState.HexagonSets[0].Hexagons.Count);
            Assert.AreEqual(2, boardState.HexagonSets.Count);
            Assert.AreEqual(0, boardState.HexagonSets[0].Hexagons[0].Id);
            Assert.IsTrue(boardState.HexagonSets[0].Hexagons[0].IsDestroyed);
            Assert.AreEqual(0, boardState.HexagonSets[1].Hexagons.Count);
        }

        game.Board.DestroyHexagon(0);
        Schema.BoardState emptyBoardState = game.Board.GetBoardState();
        Assert.AreEqual(0, emptyBoardState.HexagonSets[0].Hexagons.Count);
    }
Пример #2
0
    public void Game_InitialBoardStateMessage()
    {
        Game   game    = new Game();
        Client client1 = TestObjects.BuildClient();
        Client client2 = TestObjects.BuildClient();

        game.AddClient(client1);
        game.AddClient(client2);
        game.Update(game.LastUpdateTime);

        foreach (Client player in game.Players)
        {
            Schema.BoardState boardState     = player.MessageLog.First.Value.Unpack <Schema.BoardState>();
            HashSet <Hexagon> uniqueHexagons = new HashSet <Hexagon>();
            foreach (Schema.HexagonSet hexSet in boardState.HexagonSets)
            {
                foreach (Schema.Hexagon hexagon in hexSet.Hexagons)
                {
                    Assert.AreEqual(game.Board.Hexagons[hexagon.Id].Id, hexagon.Id);
                    Assert.AreEqual(game.Board.Hexagons[hexagon.Id].Position.X, hexagon.Position.X);
                    Assert.AreEqual(game.Board.Hexagons[hexagon.Id].Position.Y, hexagon.Position.Y);
                    Assert.AreEqual(game.Board.Hexagons[hexagon.Id].PlayerId, hexSet.PlayerId);
                    Assert.AreEqual(game.Board.Hexagons[hexagon.Id].IsDestroyed, hexagon.IsDestroyed);
                }
            }
        }

        Schema.BoardState emptyBoardState = game.Board.GetBoardState();
        Assert.AreEqual(2, emptyBoardState.HexagonSets.Count);
        Assert.AreEqual(0, emptyBoardState.HexagonSets[0].Hexagons.Count);
        Assert.AreEqual(0, emptyBoardState.HexagonSets[1].Hexagons.Count);
    }
Пример #3
0
    public void HandleBoardStateChange(Schema.BoardState boardState)
    {
        foreach (Schema.HexagonSet set in boardState.HexagonSets)
        {
            if (Hexagons.ContainsKey(set.PlayerId) == false)
            {
                Hexagons[set.PlayerId] = new Dictionary <int, GameObject>();
            }

            foreach (Schema.Hexagon hexagon in set.Hexagons)
            {
                Vector2 position = new Vector2(hexagon.Position.X, hexagon.Position.Y);
                Hexagons[set.PlayerId][hexagon.Id] = Instantiate(Hexagon, position, new Quaternion(), this.transform);
            }
        }
    }
Пример #4
0
    public Schema.BoardState GetBoardState()
    {
        Schema.BoardState boardState = new Schema.BoardState();

        for (int i = 0; i < Game.MaxPlayers; i++)
        {
            boardState.HexagonSets.Add(new Schema.HexagonSet {
                PlayerId = i
            });
        }

        foreach (int hexagonId in unsentChanges)
        {
            boardState.HexagonSets[Hexagons[hexagonId].PlayerId].Hexagons.Add(Hexagons[hexagonId].ToContract());
        }

        unsentChanges = new List <int>();

        return(boardState);
    }
Пример #5
0
    public void Server_ClientLookingForGame()
    {
        Server server = new Server(8080);
        Client client = TestObjects.BuildClient(server);

        client.ClientSendToServer(Any.Pack(client.BuildLookingForGame()));

        Assert.IsTrue(client.MessageLog.First.Value.Is(Schema.LookingForGame.Descriptor));

        Schema.JoinedGame joinedGameResponse = client.MessageLog.First.Next.Value.Unpack <Schema.JoinedGame>();
        Assert.AreEqual(client.Username, joinedGameResponse.Username);

        Assert.IsTrue(client.MessageLog.Last.Value.Is(Schema.BoardState.Descriptor));
        Schema.BoardState boardState = client.MessageLog.Last.Value.Unpack <Schema.BoardState>();
        byte[]            bytes      = boardState.ToByteArray();
        Assert.IsTrue(bytes.Length < Constants.DEFAULT_BUFFER_SIZE);
        int totalHexagonCount = boardState.HexagonSets[0].Hexagons.Count + boardState.HexagonSets[1].Hexagons.Count;

        Assert.AreEqual(Constants.RowsPerPlayer * Constants.HexagonsPerRow * 2, totalHexagonCount);
    }