예제 #1
0
 public void Constructor()
 {
     Assert.AreEqual("RxR", railroad.ToString());
     Assert.AreEqual(0, railroad.RailroadCount);
     Assert.AreEqual(200, railroad.Price);
     Assert.IsFalse(railroad.Mortgaged);
 }
예제 #2
0
파일: Actions.cs 프로젝트: jonasvdd/T2R
        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);
            }
        }
예제 #3
0
파일: Actions.cs 프로젝트: jonasvdd/T2R
        }       // done

        public static bool BuildRailRoad(Player player, List <City> cities, List <Railroad> totalNetwork)
        {
            citylist = cities;
            City city1, city2;
            int  val = 0;

            network = totalNetwork;
            string text = null;

            if (!(player is IntelligentPlayer))
            {
                foreach (City city in cities)
                {
                    text += (city.getname() + "\t");
                }
            }

            Console.WriteLine("Choose between which 2 Cities you want to add an track (give in 1 city at a time) +\n" + text);

            //getting input from console
            if (!(player is IntelligentPlayer))
            {
                val   = player.ChoseOption(Possibilities.Railroad);
                city1 = getCity(val);
                val   = player.ChoseOption(Possibilities.Neighbours);
                city2 = getCity(val);
                if (city1 != city2)
                {
                    if (city1.getNeighBours().Contains(city2))
                    {
                        List <Railroad> possibleRoads = new List <Railroad>();
                        // alle mogelijke tracks tussen de 2 steden
                        Railroad track = null;

                        foreach (Railroad road in totalNetwork)
                        {
                            if (road.getdestinations().Contains(city1) && road.getdestinations().Contains(city2))
                            {
                                if (!possibleRoads.Contains(road))  // heb er per ongeluk sommige steden dubbel toegevoegd, heb dit ontdekt bij het debuggen van de code
                                                                    // een testgeoriënteerd ontwerp (met testklassen) zou hier zeker van pas komen
                                {
                                    track = road;
                                    possibleRoads.Add(road);
                                }
                            }
                        }

                        if (possibleRoads.Count > 1)    // bij parallelle steden
                        {
                            Dictionary <string, int> roundOptions = new Dictionary <string, int>();
                            Program.logboek.WriteLine("er is meer dan 1 mogelijkheid");
                            //roundOptions.Clear();
                            foreach (Railroad road in possibleRoads)
                            {
                                roundOptions.Add(Convert.ToString(road.getColor()), (int)road.getColor());
                            }

                            val = GetInput(roundOptions, player);
                            foreach (Railroad road in totalNetwork)
                            {
                                if (road.getdestinations().Contains(city1) && road.getdestinations().Contains(city2))
                                {
                                    if (road.getColor() == (Color)val)
                                    {
                                        track = road;
                                    }
                                    else
                                    {
                                        totalNetwork.Remove(road);
                                        break;
                                    }
                                }
                            }
                        }

                        Program.logboek.WriteLine("there is a track between the two cities");
                        Program.logboek.WriteLine(track.ToString());
                        bool succesful = Pickcards(player, track);
                        if (succesful)
                        {
                            player.addRailroad(track);
                            player.addPoints(track);
                            track.drawLine(player, Program.form.pictureBox1);
                        }
                        return(succesful);
                    }
                    else
                    {
                        Console.WriteLine("The cities you picked aren't neighbours");
                        if (!(player is IntelligentPlayer))
                        {
                            MessageBox.Show("the cities you picked aren't neighbours");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("You picked twice the same city");
                    if (!(player is IntelligentPlayer))
                    {
                        MessageBox.Show("you picked twice the same city");
                    }
                }
                return(false);
            }
            else
            {
                player.addRailroad(((IntelligentPlayer)player).Maderoad);
                player.addPoints(((IntelligentPlayer)player).Maderoad);
                ((IntelligentPlayer)player).Maderoad.drawLine(player, Program.form.pictureBox1);
                return(true);
            }
        }