public bool canBuildAtIntersection(Player player, int rounds) { bool canBuild; if (this.hasABuilding()) // Cannot build here if this intersection has a building { canBuild = false; } else if (this.areAllThreeSurroundingIntersectionsAvailableToBuild()) // We can build here because nobody around already built something! { // This player must have a road leading here IF it is not the first round if (!playerHasExistingConnection(player.getColor()) && rounds >= 2) { canBuild = false; } else { canBuild = true; } } else // There is a conflict because a surrounding intersection already has a building { canBuild = false; } return canBuild; }
public TradeForm(World world, GameScreen gameScreen) { this.world = world; this.gameScreen = gameScreen; this.currentPlayerNumber = this.world.currentPlayerNumber; this.currentPlayer = this.world.currentPlayer; int nextPlayerNumber = this.currentPlayerNumber + 1; if (nextPlayerNumber == this.world.players.Count()) { nextPlayerNumber = 0; } this.nextPlayer1 = world.players[nextPlayerNumber]; nextPlayerNumber++; if (nextPlayerNumber == this.world.players.Count()) { nextPlayerNumber = 0; } this.nextPlayer2 = world.players[nextPlayerNumber]; nextPlayer1Checked = false; nextPlayer2Checked = false; InitializeComponent(); NextPlayer1Label.Text = this.nextPlayer1.getName(); NextPlayer2Label.Text = this.nextPlayer2.getName(); localize(); updateCurrentPlayerNameLabel(); }
//Purpose: set all road information and remove resources when a settlement is road //Param: gr - gamenode that is getting the road, px - player that is placing road public void AddingRoad(GameRoad gr, Player px) { if (!gameStartMode) //need to also check against Road Card { OurGame.gameBoard.setRoadInfo(gr, px); px.wood--; px.brick--; px.roadPieces++; px.SetBuildBools(); //CheckLongestRoad(); Not implemented yet } //else if(roadCard) // { // // if (roadCardCounter < 2) // { // buildingRoad = true; // OurGame.gameBoard.setRoadInfo(gr, px); // } // } else if (gameStartMode) { OurGame.gameBoard.setRoadInfo(gr, px); px.roadPieces--; } }
//Build a city, any city public bool buildCity(Player px, SettlersOfCatan game) { //Get our current settlements List<GameNode> settlements = game.gameBoard.placesForCities(px); GameNode buildHere = null; int maxProb = 0; foreach (GameNode gn in settlements) { string gh1 = gn.hex1.hexType; string gh2 = gn.hex2.hexType; string gh3 = gn.hex3.hexType; if (gh1 == "Ocean" || gh2 == "Ocean" || gh3 == "Ocean") { /*ignore, it sits on a port so no real benefit to improving that one */ } else { int tempProb = getProbability(gn.hex1.hexNumber) + getProbability(gn.hex2.hexNumber) + getProbability(gn.hex3.hexNumber); if (tempProb > maxProb) { maxProb = tempProb; buildHere = gn; } } } if (buildHere != null) { PlayingState ps = (PlayingState)game.PlayingState; ps.AddingCity(buildHere, px); return true; } return false; }
public bool buildHorizontalRoad(Point coords, Player player) { int xVal = coords.X; int yVal = coords.Y; int intRow, intCol = 0; intRow = xVal/2; if (xVal == 0 || xVal == 10) { intCol = yVal + 2; } else if (xVal == 2 || xVal == 8) { intCol = yVal + 1; } else if (xVal == 4 || xVal == 6) { intCol = yVal; } else { } // throw exception? if (roadHasBuildingOrConnectingRoad(new Point(intRow, intCol), new Point(intRow, intCol + 1), player)) { map[intRow, intCol].connections[2].buildRoad(player.getColor()); map[intRow, intCol + 1].connections[0].buildRoad(player.getColor()); player.addConnection(map[intRow, intCol].connections[2]); return true; } else return false; }
public Road(Player player) { // TODO: Complete member initialization this.player = player; Indices = new int[2]; Marked = false; }
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 BankTradeForm(World world, GameScreen gs) { InitializeComponent(); this.world = world; this.gameScreen = gs; this.current = this.world.currentPlayer; localize(); }
public Trade buildBankTrade(Player theTrader, int resourceRequestIdx, int resourceOfferIdx, int offerAmount) { int[] myOffer = new int[5]; myOffer[resourceOfferIdx] = offerAmount; int[] myReqest = new int[5]; myReqest[resourceRequestIdx] = 1; Trade myTrade = new Trade(theTrader, myOffer, myReqest); return myTrade; }
public RemoveCardsForm(Player p, GameScreen gs) { this.player = p; this.gameScreen = gs; this.hand = p.getHand(); InitializeComponent(); updateLabels(); updateComboBoxes(); }
public GameController(List<Player> players) { Dice = new Dice(); Players = players; CurrentPlayer = Players[0]; Board = new Board(); InitializeResourceLookup(); InitializeResourceDeck(); InitializeDevelopmentDeck(); CurrentPlayer = PickFirstPlayer(); }
//get a development card from the RandomCardArray public Player getCard(Player px) { px.devCards[RandCardArray[CardPlaceHolder]]++; //px.playerCard++; if (RandCardArray[CardPlaceHolder] > 0 && RandCardArray[CardPlaceHolder] < 6) { px.hiddenVictoryPoints++; } CardPlaceHolder++; return px; }
//Purpose: set all city information and remove resources when a city is built //Param: gn - gamenode that is getting the city, px - player that is placing city public void AddingCity(GameNode gn, Player px) { px.hiddenVictoryPoints++; px.victoryPoints++; px.cityPieces++; px.settlementPieces--; OurGame.gameBoard.setNodeInfo(gn, 1, px); px.ore = px.ore - 3; px.wheat = px.wheat - 2; px.SetBuildBools(); }
private void btn_Ok_Click(object sender, EventArgs e) { if ( txt_Name1.Text == "" || txt_Name2.Text == "" || txt_Name3.Text == "" || (txt_Name4.Text == "" && NumPlayers > 3) || cbox_Color1.SelectedItem.ToString() == Resources.None || cbox_Color2.SelectedItem.ToString() == Resources.None || cbox_Color3.SelectedItem.ToString() == Resources.None || (cbox_Color4.SelectedItem.ToString() == Resources.None && NumPlayers > 3) ) { MessageBox.Show( "You have not completed all of the required fields.", "Incomplete Field", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } else { Player1Name = txt_Name1.Text; Player1Color = (Colors)Enum.Parse(typeof(Colors), getColor(cbox_Color1.SelectedItem.ToString())); var player1 = new Player(Player1Name) {PlayerColor = Player1Color}; Player2Name = txt_Name2.Text; Player2Color = (Colors) Enum.Parse(typeof (Colors), getColor(cbox_Color2.SelectedItem.ToString())); var player2 = new Player(Player2Name) { PlayerColor = Player2Color }; Player3Name = txt_Name3.Text; Player3Color = (Colors) Enum.Parse(typeof (Colors), getColor(cbox_Color3.SelectedItem.ToString())); var player3 = new Player(Player3Name) { PlayerColor = Player3Color }; var players = new List<Player> { player1, player2, player3 }; if (NumPlayers > 3) { Player4Name = txt_Name4.Text; Player4Color = (Colors) Enum.Parse(typeof (Colors), getColor(cbox_Color4.SelectedItem.ToString())); players.Add(new Player(Player4Name) { PlayerColor = Player4Color }); } Controller = new GameController(players); this.DialogResult = DialogResult.OK; return; } }
public GameController(SerializationInfo info, StreamingContext ctxt) { CurrentPlayer = (Player) info.GetValue("CurrentPlayer", typeof (Player)); Board = (Board) info.GetValue("Board", typeof (Board)); Dice = (Dice) info.GetValue("Dice", typeof (Dice)); Players = (List<Player>) info.GetValue("Players", typeof (ArrayList)); ResourceDeck = (Dictionary<TileType, int>) info.GetValue("ResourceDeck", typeof (Dictionary<TileType, int>)); ResourceLookup = (Dictionary<TileType, CardType>) info.GetValue("ResourceLookup", typeof (Dictionary<TileType, CardType>)); DevelopmentDeck = (List<CardType>) info.GetValue("DevelopmentDeck", typeof (ArrayList)); LongestRoad = (Player) info.GetValue("LongestRoad", typeof (Player)); LargestArmy = (Player) info.GetValue("LargestArmy", typeof (Player)); LongestRoadLength = (int) info.GetValue("LongestRoadLength", typeof (int)); }
public frm_gameBoard(GameController controller) { InitializeComponent(); _gameController = controller; _board = _gameController.Board; UpdateUILanguage(); sp_PlayerScores.gc = controller; sp_PlayerScores.UpdateScores(); cp_PlayerColors.Location = new Point(sp_PlayerScores.Location.X + sp_PlayerScores.Width, sp_PlayerScores.Location.Y+1); cp_PlayerColors.setColors(_gameController,sp_PlayerScores.Height); _context = Context.PlaceVillageSetup; pnl_playerData.Enabled = false; _firstPlayer = _gameController.CurrentPlayer; }
public void SetUp() { _board = new Board(); _player1 = new Player(); _player2 = new Player(); _player3 = new Player(); _player4 = new Player(); _controller = new GameController(); _controller.Board = _board; _controller.Players.Add(_player1); _controller.Players.Add(_player2); _controller.Players.Add(_player3); _controller.Players.Add(_player4); }
//Construct the Trade object public Trade(Player px, int[] offer, int[] request) { tradeOffer = new int[5]; tradeRequest = new int[5]; for (int x = 0; x < 5; x++) { tradeOffer[x] = offer[x]; } for (int x = 0; x < 5; x++) { tradeRequest[x] = request[x]; } if (px != null) requestingPlayer = px; }
public bool PlayerCanBuildRoad(Player player) { int size = Roads.Count; Road checkRoad; int roadCount = 0; bool flag = false; for (int i = 0; i < size; i++) { if (Roads[i] != null) { checkRoad = Roads[i]; if (checkRoad.player == player) { flag = true; } roadCount++; } } return ((roadCount < 3) && (flag || (Settlement != null && Settlement.player == player))); }
public World(int humans, int computers, GameScreen gs) : this() { this.gameScreen = gs; players.Add(new Player("Bob", Color.Red, this)); players.Add(new Player("Joe", Color.Blue, this)); players.Add(new AI_Player("Computer", Color.Orange, this)); /* for (int i = 0; i < humans; i++) { Player p = new Player players.Add(new Player()); } for (int i = 0; i < computers; i++) { //players.Add(new Computer()); } */ currentPlayer = this.players[0]; this.currentPlayer.getHand().modifyFreeRoadPoints(1); this.currentPlayer.getHand().modifyFreeSettlementPoints(1); }
public void MonopolyChosen(int resource, Player monopolyPlayer) { foreach (Player px in OurGame.players) { if (px != monopolyPlayer) { int amountOfResource; amountOfResource = px.intToResource(resource, px); for (int i = amountOfResource; i > 0; i--) { px.decResource(resource, px); monopolyPlayer.incResource(resource); } } px.ResourceSum(); } monopolyPlayer.devCards[7]--; monopolyPlayer.cardsAvailable[7]--; monopolyPlayer.ResourceSum(); monopolyPlayer.SetBuildBools(); if (monopolyPlayer == OurGame.humanPlayer) DrawHud.playedCard = true; }
private bool roadHasConnectingRoad(Point p1, Point p2, Player player) { bool flag; bool hasRoad = false; bool roadIsCorrectPlayer = false; if (map[p1.X, p1.Y].connections[0].isBuilt()) { hasRoad = true; roadIsCorrectPlayer = map[p1.X, p1.Y].connections[0].getRoadColor() == player.getColor(); } if (map[p1.X, p1.Y].connections[1].isBuilt() && !roadIsCorrectPlayer) { hasRoad = true; roadIsCorrectPlayer = map[p1.X, p1.Y].connections[1].getRoadColor() == player.getColor(); } if (map[p1.X, p1.Y].connections[2].isBuilt() && !roadIsCorrectPlayer) { hasRoad = true; roadIsCorrectPlayer = map[p1.X, p1.Y].connections[2].getRoadColor() == player.getColor(); } if (map[p2.X, p2.Y].connections[1].isBuilt() && !roadIsCorrectPlayer) { hasRoad = true; roadIsCorrectPlayer = map[p2.X, p2.Y].connections[1].getRoadColor() == player.getColor(); } if (map[p2.X, p2.Y].connections[2].isBuilt() && !roadIsCorrectPlayer) { hasRoad = true; roadIsCorrectPlayer = map[p2.X, p2.Y].connections[2].getRoadColor() == player.getColor(); } if (map[p2.X, p2.Y].connections[0].isBuilt() && !roadIsCorrectPlayer) { hasRoad = true; roadIsCorrectPlayer = map[p2.X, p2.Y].connections[0].getRoadColor() == player.getColor(); } flag = hasRoad && roadIsCorrectPlayer && !hasOtherPlayerIntersection(p1, player); return flag; }
private bool roadHasBuildingOrConnectingRoad(Point p1, Point p2, Player player) { return roadHasPlayerBuilding(p1, p2, player) || roadHasConnectingRoad(p1, p2, player); }
private bool hasOtherPlayerIntersection(Point p1, Player player) { return map[p1.X, p1.Y].hasABuilding() && map[p1.X, p1.Y].color != player.getColor(); }
public bool roadHasPlayerBuilding(Point connection1, Point connection2, Player thePlayer) { bool flag; bool hasBuilding = false; bool buildingIsCorrectPlayer = false; if (map[connection1.X, connection1.Y].hasABuilding()) { hasBuilding = true; buildingIsCorrectPlayer = map[connection1.X, connection1.Y].getPlayer() == thePlayer; } else if (map[connection2.X, connection2.Y].hasABuilding()) { hasBuilding = true; buildingIsCorrectPlayer = map[connection2.X, connection2.Y].getPlayer() == thePlayer; } flag = hasBuilding && buildingIsCorrectPlayer; return flag; }
public bool buildVerticalRoad(Point coords, Player player) { int xVal = coords.X; int yVal = coords.Y; int intRow, intCol = 0; intRow = xVal/2; if (xVal == 1 || xVal == 9) { intCol = yVal*2 + 2; } else if (xVal == 3 || xVal == 7) { intCol = yVal*2 + 1; } else if (xVal == 5) { intCol = yVal*2; } else { } // Throw exception? if (roadHasBuildingOrConnectingRoad(new Point(intRow, intCol), new Point(intRow + 1, intCol), player)) { map[intRow, intCol].connections[1].buildRoad(player.getColor()); map[intRow + 1, intCol].connections[1].buildRoad(player.getColor()); player.addConnection(map[intRow, intCol].connections[1]); return true; } else return false; }
//bank idx is what you want to exchange with the bank //bank trade shoudl be good all the time, so return false because you //dont want to trade with the other players public void tradeWithBank(Player theTrader, SettlersOfCatan game, int bankIdx) { //Get a list of the nodes you own List<GameNode> ownedNodes = game.gameBoard.getPlayerNodes(theTrader); Trade myTrade = new Trade(); int[] currentResources = resourcesToArray(theTrader); int resourceOffer; //Yuck foreach (GameNode gn in ownedNodes) { //Trade 2:1 for a brick if ((gn.brickPort) && (bankIdx == 0)) { resourceOffer = indexOfMostResource(theTrader, new int[1] { 0 }); myTrade = buildBankTrade(theTrader, 0, resourceOffer, 2); } //Trade 2:1 for a wheat else if ((gn.grainPort) && (bankIdx == 1)) { resourceOffer = indexOfMostResource(theTrader, new int[1] { 1 }); myTrade = buildBankTrade(theTrader, 1, resourceOffer, 2); } //Trade 2:1 for a wood else if ((gn.woodPort) && (bankIdx == 2)) { resourceOffer = indexOfMostResource(theTrader, new int[1] { 2 }); myTrade = buildBankTrade(theTrader, 2, resourceOffer, 2); } //Trade 2:1 for a wool else if ((gn.woolPort) && (bankIdx == 3)) { resourceOffer = indexOfMostResource(theTrader, new int[1] { 3 }); myTrade = buildBankTrade(theTrader, 3, resourceOffer, 2); } //Trade 2:1 for an ore else if ((gn.orePort) && (bankIdx == 4)) { resourceOffer = indexOfMostResource(theTrader, new int[1] { 4 }); myTrade = buildBankTrade(theTrader, 4, resourceOffer, 2); } //Trade 3:1 for anything except what you want else if (gn.threePort) { resourceOffer = indexOfMostResource(theTrader); if ((currentResources[resourceOffer] > 3) && (resourceOffer != bankIdx)) myTrade = buildBankTrade(theTrader, bankIdx, resourceOffer, 3); } //Trade 4:1 for anything else { resourceOffer = indexOfMostResource(theTrader); if ((currentResources[resourceOffer] > 4) && (bankIdx != resourceOffer)) myTrade = buildBankTrade(theTrader, bankIdx, resourceOffer, 4); } if (myTrade != null) break; } if (myTrade != null) { //Console.WriteLine("Trading With The Bank: " + theTrader.brick.ToString() + " " + theTrader.wheat.ToString() + " " + theTrader.wood.ToString() + " " + theTrader.wool.ToString() + " " + theTrader.ore.ToString()); for (int x = 0; x < 5; x++) { if(myTrade.tradeOffer[x] != 0) { for (int y = 0; y < myTrade.tradeOffer[x]; y++) { theTrader.decResource(x, theTrader); } } } for(int x = 0; x<5; x++) { if (myTrade.tradeRequest[x] != 0) { for (int y = 0; y < myTrade.tradeRequest[x]; y++) { theTrader.incResource(x); } } } //Console.WriteLine("Traded With The Bank: " + theTrader.brick.ToString() + " " + theTrader.wheat.ToString() + " " + theTrader.wood.ToString() + " " + theTrader.wool.ToString() + " " + theTrader.ore.ToString()); //PlayingState ps = (PlayingState)game.PlayingState; //ps.currentTrade = myTrade; } }
//Purpose: trade for resources that help build settlements // if you can get rid of ore do it, other wise get rid of // whatever you have the most of //Params: theTrader - the Player that is proposing the trade //Return: A Trade object representing the proposed Trade public Trade tradeForSettlement(Player theTrader) { int[] currentResourceAry = resourcesToArray(theTrader); int[] myRequest = fillSettlementRequest(currentResourceAry); int[] myOffer = new int[5]; //You have ore, try to unload it if (currentResourceAry[4] > 0) { if (currentResourceAry[4] == 1) myOffer[4] = 1; else if ((currentResourceAry[4] == 2) || (currentResourceAry[4] == 3)) myOffer[4] = 2; else if (currentResourceAry[4] > 3) myOffer[4] = 3; } //You don't have ore so try to trade 1:1 or 2:1 with your most plentiful else { int mostIDX = indexOfMostResource(theTrader, new int[1] { 4 }); //No point in trading 1 resource you need for 1 resource you need, so dont check it if (currentResourceAry[mostIDX] == 2) myOffer[mostIDX] = 1; else if (currentResourceAry[mostIDX] == 3) myOffer[mostIDX] = 2; else if (currentResourceAry[mostIDX] > 3) myOffer[mostIDX] = 3; } Trade myTrade = new Trade(theTrader, myOffer, myRequest); if (myTrade.isValid()) return myTrade; else return null; }
public Trade tradeForRoad(Player theTrader) { int[] currentResourceAry = resourcesToArray(theTrader); int[] myRequest = fillRoadRequest(currentResourceAry); int[] myOffer = new int[5]; //Road building is more likely to come from strategyType 0 where ore isn't important if (currentResourceAry[4] > 0) { if (currentResourceAry[4] == 1) myOffer[4] = 1; else if ((currentResourceAry[4] == 2) || (currentResourceAry[4] == 3)) myOffer[4] = 2; else if (currentResourceAry[4] > 3) myOffer[4] = 3; } else { int mostIDX = indexOfMostResource(theTrader, new int[1] { 4 }); //No point in trading 1 resource you need for 1 resource you need, so dont check it if (currentResourceAry[mostIDX] == 2) myOffer[mostIDX] = 1; else if (currentResourceAry[mostIDX] == 3) myOffer[mostIDX] = 2; else if (currentResourceAry[mostIDX] > 3) myOffer[mostIDX] = 3; } Trade myTrade = new Trade(theTrader, myOffer, myRequest); if (myTrade.isValid()) return myTrade; else return null; }
public Trade tradeForCity(Player theTrader) { int[] currentResourceAry = resourcesToArray(theTrader); int[] myRequest = fillCityRequest(currentResourceAry); int[] myOffer = new int[5]; //Hang on to your ore [4] and grain [2] int mostIDX = indexOfMostResource(theTrader, new int[2] { 2, 4 }); //No point in trading 1 resource you need for 1 resource you need, so dont check it if (currentResourceAry[mostIDX] == 1) myOffer[mostIDX] = 1; if (currentResourceAry[mostIDX] == 2) myOffer[mostIDX] = 1; else if (currentResourceAry[mostIDX] == 3) myOffer[mostIDX] = 2; else if (currentResourceAry[mostIDX] > 3) myOffer[mostIDX] = 3; Trade myTrade = new Trade(theTrader, myOffer, myRequest); if (myTrade.isValid()) return myTrade; else return null; }