Beispiel #1
0
        internal void addPoints(Railroad road)
        {
            int lenghtOfTrack = road.getRailLength();

            switch (lenghtOfTrack)
            {
            case 1:
                points += 1;
                break;

            case 2:
                points += 2;
                break;

            case 3:
                points += 4;
                break;

            case 4:
                points += 7;
                break;

            case 6:
                points += 15;
                break;

            case 8:
                points += 21;
                break;

            default:
                Program.logboek.WriteLine("you can't add a track of this lenght");
                break;
            }
        }
Beispiel #2
0
        public static bool Pickcards(Player player, Railroad road)
        {
            Dictionary <TrainCard, int> traincards = player.GetTraincards();
            {
                int               amountOfLocomotives = road.getAmountOfLocomotives();
                int               railLength          = road.getRailLength() - amountOfLocomotives;
                Color             kleur     = road.getColor();
                bool              hasCard   = false;
                int /*temp = 0,*/ maxamount = 0;
                Console.WriteLine("this track needs {0} locomotives", amountOfLocomotives);
                if (amountOfLocomotives > 0)
                {
                    foreach (KeyValuePair <TrainCard, int> playercard in traincards)        // met index werken?
                    {
                        if (playercard.Key.getColor() == Color.Locomotief)
                        {
                            hasCard = true;
                            if (playercard.Value >= amountOfLocomotives)
                            {
                                Console.WriteLine("you have enough locomotives");
                                player.GetTraincards()[playercard.Key] -= amountOfLocomotives;
                                TrainCard card = playercard.Key;
                                for (int i = 0; i < amountOfLocomotives; i++)
                                {
                                    usedCardsDeck.Add(card);
                                }
                                break;
                            }
                            else
                            {
                                Console.WriteLine("you don't have enough locomotives to make the track");
                                if (!(player is IntelligentPlayer))
                                {
                                    MessageBox.Show("you don't have enough locomotives to make the track");
                                }
                                return(false);
                            }
                        }
                    }
                    if (!hasCard)
                    {
                        Console.WriteLine("you dont have any locomotives");
                        if (!(player is IntelligentPlayer))
                        {
                            MessageBox.Show("you don't have enough locomotives to make the track");
                        }
                        return(false);
                    }
                }


                // de maximumwaarde wordt gezocht
                int amountLoco = 0;
                foreach (KeyValuePair <TrainCard, int> card in traincards)
                {
                    if (card.Value > maxamount && card.Key.getColor() != Color.Locomotief)
                    {
                        maxamount = card.Value;
                    }
                    else if (card.Key.getColor() == Color.Locomotief)
                    {
                        amountLoco = card.Value;
                    }
                }
                maxamount += amountLoco;

                if (railLength > 0)
                {
                    if (railLength <= maxamount)
                    {
                        bool colorfound = false;
                        if (kleur == Color.Grijs)
                        {
                            TrainCard traincard = null;
                            Console.WriteLine("Please chose a color");
                            //bool firsttime = true;
                            string a = null;
                            Dictionary <TrainCard, int> possibleCard = goodCards(player, railLength);
                            /*misschien beter een dictionary van object int maken*/
                            Dictionary <string, int> possiblities = new Dictionary <string, int>();
                            foreach (KeyValuePair <TrainCard, int> de in possibleCard)
                            {
                                a += "\t" + de.Key.ToString();
                                possiblities.Add(de.Key.ToString(), (int)de.Key.getColor());
                            }
                            Console.WriteLine(a);
                            if (!(player is IntelligentPlayer))
                            {
                                int val = GetInput(possiblities, player);
                                traincard = new TrainCard((Color)val);
                            }
                            else
                            {
                                traincard = new TrainCard((Color)possiblities.Values.ToList()[0]);
                                // sorry, heb hiervoor geen intelligentie meer geïmplementeerd
                            }
                            foreach (KeyValuePair <TrainCard, int> card in traincards)
                            {
                                if (card.Key.getColor() == traincard.getColor())
                                {
                                    if (railLength > card.Value)
                                    {
                                        int temp = card.Value;
                                        railLength -= temp;
                                        TrainCard tCard = card.Key;
                                        for (int i = 0; i < temp; i++)
                                        {
                                            usedCardsDeck.Add(tCard);
                                        }
                                        traincards[card.Key] = 0;
                                        foreach (KeyValuePair <TrainCard, int> trCard in traincards)
                                        {
                                            if (trCard.Key.getColor() == Color.Locomotief)
                                            {
                                                traincards[trCard.Key] -= railLength;
                                                tCard = trCard.Key;
                                                for (int i = 0; i < railLength; i++)
                                                {
                                                    usedCardsDeck.Add(tCard);
                                                }
                                                return(true);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        traincards[card.Key] -= railLength;
                                        traincard             = card.Key;
                                        for (int i = 0; i < railLength; i++)
                                        {
                                            usedCardsDeck.Add(traincard);
                                        }
                                        return(true);
                                    }
                                }
                            }
                        }

                        else
                        {
                            // indien de kleur van het spoort vasligt
                            foreach (KeyValuePair <TrainCard, int> card in traincards)
                            {
                                if (card.Key.getColor() == kleur)
                                {
                                    colorfound = true;
                                    // indien je voldoende kaarten hebt van die kleur (zonder locomotieven bij te leggen)
                                    if (card.Value >= railLength)
                                    {
                                        traincards[card.Key] -= railLength;
                                        player.addRailroad(road);
                                        TrainCard trCard = card.Key;
                                        for (int i = 0; i < railLength; i++)
                                        {
                                            usedCardsDeck.Add(trCard);
                                        }
                                        return(true);
                                    }
                                    else
                                    {
                                        foreach (KeyValuePair <TrainCard, int> pair in traincards)
                                        {
                                            if (pair.Key.getColor() == Color.Locomotief)
                                            {
                                                int val = traincards[card.Key];
                                                traincards[card.Key]  = 0;
                                                traincards[pair.Key] -= (railLength - val);
                                                TrainCard trCard = card.Key;
                                                for (int i = 0; i < railLength - val; i++)
                                                {
                                                    usedCardsDeck.Add(trCard);
                                                }
                                                return(true);
                                            }
                                        }
                                    }
                                }
                                else if (amountLoco >= railLength)
                                {
                                    foreach (KeyValuePair <TrainCard, int> pair in traincards)
                                    {
                                        if (pair.Key.getColor() == Color.Locomotief)
                                        {
                                            traincards[pair.Key] -= (railLength);
                                            TrainCard trCard = pair.Key;
                                            for (int i = 0; i < railLength; i++)
                                            {
                                                usedCardsDeck.Add(trCard);
                                            }
                                            return(true);
                                        }
                                    }
                                }
                            }
                            return(false);

                            if (!colorfound)
                            {
                                if (amountLoco >= railLength)
                                {
                                    foreach (KeyValuePair <TrainCard, int> card in traincards)
                                    {
                                        traincards[card.Key] -= amountLoco;
                                        TrainCard trCard = card.Key;
                                        for (int i = 0; i < railLength; i++)
                                        {
                                            usedCardsDeck.Add(trCard);
                                        }
                                        return(true);
                                    }
                                }
                                Console.WriteLine("U heeft geen kaarten van dit type kleur");
                                if (!(player is IntelligentPlayer))
                                {
                                    MessageBox.Show("you dont have any cards of this type color");
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("you dont have enough cards of the same type to build the track");
                        if (!(player is IntelligentPlayer))
                        {
                            MessageBox.Show("you dont have enough cards of the same type to build the track");
                        }
                    }
                }
                else
                {
                    player.addRailroad(road);
                    Console.WriteLine("The railroad {0} was successfully added", road.ToString());
                    ExtensionMethods.WaitForUser();
                    return(true);
                }
                //ExtensionMethods.WaitForUser();
                returnLocomotives(traincards, amountOfLocomotives);
                return(false);
            }
        }
Beispiel #3
0
 public void addRailroad(Railroad track)
 {
     track.setOccupied(this);
     amountOfTrains -= track.getRailLength();
     network.Add(track);
 }