public void SetUp() { _testBoard = new Board(); _testPlayer = new Player(); _village = new Settlement(_testPlayer, SettlementType.Village); _city = new Settlement(_testPlayer, SettlementType.City); _road = new Road(_testPlayer); }
public void TestCityHasTwoPoints() { var city = new Settlement(_player1, SettlementType.City); (_board.Vertices[0]).Settlement = city; _controller.ScorePlayers(); Assert.AreEqual(2, _player1.Score); Assert.AreEqual(0, _player2.Score); Assert.AreEqual(0, _player3.Score); Assert.AreEqual(0, _player4.Score); }
public void TestVillageHasOnePoint() { var village = new Settlement(_player1, SettlementType.Village); (_board.Vertices[0]).Settlement = village; _controller.ScorePlayers(); Assert.AreEqual(1, _player1.Score); Assert.AreEqual(0, _player2.Score); Assert.AreEqual(0, _player3.Score); Assert.AreEqual(0, _player4.Score); }
public void TestVillageAndCityHasThreePoints() { var village = new Settlement(_player1, SettlementType.Village); var city = new Settlement(_player1, SettlementType.City); (_board.Vertices[0]).Settlement = village; (_board.Vertices[1]).Settlement = city; _controller.ScorePlayers(); Assert.AreEqual(3, _player1.Score); Assert.AreEqual(0, _player2.Score); Assert.AreEqual(0, _player3.Score); Assert.AreEqual(0, _player4.Score); }
public void addTradeLocation(Settlement s) { this.validTradeLocations.Add(s); }
private void OnVertexClick(object sender, EventArgs e) { var currentPlayer = _gameController.CurrentPlayer; ButtonWithVertex curVertex; Pen pen; Road road; Settlement piece; switch(_context) { case Context.None: break; case Context.PlaceCity: var settlement = new Settlement(currentPlayer, SettlementType.City); try { _board.PlacePiece(settlement, ((ButtonWithVertex) sender)._vertex.Index); } catch (Exception ex) { MessageBox.Show( Resources.settlementPlacementError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } currentPlayer.Buy(settlement); ((Button) sender).BackColor = currentPlayer.GetDrawColor(); ((Button) sender).Text = Resources.C; _context = Context.None; break; case Context.RoadBuildingFirstVertex: case Context.PlaceRoadFirstVertex: _roadFirstVertex = sender as ButtonWithVertex; _vertexOriginalColor = _roadFirstVertex.BackColor; _roadFirstVertex.BackColor = Color.Yellow; if (_context == Context.PlaceRoadFirstVertex) { _context = Context.PlaceRoadSecondVertex; } else { _context = Context.RoadBuildingSecondVertex; } break; case Context.RoadBuildingSecondVertex: case Context.PlaceRoadSecondVertex: curVertex = sender as ButtonWithVertex; if (!curVertex._vertex.Neighbors.Contains(_roadFirstVertex._vertex)) { MessageBox.Show( Resources.neighboringVertexError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } if (curVertex._vertex.HasRoad(_roadFirstVertex._vertex)) { MessageBox.Show( Resources.roadExistsError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } _roadFirstVertex.BackColor = _vertexOriginalColor; road = new Road(currentPlayer); try { _board.PlacePiece(road, curVertex._vertex, _roadFirstVertex._vertex); } catch (Exception ex) { MessageBox.Show( Resources.roadPlacementError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } if (_context == Context.PlaceRoadSecondVertex) { currentPlayer.Buy(road); } pen = new Pen(currentPlayer.GetDrawColor(), 10); CreateGraphics().DrawLine(pen, curVertex.Location.X + 10, curVertex.Location.Y + 10, _roadFirstVertex.Location.X + 10, _roadFirstVertex.Location.Y + 10); if (_context == Context.PlaceRoadSecondVertex || _roadBuildingFirst) { _roadBuildingFirst = false; _context = Context.None; } else { _roadBuildingFirst = true; _context = Context.RoadBuildingFirstVertex; } break; case Context.PlaceVillage: piece = new Settlement(currentPlayer, SettlementType.Village); try { _board.PlacePiece(piece, ((ButtonWithVertex)sender)._vertex.Index); } catch (Exception ex) { MessageBox.Show( Resources.settlementPlacementError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } currentPlayer.Buy(piece); ((Button) sender).BackColor = currentPlayer.GetDrawColor(); ((Button) sender).Text = Resources.V; _context = Context.None; break; case Context.Trade: _context = Context.None; break; case Context.PlaceVillageSetup: piece = new Settlement(currentPlayer, SettlementType.Village); try { _board.PlacePieceSetup(piece, ((ButtonWithVertex)sender)._vertex.Index); } catch (Exception ex) { MessageBox.Show( Resources.settlementPlacementError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } ((Button) sender).BackColor = currentPlayer.GetDrawColor(); ((Button) sender).Text = Resources.V; _roadFirstVertex = sender as ButtonWithVertex; _context = Context.PlaceRoadSetup; GameSetup(); break; case Context.PlaceRoadSetup: curVertex = sender as ButtonWithVertex; if (!curVertex._vertex.Neighbors.Contains(_roadFirstVertex._vertex)) { MessageBox.Show( Resources.neighboringVertexError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } if (curVertex._vertex.HasRoad(_roadFirstVertex._vertex)) { MessageBox.Show( Resources.roadExistsError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } road = new Road(currentPlayer); try { _board.PlacePieceSetup(road, curVertex._vertex, _roadFirstVertex._vertex); } catch (Exception ex) { MessageBox.Show( Resources.roadPlacementError, Resources.invalidLocation, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } pen = new Pen(currentPlayer.GetDrawColor(), 10); CreateGraphics().DrawLine(pen, curVertex.Location.X + 10, curVertex.Location.Y + 10, _roadFirstVertex.Location.X + 10, _roadFirstVertex.Location.Y + 10); _context = Context.PlaceVillageSetup; NextPlayerSetup(); GameSetup(); break; default: break; } }
public void addSettlement(Settlement s) { this.settlements.Add(s); }
/* * Creates the data structures used for the board's tiles. */ public void distributeTiles() { //Sets up the terrain tiles deck terrainTiles = new Deck(19); foreach (Board.ResourceType r in fourPlayerTiles) { terrainTiles.putCard(new TerrainTile(pnlBoardArea, r, this.tileImages[(int)r])); } terrainTiles.shuffleDeck(); //Set up the number chip deck. (can be randomized, however, the default is to keep the correct order). numberChips = new Deck(18); foreach (int num in fourPlayerNumberChips) { numberChips.putCard(new NumberChip(num)); } /* * If random number chip order is marked, randomize the number chips deck. * Replace x with proper condition * * if (x) { * numberChips.shuffleDeck(); * } */ int row = 0; int column = 0; //This creates and positions each tile in the world. for (int i = 0; i < BOARD_TILE_COUNT; i++) { int numSettlementSpots = 2; //By default each tile creates 2 settlement spots //This checks for the end of a row on specific indices for correct row breaks. if (i == 4 || i == 9 || i == 15 || i == 22 || i == 28 || i == 33) { row += 1; column = 0; //We need to create 3 settlement spots } //Shift is used to keep track of the row offsets for the correct "meshing" of the tiles. int shift = 0; //This checks for every other row and applies a half tile shift if it is an odd numbered row. if (row % 2 != 0) { shift += SPACING / 2; } //This shifts the specified row indices by whole tiles for the correct look. switch (row) { case 0: shift += SPACING * 2; break; case 1: shift += SPACING * 1; break; case 2: shift += SPACING * 1; break; case 4: shift += SPACING * 1; break; case 5: shift += SPACING * 1; //We need to create even more settlement spots (+4) numSettlementSpots++; //if (i==) break; case 6: shift += SPACING * 2; break; } //Determine if this tile is an ocean border. bool ocean = false; for (int f = 0; f < oceanBorderIndsFourPlayer.Length; f++) { if (i == oceanBorderIndsFourPlayer[f]) { ocean = true; } } Point position = new Point(column * SPACING + shift, row * (SPACING - TILE_TRIANGLE_HEIGHT)); if (!ocean) { TerrainTile tile = (TerrainTile)terrainTiles.drawTopCard(); tile.setPosition(position); tile.index = i; boardTiles[i] = tile; if (tile.getResourceType() == ResourceType.Desert) { //Create a number chip with a value of 0 tile.setNumberChip(new NumberChip(0)); tile.placeThief(); } else { //Get the next number chip in line. tile.setNumberChip((NumberChip)numberChips.drawTopCard()); } } else { OceanBorderTile tile = new OceanBorderTile(pnlBoardArea); tile.setPosition(position); tile.index = i; boardTiles[i] = tile; } column++; /* * The following code block takes care of creating, linking, and positioning each settlement and road for the game. * This ensures there are no duplicate locations. * */ if (!ocean) { TerrainTile t = (TerrainTile)boardTiles[i]; //Default placement is the top left and top center locations of the tile. //This covers almost all settlement locations. Point[] settlementPoints = new Point[6]; //A list of positions for each possible settlement location on this tile. The order matters greatly. (In a clockwise direction) settlementPoints[0] = new Point(position.X, position.Y + TILE_TRIANGLE_HEIGHT); settlementPoints[1] = new Point(position.X + (SPACING / 2), position.Y); settlementPoints[2] = new Point(position.X + SPACING, position.Y + TILE_TRIANGLE_HEIGHT); settlementPoints[3] = new Point(position.X + SPACING, position.Y + SPACING - TILE_TRIANGLE_HEIGHT); settlementPoints[4] = new Point(position.X + (SPACING / 2), position.Y + SPACING); settlementPoints[5] = new Point(position.X, position.Y + SPACING - TILE_TRIANGLE_HEIGHT); foreach (Point setPoint in settlementPoints) { //We check if this settlement location has already been created. Settlement settlementLocation = findSettlementWithPosition(setPoint); //If not already created we need to make a new location if (settlementLocation == null) { settlementLocation = new Settlement(setPoint, 0); settlementLocation.id = settlementLocations.Count; settlementLocations.Add(settlementLocation); pnlBoardArea.Controls.Add(settlementLocation); settlementLocation.BringToFront(); } t.adjascentSettlements.Add(settlementLocation); } //This is almost an exact duplicate of the above process. The only difference being the positions. Point[] roadPoints = new Point[6]; roadPoints[0] = new Point(position.X, position.Y + (SPACING / 2)); //V roadPoints[1] = new Point(position.X + (SPACING / 4), position.Y + (TILE_TRIANGLE_HEIGHT / 2)); //H L roadPoints[2] = new Point(position.X + (SPACING / 4) * 3, position.Y + (TILE_TRIANGLE_HEIGHT / 2)); // H R roadPoints[3] = new Point(position.X + SPACING, position.Y + (SPACING / 2)); //V roadPoints[4] = new Point(position.X + (SPACING / 4) * 3, position.Y + (SPACING - (TILE_TRIANGLE_HEIGHT / 2))); //H R roadPoints[5] = new Point(position.X + (SPACING / 4), position.Y + (SPACING - (TILE_TRIANGLE_HEIGHT / 2))); //H L int f = 0; foreach (Point roadPoint in roadPoints) { //We check if this settlement location has already been created. Road roadLocation = findRoadWithPosition(roadPoint); if (roadLocation == null) { roadLocation = new Road(roadPoint, 0); pnlBoardArea.Controls.Add(roadLocation); roadLocation.id = roadLocations.Count; roadLocations.Add(roadLocation); roadLocation.BringToFront(); roadLocation.BackgroundImage = new Bitmap(roadImageLocations[f]); roadLocation.Size = roadLocation.BackgroundImage.Size; roadLocation.Location = new Point(roadPoint.X - (roadLocation.BackgroundImage.Width / 2), roadPoint.Y - (roadLocation.BackgroundImage.Height / 2)); } t.adjascentRoads.Add(roadLocation); f++; } //Next we link the roads and settlements together. //We know the order in which the roads and settlements were created in, so all we need to do is link them in that order. for (int index = 0; index < 6; index++) { t.adjascentRoads[index].linkSettlement(t.adjascentSettlements[index]); //Link settlement to road if (index == 0) { t.adjascentRoads[index].linkSettlement(t.adjascentSettlements[5]); } else { t.adjascentRoads[index].linkSettlement(t.adjascentSettlements[index - 1]); } //Link road to settlement t.adjascentSettlements[index].linkRoad(t.adjascentRoads[index]); if (index == 5) { t.adjascentSettlements[index].linkRoad(t.adjascentRoads[0]); } else { t.adjascentSettlements[index].linkRoad(t.adjascentRoads[index + 1]); } } } } //Position each of the harbors for (int i = 0; i < FourPlayerHarborLocations.Count(); i++) { //Create a new harbor using the information from the trade at harborCount location OceanBorderTile bt = (OceanBorderTile)this.boardTiles[FourPlayerHarborLocations[i]]; Harbor h = new Harbor(FourPlayerHarborRequiredResources[i], FourPlayerHarborOutputResources[i]); //MessageBox.Show("Resources/" + FourPlayerHarborResourceNames[harborCount]); h.BackgroundImage = new Bitmap("Resources/" + FourPlayerHarborResourceNames[i]); h.Location = new Point(0, TILE_TRIANGLE_HEIGHT); harbors.Add(h); bt.setHarbor(h); bt.Controls.Add(h); //Set the settlements that will be able to use this harbor Point position = bt.getPosition(); Point[] settlementPoints = new Point[6]; //A list of positions for each possible settlement location on this ocean border settlementPoints[0] = new Point(position.X, position.Y + TILE_TRIANGLE_HEIGHT); settlementPoints[1] = new Point(position.X + (SPACING / 2), position.Y); settlementPoints[2] = new Point(position.X + SPACING, position.Y + TILE_TRIANGLE_HEIGHT); settlementPoints[3] = new Point(position.X + SPACING, position.Y + SPACING - TILE_TRIANGLE_HEIGHT); settlementPoints[4] = new Point(position.X + (SPACING / 2), position.Y + SPACING); settlementPoints[5] = new Point(position.X, position.Y + SPACING - TILE_TRIANGLE_HEIGHT); //Look through the list of points to see if any of these positions match exisiting settlement locations foreach (Point p in settlementPoints) { Settlement set = findSettlementWithPosition(p); if (set != null) { //We have found a valid trade location bt.getHarbor().addTradeLocation(set); } } } foreach (Settlement set in settlementLocations) { var adjTiles = boardTiles .OfType <TerrainTile>() .Where(x => x.adjascentSettlements.Contains(set)); set.adjacentTiles.AddRange(adjTiles); } debugSaveBoardData(); }