コード例 #1
0
 //Remove this railroad's cost from player's total money.
 //Sets the money to zero if money goes below zero.
 public void RemoveMoney(Railroad railroad)
 {
     if ((totalMoney - railroad.GetCost()) < 0)
     {
         totalMoney = 0;
     }
     else
     {
         totalMoney -= railroad.GetCost();
     }
 }
コード例 #2
0
 //Checks if a player can afford this railroad
 public bool DoesPlayerHaveMoney(Railroad railroad)
 {
     if (totalMoney >= railroad.GetCost())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #3
0
        public RailroadSpace(int spaceId, int x, int y, Railroad railroad, Size size, RotateEnum rotate)
            : base(spaceId, x, y, size, rotate)
        {
            utilityNameFormat = new StringFormat();
            utilityNameFormat.LineAlignment = StringAlignment.Near;
            utilityNameFormat.Alignment     = StringAlignment.Center;


            utilityCostFormat = new StringFormat();
            utilityCostFormat.LineAlignment = StringAlignment.Far;
            utilityCostFormat.Alignment     = StringAlignment.Center;

            this.railroad = railroad;

            if (rotate == RotateEnum.Rotate90 || rotate == RotateEnum.Rotate270)
            {
                Rotate();
            }

            GenerateQuadrants();
        }
コード例 #4
0
ファイル: GameBoard.cs プロジェクト: Rubynight/Monopoly_Copy
        //Reads text file and generates board spaces.
        //Creates 40 spaces
        public void LoadBoardFromFile()
        {
            //Determines the dimensions of the spaces and the starting
            //locations for the four board lanes.
            double sizeMultiplier = FormatManager.GetSizeMultiplier();
            int    SpaceSize      = (int)((size.Width / 11) * sizeMultiplier);
            int    LaneOneY       = SpaceSize * 9 + SpaceSize;
            int    LaneTwoX       = 0;
            int    LaneThreeY     = 0;
            int    LaneFourX      = SpaceSize * 9 + SpaceSize;

            //Variables for reading the text file
            int    i = 1;
            int    x = 0;
            int    id;
            String spaceType;
            String line;

            String[] lineSplit;
            char     token = ',';

            reader = new StreamReader(fileLocation);

            //Add the four constant spaces and the inner board (rectangle within board).
            innerBoard = new RectangleObject(LaneTwoX + SpaceSize, LaneThreeY + SpaceSize, new Size(SpaceSize * 9, SpaceSize * 9));
            boardSpaces.Add(new JailSpace(JAIL_SPACE_ID, LaneOneY, LaneOneY, Color.White, new Size(SpaceSize, SpaceSize), RotateEnum.DoNotRotate));
            boardSpaces.Add(new FreeParkingSpace(FREE_PARKING_SPACE_ID, LaneTwoX, LaneOneY, Color.White, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate270));
            boardSpaces.Add(new GoToJailSpace(GO_TO_JAIL_SPACE_ID, LaneTwoX, LaneThreeY, Color.White, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate180));
            boardSpaces.Add(new GoSpace(GO_SPACE_ID, LaneFourX, LaneThreeY, Color.White, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate90));

            //Reads the whole file and generates a board space for each line
            while (!reader.EndOfStream)
            {
                line      = reader.ReadLine();
                lineSplit = line.Split(token);
                spaceType = lineSplit[0];

                //Moves to next lane once the lane is filled
                if (i == 10)
                {
                    i = 1;
                    x++;
                }

                //Keeps the id consistent across lanes
                id = (i + (x * 10));

                //Used to determine what kind of board space to create
                //Each case is a space type and each if is a lane
                switch (spaceType)
                {
                case "Property":

                    Property property = new Property(lineSplit[1], int.Parse(lineSplit[2]), 0, Color.FromName(lineSplit[3].Trim()));
                    if (x == 0)
                    {
                        boardSpaces.Add(new PropertySpace(id, LaneFourX, (i * SpaceSize) + (SpaceSize - SpaceSize), property, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate90));
                    }
                    else if (x == 1)
                    {
                        boardSpaces.Add(new PropertySpace(id, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), LaneOneY, property, new Size(SpaceSize, SpaceSize), RotateEnum.DoNotRotate));
                    }
                    else if (x == 2)
                    {
                        boardSpaces.Add(new PropertySpace(id, LaneTwoX, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), property, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate270));
                    }
                    else
                    {
                        boardSpaces.Add(new PropertySpace(id, (i * SpaceSize) + (SpaceSize - SpaceSize), LaneThreeY, property, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate180));
                    }
                    break;

                case "Railroad":
                    Railroad railroad = new Railroad(lineSplit[1], int.Parse(lineSplit[2]));
                    if (x == 0)
                    {
                        boardSpaces.Add(new RailroadSpace(id, LaneFourX, (i * SpaceSize) + (SpaceSize - SpaceSize), railroad, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate90));
                    }
                    else if (x == 1)
                    {
                        boardSpaces.Add(new RailroadSpace(id, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), LaneOneY, railroad, new Size(SpaceSize, SpaceSize), RotateEnum.DoNotRotate));
                    }
                    else if (x == 2)
                    {
                        boardSpaces.Add(new RailroadSpace(id, LaneTwoX, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), railroad, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate270));
                    }
                    else
                    {
                        boardSpaces.Add(new RailroadSpace(id, (i * SpaceSize) + (SpaceSize - SpaceSize), LaneThreeY, railroad, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate180));
                    }
                    break;

                case "CommunityChest":
                    if (x == 0)
                    {
                        boardSpaces.Add(new CommunityChestSpace(id, LaneFourX, (i * SpaceSize) + (SpaceSize - SpaceSize), new Size(SpaceSize, SpaceSize), RotateEnum.Rotate90));
                    }
                    else if (x == 1)
                    {
                        boardSpaces.Add(new CommunityChestSpace(id, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), LaneOneY, new Size(SpaceSize, SpaceSize), RotateEnum.DoNotRotate));
                    }
                    else if (x == 0)
                    {
                        boardSpaces.Add(new CommunityChestSpace(id, LaneTwoX, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), new Size(SpaceSize, SpaceSize), RotateEnum.Rotate270));
                    }
                    else
                    {
                        boardSpaces.Add(new CommunityChestSpace(id, (i * SpaceSize) + (SpaceSize - SpaceSize), LaneThreeY, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate180));
                    }
                    break;

                case "Chance":
                    if (x == 0)
                    {
                        boardSpaces.Add(new ChanceSpace(id, LaneFourX, (i * SpaceSize) + (SpaceSize - SpaceSize), new Size(SpaceSize, SpaceSize), RotateEnum.Rotate90));
                    }
                    else if (x == 1)
                    {
                        boardSpaces.Add(new ChanceSpace(id, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), LaneOneY, new Size(SpaceSize, SpaceSize), RotateEnum.DoNotRotate));
                    }
                    else if (x == 2)
                    {
                        boardSpaces.Add(new ChanceSpace(id, LaneTwoX, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), new Size(SpaceSize, SpaceSize), RotateEnum.Rotate270));
                    }
                    else
                    {
                        boardSpaces.Add(new ChanceSpace(id, (i * SpaceSize) + (SpaceSize - SpaceSize), LaneThreeY, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate180));
                    }
                    break;

                case "Utility":
                    Utility utility = new Utility(lineSplit[1], 100);
                    if (x == 0)
                    {
                        boardSpaces.Add(new UtilitySpace(id, LaneFourX, (i * SpaceSize) + (SpaceSize - SpaceSize), utility, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate90));
                    }
                    else if (x == 1)
                    {
                        boardSpaces.Add(new UtilitySpace(id, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), LaneOneY, utility, new Size(SpaceSize, SpaceSize), RotateEnum.DoNotRotate));
                    }
                    else if (x == 2)
                    {
                        boardSpaces.Add(new UtilitySpace(id, LaneTwoX, ((10 - i) * SpaceSize) + (SpaceSize - SpaceSize), utility, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate270));
                    }
                    else
                    {
                        boardSpaces.Add(new UtilitySpace(id, (i * SpaceSize) + (SpaceSize - SpaceSize), LaneThreeY, utility, new Size(SpaceSize, SpaceSize), RotateEnum.Rotate180));
                    }
                    break;
                }

                i++;
            }

            reader.Close();
        }
コード例 #5
0
 //Removes railroad from railroad list
 public void RemoveRailraod(Railroad railroad)
 {
     railroadsOwned.Remove(railroad);
 }
コード例 #6
0
 //Add railroad to railroad list
 public void AddRailraod(Railroad railroad)
 {
     railroadsOwned.Add(railroad);
 }
コード例 #7
0
 //Gives another player a railroad that the player owns
 public void TradeRailroad(Railroad railroad, Player tradePlayer)
 {
     railroad.SetOwner(tradePlayer);
     tradePlayer.AddRailraod(railroad);
     railroadsOwned.Remove(railroad);
 }