Ejemplo n.º 1
0
    /**
     * Obtain the victory points for a player, given their ID.
     */
    public int GetVictoryPointsForPlayerId(string id)
    {
        BoardGrid boardGrid     = GetComponent <GameManager>().GetGame().GetBoardHandler().GetBoardGrid();
        int       victoryPoints = 0;

        for (int col = 0; col < boardGrid.GetColCount(); col++)
        {
            for (int row = 0; row < boardGrid.GetRowCount(); row++)
            {
                for (int spec = 0; spec < 2; spec++)
                {
                    Vertex vertex = boardGrid.GetVertex(col, row, (BoardGrid.VertexSpecifier)spec);
                    if (vertex != null && vertex.settlement != null)
                    {
                        if (vertex.settlement.ownerId == id)
                        {
                            if (vertex.settlement.isCity)
                            {
                                victoryPoints += 2;
                            }
                            else
                            {
                                victoryPoints += 1;
                            }
                        }
                    }
                }
            }
        }
        return(victoryPoints);
    }
Ejemplo n.º 2
0
    public void CmdRollDice()
    {
        // Roll
        System.Random random = new System.Random();
        int           roll   = random.Next(1, 7) + random.Next(1, 7);

        GameManager.Instance.recentRoll = roll;

        // Update this player's state
        Player thisPlayer = GameManager.Instance.GetPlayerById(playerBehaviour.netId + "");

        if (roll == 7)
        {
            thisPlayer.state = PlayerState.ROBBING;

            // If any players have 8 or more development cards, dump half their hands by random
            foreach (Player player in GameManager.Instance.GetGame().players)
            {
                player.AttemptToDiscardHalfOfCards();
            }
        }
        else
        {
            thisPlayer.state = PlayerState.TRADING;
        }

        // Produce resources for each player
        BoardGrid boardGrid = GameManager.Instance.GetGame().GetBoardHandler().GetBoardGrid();

        for (int col = 0; col < boardGrid.GetColCount(); col++)
        {
            for (int row = 0; row < boardGrid.GetRowCount(); row++)
            {
                Face face = boardGrid.GetFace(col, row);
                if (face != null && face.tile != null && face.tile.chanceValue == roll) // If tile exists, and roll
                {
                    List <Vertex> vertices = boardGrid.GetVerticesFromFace(col, row);
                    foreach (Vertex vertex in vertices) // Get all vertexes of this tile
                    {
                        if (vertex.settlement != null)
                        {
                            Player player = GameManager.Instance.GetPlayerById(vertex.settlement.ownerId);
                            player.AddResource(face.tile.resourceType, vertex.settlement.isCity ? 2 : 1); // Give two resources if city, one if settlement
                        }
                    }
                }
            }
        }

        GameManager.Instance.SetDirtyBit(0b11111111);
    }
Ejemplo n.º 3
0
 /**
  * Robber's first tile is at the desert. The robber represents the most recent "robbery" occurance.
  */
 public void SetupRobberAtDesert()
 {
     for (int col = 0; col < boardGrid.GetColCount(); col++)
     {
         for (int row = 0; row < boardGrid.GetRowCount(); row++)
         {
             if (boardGrid.GetFace(col, row) != null && boardGrid.GetFace(col, row).tile != null)
             {
                 if (boardGrid.GetFace(col, row).tile.resourceType == ResourceType.Desert)
                 {
                     robberCol = col;
                     robberRow = row;
                 }
             }
         }
     }
 }
    /**
     * Obtain the victory points for a player, given their ID.
     */
    public int GetVictoryPointsForPlayerId(string id)
    {
        BoardGrid boardGrid     = GameManager.Instance.GetGame().GetBoardHandler().GetBoardGrid();
        int       victoryPoints = 0;

        // Building related victory points
        for (int col = 0; col < boardGrid.GetColCount(); col++)
        {
            for (int row = 0; row < boardGrid.GetRowCount(); row++)
            {
                for (int spec = 0; spec < 2; spec++)
                {
                    Vertex vertex = boardGrid.GetVertex(col, row, (BoardGrid.VertexSpecifier)spec);
                    if (vertex != null && vertex.settlement != null)
                    {
                        if (vertex.settlement.ownerId == id)
                        {
                            if (vertex.settlement.isCity)
                            {
                                victoryPoints += 2;
                            }
                            else
                            {
                                victoryPoints += 1;
                            }
                        }
                    }
                }
            }
        }

        // Longest Road related victory points

        // Largest Army related victory points

        return(victoryPoints);
    }
Ejemplo n.º 5
0
    public static void WriteBoard(this NetworkWriter writer, BoardGrid boardGrid)
    {
        writer.WriteInt32(boardGrid.GetColCount());
        writer.WriteInt32(boardGrid.GetRowCount());
        for (int col = 0; col < boardGrid.GetColCount(); col++)
        {
            for (int row = 0; row < boardGrid.GetRowCount(); row++)
            {
                // Serialize col, row face
                Face face = boardGrid.GetFace(col, row);

                if (face == null)
                {
                    writer.WriteBoolean(false);
                }
                else if (face.tile == null)
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(false);
                }
                else
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(true);
                    writer.WriteInt32((int)face.tile.resourceType);
                    writer.WriteInt32(face.tile.chanceValue);
                }

                // Serialize col, row vertices L and R
                Vertex vertexL = boardGrid.GetVertex(col, row, BoardGrid.VertexSpecifier.L);
                Vertex vertexR = boardGrid.GetVertex(col, row, BoardGrid.VertexSpecifier.R);

                if (vertexL == null)
                {
                    writer.WriteBoolean(false);
                }
                else if (vertexL.settlement == null)
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(false);
                }
                else
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(true);
                    writer.WriteString(vertexL.settlement.ownerId);
                    writer.WriteBoolean(vertexL.settlement.isCity);
                }

                if (vertexR == null)
                {
                    writer.WriteBoolean(false);
                }
                else if (vertexR.settlement == null)
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(false);
                }
                else
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(true);
                    writer.WriteString(vertexR.settlement.ownerId);
                    writer.WriteBoolean(vertexR.settlement.isCity);
                }

                // Serialize col, row edges W, N and E
                Edge edgeW = boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.W);
                Edge edgeN = boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.N);
                Edge edgeE = boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.E);

                if (edgeW == null)
                {
                    writer.WriteBoolean(false);
                }
                else if (edgeW.road == null)
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(false);
                }
                else
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(true);
                    writer.WriteString(edgeW.road.ownerId);
                }

                if (edgeN == null)
                {
                    writer.WriteBoolean(false);
                }
                else if (edgeN.road == null)
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(false);
                }
                else
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(true);
                    writer.WriteString(edgeN.road.ownerId);
                }

                if (edgeE == null)
                {
                    writer.WriteBoolean(false);
                }
                else if (edgeE.road == null)
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(false);
                }
                else
                {
                    writer.WriteBoolean(true);
                    writer.WriteBoolean(true);
                    writer.WriteString(edgeE.road.ownerId);
                }
            }
        }
    }