Ejemplo n.º 1
0
        private void CurrentPlayerBuyACard()
        {
            if (Players[currentPlayerIndex].CityHall && Players[currentPlayerIndex].Money == 0)
            {
                Players[currentPlayerIndex].Money += 1;
            }

            Card   cardPicked;
            Card   cardToBuy = null;
            string cardtype;

            do
            {
                Type CardType;
                do
                {
                    Console.WriteLine(Players[currentPlayerIndex].Name + ", you have " + Players[currentPlayerIndex].Money + " coins, please type in the card name that you want to buy:");
                    cardtype = Console.ReadLine();
                    CardType = Type.GetType("MachiKoro." + cardtype);

                    if (CardType == null)
                    {
                        Console.WriteLine(cardtype + " is not a valid card.");
                    }
                }while (CardType == null);

                var firstConstructor = CardType.GetConstructors()[0];

                cardPicked = (Card)(Activator.CreateInstance(CardType));
                if (Players[currentPlayerIndex].Money >= cardPicked.Cost)
                {
                    cardToBuy = cardPicked;
                }
                else
                {
                    Console.WriteLine(Players[currentPlayerIndex].Name + ", You don't have enough money to buy this card.");
                }
            }while(cardToBuy == null);

            Players[currentPlayerIndex].Money = Players[currentPlayerIndex].Money - cardToBuy.Cost;
            if (cardtype != "E")
            {
                Players[currentPlayerIndex].Cards.Add(cardToBuy);
            }
            switch (cardtype)
            {
            case "Y2":
                Players[currentPlayerIndex].Harbor = true;
                Players[currentPlayerIndex].LandmarkCount++;
                break;

            case "Y30":
                Players[currentPlayerIndex].Airport = true;
                Players[currentPlayerIndex].LandmarkCount++;
                break;

            case "Y10":
                Players[currentPlayerIndex].ShoppingMall = true;
                Players[currentPlayerIndex].LandmarkCount++;
                break;

            case "Y16":
                Players[currentPlayerIndex].AmusementPark = true;
                Players[currentPlayerIndex].LandmarkCount++;
                break;

            case "Y4":
                Players[currentPlayerIndex].TrainStation = true;
                Players[currentPlayerIndex].LandmarkCount++;
                break;

            case "Y22":
                Players[currentPlayerIndex].RadioTower = true;
                Players[currentPlayerIndex].LandmarkCount++;
                break;

            default:
                break;
            }
        }