/** * Setup chance token values for each tile on the grid. Tokens are generated in circular order. */ public void SetupChanceTokens() { int tokenIndex = 0; for (int i = 0; i < circularOrderCols.Length; i++) { Tile tile = boardGrid.GetFace(circularOrderCols[i], circularOrderRows[i]).tile; if (!(tile.resourceType == ResourceType.Desert || tile.resourceType == ResourceType.None)) { tile.chanceValue = chanceValues[tokenIndex]; tokenIndex++; } } }
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); }
public bool Equals(BoardGrid other) { for (int col = 0; col < this.GetColCount(); col++) { for (int row = 0; row < this.GetRowCount(); row++) { // This' properties Face face = this.GetFace(col, row); Vertex vertexL = this.GetVertex(col, row, VertexSpecifier.L); Vertex vertexR = this.GetVertex(col, row, VertexSpecifier.R); Edge edgeW = this.GetEdge(col, row, EdgeSpecifier.W); Edge edgeN = this.GetEdge(col, row, EdgeSpecifier.N); Edge edgeE = this.GetEdge(col, row, EdgeSpecifier.E); // Other's properties Face faceOther = other.GetFace(col, row); Vertex vertexLOther = other.GetVertex(col, row, VertexSpecifier.L); Vertex vertexROther = other.GetVertex(col, row, VertexSpecifier.R); Edge edgeWOther = other.GetEdge(col, row, EdgeSpecifier.W); Edge edgeNOther = other.GetEdge(col, row, EdgeSpecifier.N); Edge edgeEOther = other.GetEdge(col, row, EdgeSpecifier.E); // Comparing face if (face == null) { if (faceOther != null) { return(false); } } else { if (!face.Equals(faceOther)) { return(false); } } // Comparing vertices if (vertexL == null) { if (vertexLOther != null) { return(false); } } else { if (!vertexL.Equals(vertexLOther)) { return(false); } } if (vertexR == null) { if (vertexROther != null) { return(false); } } else { if (!vertexR.Equals(vertexROther)) { return(false); } } // Comparing edges if (edgeW == null) { if (edgeWOther != null) { return(false); } } else { if (!edgeW.Equals(edgeWOther)) { return(false); } } if (edgeN == null) { if (edgeNOther != null) { return(false); } } else { if (!edgeN.Equals(edgeNOther)) { return(false); } } if (edgeE == null) { if (edgeNOther != null) { return(false); } } else { if (!edgeE.Equals(edgeEOther)) { return(false); } } } } return(true); }
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); } } } }
public static BoardGrid ReadBoard(NetworkReader reader) { int cols = reader.ReadInt32(); int rows = reader.ReadInt32(); BoardGrid boardGrid = new BoardGrid(cols, rows); for (int col = 0; col < cols; col++) { for (int row = 0; row < rows; row++) { // Face exists? bool faceExists = reader.ReadBoolean(); if (faceExists) { // Face col, row boardGrid.CreateFace(col, row); bool tileExists = reader.ReadBoolean(); if (tileExists) { boardGrid.GetFace(col, row).tile = new Tile(); boardGrid.GetFace(col, row).tile.resourceType = (ResourceType)reader.ReadInt32(); boardGrid.GetFace(col, row).tile.chanceValue = reader.ReadInt32(); } } // Vertex L exists? bool vertexLExists = reader.ReadBoolean(); if (vertexLExists) { boardGrid.CreateVertex(col, row, BoardGrid.VertexSpecifier.L); bool settlementExists = reader.ReadBoolean(); if (settlementExists) { boardGrid.GetVertex(col, row, BoardGrid.VertexSpecifier.L).settlement = new Settlement(); boardGrid.GetVertex(col, row, BoardGrid.VertexSpecifier.L).settlement.ownerId = reader.ReadString(); boardGrid.GetVertex(col, row, BoardGrid.VertexSpecifier.L).settlement.isCity = reader.ReadBoolean(); } } // Vertex R exists? bool vertexRExists = reader.ReadBoolean(); if (vertexRExists) { boardGrid.CreateVertex(col, row, BoardGrid.VertexSpecifier.R); bool settlementExists = reader.ReadBoolean(); if (settlementExists) { boardGrid.GetVertex(col, row, BoardGrid.VertexSpecifier.R).settlement = new Settlement(); boardGrid.GetVertex(col, row, BoardGrid.VertexSpecifier.R).settlement.ownerId = reader.ReadString(); boardGrid.GetVertex(col, row, BoardGrid.VertexSpecifier.R).settlement.isCity = reader.ReadBoolean(); } } // Edge W exists? bool edgeWExists = reader.ReadBoolean(); if (edgeWExists) { boardGrid.CreateEdge(col, row, BoardGrid.EdgeSpecifier.W); bool roadExists = reader.ReadBoolean(); if (roadExists) { boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.W).road = new Road(); boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.W).road.ownerId = reader.ReadString(); } } // Edge N exists? bool edgeNExists = reader.ReadBoolean(); if (edgeNExists) { boardGrid.CreateEdge(col, row, BoardGrid.EdgeSpecifier.N); bool roadExists = reader.ReadBoolean(); if (roadExists) { boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.N).road = new Road(); boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.N).road.ownerId = reader.ReadString(); } } // Edge E exists? bool edgeEExists = reader.ReadBoolean(); if (edgeEExists) { boardGrid.CreateEdge(col, row, BoardGrid.EdgeSpecifier.E); bool roadExists = reader.ReadBoolean(); if (roadExists) { boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.E).road = new Road(); boardGrid.GetEdge(col, row, BoardGrid.EdgeSpecifier.E).road.ownerId = reader.ReadString(); } } } } return(boardGrid); }