Ejemplo n.º 1
0
 public static bool canPlayerTradeWithHarbor(Harbor hb, Player pl)
 {
     foreach (Board.ResourceType rt in Enum.GetValues(typeof(Board.ResourceType)))
     {
         //Get the player's current resource counts.
         int count = pl.getResourceCount(rt);
         if (count >= hb.getRequiredResourceCount())
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        /*
         *  Allow the player to trade with the chosen harbor.
         */
        public void loadHarborTrade(Harbor hb, Player pl)
        {
            //Auto selects resources from other party (some trades allows the player to choose the resource)
            //Build the window based on the harbor.
            initiatingPlayer = pl;
            createResourceSelectors(false, false);
            minimumPlayerInput       = hb.getRequiredResourceCount();
            lblTradeName.Text        = "Harbor";
            lblPlayerTitle.Text      = pl.getName();
            lblPlayerTitle.BackColor = pl.getColor();
            foreach (ResourceSelector sel in playerResourceSelectors)
            {
                sel.Click += lockedTradePlayerClickPlayerResource;
            }

            if (hb.getTradeOutputResource() == Board.ResourceType.Desert)
            {
                //The player may choose any resource to trade for.
                foreach (ResourceSelector select in otherResourceSelectors)
                {
                    select.Click += playerClickOtherResource;
                }
            }
            else
            {
                //The player is only allowed to choose the one resource.
                canClearOther = false;
                foreach (ResourceSelector select in otherResourceSelectors)
                {
                    if (select.type == hb.getTradeOutputResource())
                    {
                        select.setSelected(true);
                    }
                    else
                    {
                        select.Hide();
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public void setHarbor(Harbor harbor)
 {
     this.harbor = harbor;
 }
Ejemplo n.º 4
0
        /*
         *  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();
        }