public Boolean initializeCardList()
        {
            string  nextCard;
            Boolean isEndOfFile = true;
            Boolean success;
            int     countSpaces = 0;

            nextCard = MonopolyBoardGame.readCardFile.getNextRecord(ref isEndOfFile);
            while (!isEndOfFile)
            {
                countSpaces++;
                CardClass card = new CardClass();
                success = card.createCardObject(nextCard);
                if (success != true)
                {
                    MessageBox.Show("unable to create spaceObject");
                    return(false);
                }
                InternalList.Add(card);
                nextCard = MonopolyBoardGame.readCardFile.getNextRecord(ref isEndOfFile);
            }
            if (countSpaces > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void doChanceCard(CardClass pickedCard)
        {
            int moneyOnCard = pickedCard.getCardValue();

            if (playerMoney + moneyOnCard <= 0)//if they dont have enough money after chance action
            {
                MessageBox.Show("You are out of money");
                getWinner();
            }
            else//performs chance action
            {
                playerMoney = playerMoney + moneyOnCard;
            }
        }
        public CardClass randomCard()
        {
            index = randomNumberCard();
            foreach (CardClass card in InternalList)
            {
                if (card.checkCardID(index) == true)
                {
                    return(card);
                }
            }
            CardClass cards = new CardClass();

            return(cards);
        }
Пример #4
0
        public Boolean checkCardID(int ID) //to get space in list for SpaceListClass
        {
            CardClass card = this;         //object

            if (ID == card.cardId)
            {
                //cards attributes
                cardId    = card.cardId;
                cardText  = card.cardText;
                cardValue = card.cardValue;

                return(true);
            }

            else
            {
                return(false);
            }
        }
Пример #5
0
        public Boolean createCardObject(string c) //creates card objects from text file
        {
            CardClass card = this;                //creates object

            string[] cardString = c.Split('*');   //splits object into seperate text for conversion of attributes

            int cardStringSize = cardString.GetLength(0);

            for (int i = 0; i < cardStringSize; i++)//loops thru cards
            {
                cardString[i] = cardString[i].Trim();
            }
            if (cardString[0].Length > 1)//for card id
            {
                MessageBox.Show("incorrect length");
                return(false);
            }
            try
            {
                cardId = Convert.ToInt32(cardString[0]); //tries to convert
            }
            catch                                        //catches if not a number
            {
                MessageBox.Show("not a number");
                return(false);
            }
            cardText = cardString[1];
            if (cardText == "" || cardText == " ")//makes sure there is some text
            {
                MessageBox.Show("Card has no text");
                return(false);
            }
            try
            {
                cardValue = Convert.ToInt32(cardString[2]);//tries ti cnvert  card value
            }
            catch
            {
                MessageBox.Show("Card Value Not Integer");
            }
            return(true);
        }
    public Boolean checkSpaceID(int ID) //to get space in list for SpaceListClass
    {
        SpaceClass space = this;        //for object

        if (ID == space.spaceId)        //for a space, get its spaceid
        {
            //gets evey attribute for object
            spaceId    = space.spaceId;
            rent       = space.rent;
            spaceType  = space.spaceType;
            spaceName  = space.spaceName;
            spaceColor = space.spaceColor;
            isOwned    = space.isOwned;
            MessageBox.Show(space.displaySpace());
            if (!isOwned && spaceType == "property")//checks for unowned properties
            {
                if (!MonopolyJr.MonopolyBoardGame.turn)
                {
                    MonopolyJr.MonopolyBoardGame.user.buyProperty(rent, space);
                    MonopolyJr.MonopolyBoardGame.turn = true;
                }
                else
                {
                    MonopolyJr.MonopolyBoardGame.player2.buyProperty(rent, space);
                    MonopolyJr.MonopolyBoardGame.turn = false;
                }
            }

            else if (spaceType == "chance")             //call find card, get random card instance == to random card call display
            {
                if (!MonopolyJr.MonopolyBoardGame.turn) //player1 turn
                {
                    //MonopolyJr.MonopolyBoardGame.user.userPayRent(rent, space);
                    MonopolyJr.CardClass chanceCard1 = MonopolyJr.MonopolyBoardGame.cardList.randomCard();
                    MessageBox.Show(chanceCard1.displayCard());
                    MonopolyJr.MonopolyBoardGame.user.doChanceCard(chanceCard1);
                    MonopolyJr.MonopolyBoardGame.turn = true;
                }
                else
                {
                    //MonopolyJr.MonopolyBoardGame.player2.player2PayRent(rent, space);
                    MonopolyJr.CardClass chanceCard2 = MonopolyJr.MonopolyBoardGame.cardList.randomCard();
                    MessageBox.Show(chanceCard2.displayCard());
                    MonopolyJr.MonopolyBoardGame.player2.doChanceCard(chanceCard2);
                    MonopolyJr.MonopolyBoardGame.turn = false;
                }
            }

            else if (isOwned && spaceType == "property")     //this handles owned prop
            {
                MessageBox.Show("Somebody owns this space"); //this is where you will pay others
                if (!MonopolyJr.MonopolyBoardGame.turn)      //player1 turn
                {
                    MonopolyJr.MonopolyBoardGame.user.userPayRent(rent, space);
                    MonopolyJr.MonopolyBoardGame.turn = true;
                }
                else
                {
                    //player 2 turn
                    MonopolyJr.MonopolyBoardGame.player2.player2PayRent(rent, space);
                    MonopolyJr.MonopolyBoardGame.turn = false;
                }
            }
            else
            {
                if (!MonopolyJr.MonopolyBoardGame.turn)
                {
                    MonopolyJr.MonopolyBoardGame.turn = true;
                }
                else
                {
                    MonopolyJr.MonopolyBoardGame.turn = false;
                }
            }
            return(true);
        }

        else
        {
            return(false);
        }
    }