public void newChip(ref int row, ref int column, ref int value) { Random randomGenerator; randomGenerator = new Random(); if (randomGenerator.Next(2) == 0) { value = 2; } else { value = 4; } NumberChip chip = new NumberChip(value); column = randomGenerator.Next(4); row = randomGenerator.Next(4); while (board.getBoardPosition(row, column).getValue() != 0) { column = randomGenerator.Next(4); row = randomGenerator.Next(4); } board.setBoardPosition(row, column, chip); updateChipCollection(); }
public override void enableEventObjects() { foreach (Tile t in theBoard.boardTiles) { if (t is TerrainTile) { TerrainTile tt = (TerrainTile)t; tt.getNumberChip().Click += executeUpdate; if (tt.getNumberChip().isBlocked()) { oldThiefLocation = tt.getNumberChip(); } } } foreach (Settlement set in theBoard.settlementLocations) { set.Click += executeUpdate; } }
/* * A bit of an odd workaround for the issue of having no way to handle exceptions from buttons firing these * methods. */ public void exec(object sender, EventArgs e) { //Check switch (state) { case 0: if (sender is NumberChip) { NumberChip nc = (NumberChip)sender; //Check if the player has selected the desert if (Board.THIEF_MUST_MOVE && nc.isBlocked()) { throw new ThiefException(ThiefException.THIEF_CANNOT_STAY); } if (Board.THIEF_CANNOT_GO_HOME && nc.getNumber() == 0) { throw new ThiefException(ThiefException.THIEF_CANNOT_GO_DESERT); } theBoard.addEventText(UserMessages.RobberHasMoved(theBoard.currentPlayer)); oldThiefLocation.removeThief(); nc.placeThief(); oldThiefLocation = nc; if (chitHasPlayers()) { state++; theBoard.addEventText(UserMessages.PLAYER_STEAL_RESOURCES); } else { endExecution(); } } break; case 1: if (!(sender is Settlement)) { //We only run this check in case something did not clean up properly from a previous event. return; } //We check if the settlement is actually adjascent to the thief. if (!terrainTileWithThief.hasSettlement((Settlement)sender)) { throw new ThiefException(ThiefException.CANT_STEAL_FROM_PLAYER); } //Get the player at the chosen location (sender is that location) Player playerToStealFrom = ((Settlement)sender).getOwningPlayer(); //Check if there is a player at the location. if (playerToStealFrom == null) { throw new ThiefException(ThiefException.NO_PLAYER); } //Check if the player is not the current player. if (playerToStealFrom == theBoard.currentPlayer) { throw new ThiefException(ThiefException.YOU_OWN_THIS_SETTLEMENT); } //At this point we can safely assume a card can be taken. ResourceCard rCard = playerToStealFrom.takeRandomResource(); //We check if the card is null because if the player has no cards to give takeRandomResource() returns null. if (rCard != null) { //What happens if there were cards to steal theBoard.currentPlayer.giveResource(playerToStealFrom.takeRandomResource()); theBoard.addEventText(UserMessages.PlayerGotResourceFromPlayer(theBoard.currentPlayer, playerToStealFrom, rCard.getResourceType())); state++; endExecution(); } else { //What happens if there were no cards to steal. theBoard.addEventText(UserMessages.PlayerGoNoResourceFromPlayer(theBoard.currentPlayer, playerToStealFrom)); state++; endExecution(); } break; } }
internal void setBoardPosition(int row, int column, int value) { NumberChip chip = new NumberChip(value); board.setBoardPosition(row, column, chip); }