コード例 #1
0
        /*
         * This will allow the player to choose what resources they loose when
         * the dice land on a "7" while the player has more than 7 resources on hand.
         */
        public void loadPlayerResourceLoss(Player pl)
        {
            //Load the player's resource selectors
            for (int i = 0; i < 5; i++)
            {
                Board.ResourceType resType        = (Board.ResourceType)i;
                ResourceSelector   playerSelector = new ResourceSelector(resType);
                playerResourceSelectors.Add(playerSelector);
                pnlPlayer.Controls.Add(playerSelector);
                playerSelector.Location = new Point(5, i * playerSelector.Height + 1);
                playerSelector.hideControls();
                playerSelector.Click += playerClickResourceSelectorRobber;
            }
            lblInstructions.Visible  = true;
            btnAccept.Enabled        = false;
            initiatingPlayer         = pl;
            lblPlayerTitle.Text      = pl.getName();
            lblPlayerTitle.BackColor = pl.getColor();
            //Disable the cancel button
            btnCancel.Visible = false;
            int numToGive = pl.getTotalResourceCount() / 2; //Since this is an integer, VS will automatically drop the decimal which is essentailly the same as floor(count/2)

            minimumPlayerInput = numToGive;
            //Hide the other section
            lblTradeName.Text = "";
            pnlOther.Visible  = false;
            //Show the player some instructions.
            lblInstructions.Text = "Please select " + numToGive + " resource to give up.";

            btnClearSelection.Click += playerClickResourceSelectorRobber;
        }
コード例 #2
0
 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;
 }
コード例 #3
0
 /*
  *  Allow the player to pick any two available resources from the bank for no cost.
  */
 public void loadYearOfPlenty(Player pl)
 {
     initiatingPlayer         = pl;
     lblTradeName.Text        = "Bank";
     lblPlayerTitle.Text      = pl.getName();
     lblPlayerTitle.BackColor = pl.getColor();
     //Allow the player to choose resources much like they can with the harbor trade
     for (int i = 0; i < 5; i++)
     {
         ResourceSelector otherSelector = new ResourceSelector((Board.ResourceType)i);
         otherResourceSelectors.Add(otherSelector);
         pnlOther.Controls.Add(otherSelector);
         otherSelector.Location = new Point(5, i * otherSelector.Height + 1);
         otherSelector.Click   += yearOfPlentyClickResourceSelector;
         otherSelector.hideControls();
     }
 }
コード例 #4
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();
                    }
                }
            }
        }
コード例 #5
0
        /*
         *  Allow the player to trade any 4 of the same resource for any one other available resource from the bank.
         */
        public void loadBankTrade(Player pl)
        {
            //Bank automatically selects the number of resources on the other party
            initiatingPlayer = 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       = 4;
            lblTradeName.Text        = "Bank";
            lblPlayerTitle.Text      = pl.getName();
            lblPlayerTitle.BackColor = pl.getColor();
            foreach (ResourceSelector sel in playerResourceSelectors)
            {
                sel.Click += lockedTradePlayerClickPlayerResource;
            }

            foreach (ResourceSelector select in otherResourceSelectors)
            {
                select.Click += playerClickOtherResource;
            }
        }
コード例 #6
0
 /*
  *
  */
 public void loadMonopoly(Player pl)
 {
     pnlOther.Visible          = false;
     btnClearSelection.Visible = false;
     lblInstructions.Text     += "Please select the resource you wish to take from the other players.";
     lblInstructions.Visible   = true;
     lblTradeName.Text         = "";
     lblPlayerTitle.Text       = pl.getName();
     lblPlayerTitle.BackColor  = pl.getColor();
     btnAccept.Click          -= acceptClickToBank;
     btnAccept.Click          += acceptClickMonopoly;
     btnAccept.Enabled         = false;
     //Load all resource selectors.
     for (int i = 0; i < 5; i++)
     {
         ResourceSelector resSelect = new ResourceSelector((Board.ResourceType)i);
         resSelect.hideControls();
         pnlPlayer.Controls.Add(resSelect);
         resSelect.Location = new Point(5, i * resSelect.Height + 1);
         playerResourceSelectors.Add(resSelect);
         resSelect.Click += clickMonopoly;
     }
 }
コード例 #7
0
        /*
         *  Allow the player to trade with another player.
         */
        public void loadPlayerTrade(Player currentPlayer, Player otherPlayer)
        {
            //Both players choose their resources.
            initiatingPlayer         = currentPlayer;
            lblPlayerTitle.Text      = currentPlayer.getName();
            lblPlayerTitle.BackColor = currentPlayer.getColor();
            this.otherPlayer         = otherPlayer;
            lblTradeName.Text        = otherPlayer.getName();
            lblTradeName.BackColor   = otherPlayer.getColor();
            otherPlayer.Current      = true;
            btnAccept.Click         -= acceptClickToBank;
            btnAccept.Click         += acceptClickPlayerToPlayer;
            createResourceSelectors(false, false);
            foreach (ResourceSelector sel in playerResourceSelectors)
            {
                sel.Click += ptpClickResourceSelectorPlayer;
            }

            foreach (ResourceSelector sel in otherResourceSelectors)
            {
                sel.Click += ptpClickResourceSelectorOther;
            }
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        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;
        }
コード例 #10
0
 private bool hasOtherPlayerIntersection(Point p1, Player player)
 {
     return map[p1.X, p1.Y].hasABuilding() && map[p1.X, p1.Y].color != player.getColor();
 }
コード例 #11
0
        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;
        }
コード例 #12
0
        public void TestConstructor()
        {
            var player0 = new Player();
            Assert.NotNull(player0);

            String playerName = "player1";
            Color playerColor = Color.Beige;
            var world = new World();
            var player1 = new Player(playerName, playerColor, world);
            Assert.IsTrue(player1.getColor() == playerColor);
            Assert.IsTrue(player1.getName() == playerName);
        }