Exemple #1
0
        static ListPlayer CreatePlayers(int nb_pl)
        {
            Console.WriteLine("Enter the name of player 0");
            string     name = Console.ReadLine();
            Player     p    = new Player(name);
            ListPlayer LiPl = new ListPlayer(p);

            Console.WriteLine(p);
            for (int i = 1; i < nb_pl; i++)
            {
                Console.WriteLine("Enter the name of player " + i);
                name = Console.ReadLine();
                p    = new Player(name);
                LiPl.AddTail(p);
                Console.WriteLine(p);
            }
            Console.WriteLine("Enter the position of the player who will be banker : ");
            int pos = Convert.ToInt32(Console.ReadLine());

            while (pos < 0 || pos >= nb_pl)
            {
                Console.WriteLine("Please enter a correct value ");
                Console.WriteLine("The position should be between 0 and " + (nb_pl - 1));
                pos = Convert.ToInt32(Console.ReadLine());
            }

            Banker ban = Banker.GetInstance(LiPl.getPlayer(pos));

            LiPl.getPlayer(nb_pl - 1).next = LiPl.getPlayer(0);
            return(LiPl);
        }
Exemple #2
0
        public string getInformationPnumber(ListPlayer P)
        {
            Console.WriteLine("Enter the number of the player whom you want to have information : ");
            int pos_sp = Convert.ToInt32(Console.ReadLine());

            return(P.getPlayer(pos_sp).ToString());
        }
Exemple #3
0
        public void getInformationP(ListPlayer P)
        {
            Console.WriteLine("\nSpaces Informations");
            Console.WriteLine("-----------------\n\n");
            bool   end     = false;
            bool   valid   = true;
            string lecture = "";

            do
            {
                end = false;
                Console.WriteLine();
                Console.WriteLine("1 : Player informations by name");
                Console.WriteLine("2 : Player informations by number");
                Console.WriteLine("3 : Leave the player information option");

                do
                {
                    lecture = "";
                    valid   = true;

                    Console.Write("\n Choose an action : ");
                    lecture = Console.ReadLine();
                    Console.WriteLine(lecture);
                    if (lecture == "" || !"123".Contains(lecture[0]))
                    {
                        Console.WriteLine("Your choice <" + lecture + "> is not valid = > Please choose a correct action. ");
                        valid = false;
                    }
                } while (!valid);


                switch (lecture[0])
                {
                case '1':
                    Console.Clear();
                    Console.WriteLine(getInformationPname(P));
                    break;

                case '2':
                    Console.Clear();
                    Console.WriteLine(getInformationPnumber(P));
                    break;

                case '3':
                    Console.Clear();
                    Console.WriteLine("You leave this optionnality");
                    Console.ReadKey();
                    end = true;
                    break;

                default:
                    Console.WriteLine("\n Please choose a correct action.");
                    break;
                }
            } while (!end);
        }
Exemple #4
0
 public void buySpace(ListSpaces B, ListPlayer P)
 {
     if (B.getSpace(position) is Propriety)
     {
         Propriety prop = (Propriety)B.getSpace(position);
         if (prop.possessed)
         {
             Console.WriteLine("This propriety is already possessed by " + prop.pl.name + ", you can't buy it.");
         }
         else
         {
             Console.WriteLine("Do you want to buy this propriety ? ");
             Console.WriteLine("Press 1 for yes or 0 for no. ");
             int resp = Convert.ToInt32(Console.ReadLine());
             while (resp != 0 && resp != 1)
             {
                 Console.WriteLine("Please enter a correct awnser.");
                 Console.WriteLine("Press 1 for yes or 0 for no. ");
                 resp = Convert.ToInt32(Console.ReadLine());
             }
             if (resp == 1)
             {
                 int pri = prop.price;
                 if (account > prop.price)
                 {
                     prop.possessed = true;
                     prop.pl        = this;
                     account        = account - prop.price;
                     B.changeSpace(position, prop);
                     if (list_pr == null)
                     {
                         prop      = (Propriety)B.getSpace(position).Shallowcopy();
                         prop.next = null;
                         list_pr   = new ListSpaces(prop);
                     }
                     else
                     {
                         prop      = (Propriety)B.getSpace(position).Shallowcopy();
                         prop.next = null;
                         list_pr.AddTail(prop);
                     }
                     Console.WriteLine("You have acquired " + prop.name);
                 }
                 else
                 {
                     Console.WriteLine("You don't have enough money in your bank account to buy this propriety ! ");
                 }
             }
         }
     }
     else
     {
         Console.WriteLine("You can't buy this space, this is not a propriety.");
     }
 }
Exemple #5
0
        public void playSpecialSpace(ListSpaces B, ListPlayer P, Queue <SpecialCards> Chance, Queue <SpecialCards> CommunityChest)
        {
            SpecialSpace sp = (SpecialSpace)B.getSpace(position);

            if (sp.go_to_prison)
            {
                Console.WriteLine("Go to prison !");
                Console.WriteLine("You will not receive your 200 if you pas by the Start");
                goToPrison();
            }
            if (sp.tax)
            {
                Console.WriteLine("Pay a tax of 100 euros");
                SpecialSpace park = (SpecialSpace)B.getSpace(20);
                park.money_in_parking += 100;
                account -= 100;
                Console.WriteLine("The money will go to the Public Parking (position 20)");
                Console.WriteLine("The actual amount of money in the parking is : " + park.money_in_parking);
            }
            if (sp.luxe_tax)
            {
                Console.WriteLine("Pay a tax of 200 euros");
                SpecialSpace park = (SpecialSpace)B.getSpace(20);
                park.money_in_parking += 200;
                account -= 200;
                Console.WriteLine("The money will go to the Public Parking (position 20)");
                Console.WriteLine("The actual amount of money in the parking is : " + park.money_in_parking);
            }
            if (sp.chance)
            {
                Console.WriteLine("Press enter to pull a chance card");
                Console.ReadLine();
                SpecialCards cha = Chance.Dequeue();
                Console.WriteLine(cha.SpecialCardAction(this, P, B));
                Chance.Enqueue(cha);
            }
            if (sp.community_chest)
            {
                Console.WriteLine("Press enter to pull a community chest card");
                Console.ReadLine();
                SpecialCards cc = CommunityChest.Dequeue();
                Console.WriteLine(cc.SpecialCardAction(this, P, B));
                Chance.Enqueue(cc);
            }
        }
Exemple #6
0
        public string getInformationPname(ListPlayer P)
        {
            Console.WriteLine("Enter the name of the player whom you want to have information: ");
            string n   = Console.ReadLine();
            int    pos = 0;

            while (!(P.onList(n)))
            {
                Console.WriteLine("This player is not playing in this game !");
                Console.WriteLine("Please write a correct name.");
                Console.WriteLine("If you want to leave, press 'z'");
                n = Console.ReadLine();
                if (n == "z")
                {
                    return(null);
                }
            }
            return("Here is all the informations about this player \n" + P.getPlayerByName(n));
        }
Exemple #7
0
        public void outOfPrison(ListSpaces B, ListPlayer P)
        {
            Console.WriteLine("You're on prison !");
            Console.WriteLine("Press enter to roll dices");
            Console.ReadLine();
            Random rd          = new Random();
            int    first_dice  = rd.Next(1, 7);
            int    second_dice = rd.Next(1, 7);

            Console.WriteLine("The value of the first dice is : " + first_dice);
            Console.WriteLine("The value of the second dice is : " + second_dice);
            if (first_dice == second_dice)
            {
                Console.WriteLine("You're out of prison !");
                position = position + 2 * first_dice;
                recalculatePosition();
                Console.WriteLine("You are now in the space number : " + position);
                Console.WriteLine(B.getSpace(position));
                Console.WriteLine(" You've turned the dices, make an action.");
                in_prison      = false;
                time_in_prison = 0;
                makeAction(B, P);
            }
            else
            {
                time_in_prison++;
                if (time_in_prison >= 3)
                {
                    Console.WriteLine("You're out of prison !");
                    in_prison      = false;
                    time_in_prison = 0;
                    Console.WriteLine("You will play on your next turn.");
                }
                else
                {
                    Console.WriteLine("Sorry, you will still in prison for " + (3 - time_in_prison) + "turns ...");
                }
            }
            Console.ReadLine();
        }
Exemple #8
0
        static void Game(ListSpaces l_s, ListPlayer l_p, Player p, int size, Queue <SpecialCards> Chance, Queue <SpecialCards> CommunityChest)
        {
            while (p.next != p)
            {
                Console.Clear();
                Console.WriteLine(p);
                Console.WriteLine("This is your turn to play !");

                if (p.in_prison)
                {
                    p.outOfPrison(l_s, l_p);
                }
                else
                {
                    p.rollDice(l_s, l_p, Chance, CommunityChest);
                    if (l_s.getSpace(p.position) is SpecialSpace)
                    {
                        p.playSpecialSpace(l_s, l_p, Chance, CommunityChest);
                    }
                    if (p.passByStart(p.position))
                    {
                        Console.WriteLine("Collect your 200 euros for completing a tour ");
                        p.account += 200;
                        Console.WriteLine("Your account is now : " + p.account);
                    }
                    p.recalculatePosition();
                    p.makeAction(l_s, l_p);
                }
                if (p.bankruptcy())
                {
                    Console.WriteLine(p.name + ", you're in bankruptcy, you're out of the game!");
                    int pos_del = l_p.getPlayerPosition(p, size);
                    l_p.deletePlayer(pos_del);
                    size = size - 1;
                }
                p = p.next;
            }
            Console.WriteLine("This game is over !");
            Console.WriteLine("Bravo " + p.name + " you won this game !");
        }
Exemple #9
0
        static void Main(string[] args)
        {
            // -------------------------Intialization-------------------------------------------------------
            ListSpaces Board = CreateBoard();

            Console.WriteLine("How many players will play this game ? ");
            Console.WriteLine("Please enter a number : ");
            int number_players = Convert.ToInt32(Console.ReadLine());

            while (number_players < 2)
            {
                Console.WriteLine("At least two players needed to start a game ! ");
                Console.WriteLine("How many players will play this game ? ");
                Console.WriteLine("Please enter a number : ");
                number_players = Convert.ToInt32(Console.ReadLine());
            }
            ListPlayer           List_of_players = CreatePlayers(number_players);
            Queue <SpecialCards> cc  = CreateChanceQueue();
            Queue <SpecialCards> ccc = CreateCommunityChestQueue();

            // ----------------------------------------------------------------------------------------------
            Game(Board, List_of_players, List_of_players.getPlayer(0), number_players, cc, ccc);
            Console.ReadLine();
        }
 public ListPlayerIterator(ListPlayer l)
 {
     list = l;
     current_player_idx = -1;
 }
Exemple #11
0
        public void makeAction(ListSpaces B, ListPlayer P)
        {
            bool   fin     = false;
            bool   valid   = true;
            string lecture = "";

            do
            {
                Console.WriteLine("\nPlayer Action");
                Console.WriteLine("\n Turn of " + name);
                Console.WriteLine("-----------------\n\n");
                fin = false;
                Console.WriteLine();
                Console.WriteLine("1 : Buy this propiety");
                Console.WriteLine("2 : Buy a house or an hotel");
                Console.WriteLine("3 : Get informations");
                Console.WriteLine("4 : Pass your turn");

                do
                {
                    lecture = "";
                    valid   = true;

                    Console.Write("\n Choose an action : ");
                    lecture = Console.ReadLine();
                    Console.WriteLine(lecture);
                    if (lecture == "" || !"1234".Contains(lecture[0]))
                    {
                        Console.WriteLine("Your choice <" + lecture + "> is not valid = > Please choose a correct action. ");
                        valid = false;
                    }
                } while (!valid);


                switch (lecture[0])
                {
                case '1':
                    Console.Clear();
                    buySpace(B, P);
                    break;

                case '2':
                    Console.Clear();
                    buyH(B);
                    break;

                case '3':
                    Console.Clear();
                    getInformation(B, P);
                    break;

                case '4':
                    Console.Clear();
                    Console.WriteLine("You pass your turn");
                    if (B.getSpace(position) is Propriety)
                    {
                        Propriety prop = (Propriety)B.getSpace(position);
                        if (!(prop.possessed))
                        {
                            Console.WriteLine("This propriety will be auctionned");
                            Player pla = prop.auction(P);
                            prop.possessed = true;
                            prop.pl        = pla;
                            B.changeSpace(position, prop);
                            if (pla.list_pr == null)
                            {
                                prop        = (Propriety)B.getSpace(position).Shallowcopy();
                                prop.next   = null;
                                pla.list_pr = new ListSpaces(prop);
                            }
                            else
                            {
                                prop      = (Propriety)B.getSpace(position).Shallowcopy();
                                prop.next = null;
                                pla.list_pr.AddTail(prop);
                            }
                        }
                    }
                    Console.ReadKey();
                    fin = true;
                    break;

                default:
                    Console.WriteLine("\n Please choose a correct action.");
                    break;
                }
            } while (!fin);
        }
Exemple #12
0
        public string rollDice(ListSpaces B, ListPlayer P, Queue <SpecialCards> Chance, Queue <SpecialCards> CommunityChest)
        {
            int count = 0;

            Console.WriteLine("Press enter to roll dices");
            Console.ReadLine();
            Random rd          = new Random();
            int    first_dice  = rd.Next(1, 7);
            int    second_dice = rd.Next(1, 7);

            Console.WriteLine("The value of the first dice is : " + first_dice);
            Console.WriteLine("The value of the second dice is : " + second_dice);
            while (first_dice == second_dice)
            {
                count++;
                if (count == 3)
                {
                    goToPrison();
                    return("You're probably cheating, go to prison !");
                }
                position = position + 2 * first_dice;
                if (passByStart(position))
                {
                    Console.WriteLine("Collect your 200 euros for completing a tour ");
                    account += 200;
                    Console.WriteLine("Your account is now : " + account);
                }
                recalculatePosition();
                Console.WriteLine("You are now in the space number : " + position);
                Console.WriteLine(B.getSpace(position).name);
                payRent(B, first_dice + second_dice);
                if (B.getSpace(position) is SpecialSpace)
                {
                    playSpecialSpace(B, P, Chance, CommunityChest);
                }
                if (passByStart(position))
                {
                    Console.WriteLine("Collect your 200 euros for completing a tour ");
                    account += 200;
                    Console.WriteLine("Your account is now : " + account);
                }
                recalculatePosition();
                makeAction(B, P);
                Console.WriteLine("You made a double, you can play again !");
                Console.WriteLine("Press enter to roll dices again");
                Console.ReadLine();
                first_dice  = rd.Next(1, 7);
                second_dice = rd.Next(1, 7);
                Console.WriteLine("The value of the first dice is : " + first_dice);
                Console.WriteLine("The value of the second dice is : " + second_dice);
            }
            int total = first_dice + second_dice;

            position = position + total;

            if (passByStart(position))
            {
                Console.WriteLine("Collect your 200 euros for completing a tour ");
                account += 200;
                Console.WriteLine("Your account is now : " + account);
            }
            recalculatePosition();
            payRent(B, total);
            Console.WriteLine("You are now in the space number : " + position);
            Console.WriteLine(B.getSpace(position).name);
            return(" You've turned the dices, make an action.");
        }
Exemple #13
0
        public Player auction(ListPlayer P)
        {
            Console.Clear();
            Player pla = P.getPlayer(0);

            Console.WriteLine("This auction starts");
            Console.WriteLine("The propriety to buy is " + name);
            int    amount = 0;
            int    res    = 10;
            string n      = "";

            while (n != pla.name)
            {
                if (!(pla.in_prison))
                {
                    Console.WriteLine(pla.name + " this is you turn to auction");
                    Console.WriteLine("Do you want to bid for this propriety : " + name + " ?");
                    Console.WriteLine("The current bid is " + amount);
                    Console.WriteLine("Press 1 for yes, 0 for no");
                    res = Convert.ToInt32(Console.ReadLine());
                    while (res != 0 && res != 1)
                    {
                        Console.WriteLine("Please enter a correct awnser.");
                        Console.WriteLine("Press 1 for yes or 0 for no. ");
                        res = Convert.ToInt32(Console.ReadLine());
                    }
                    if (res == 1)
                    {
                        int  am         = 0;
                        bool bid_placed = false;
                        while (!(bid_placed) && am != 9999)
                        {
                            Console.WriteLine("Enter the amount of your bid :");
                            am = Convert.ToInt32(Console.ReadLine());
                            if (am > amount)
                            {
                                if (am <= pla.account)
                                {
                                    Console.WriteLine("You place your bid for this propriety !");
                                    amount     = am;
                                    bid_placed = true;
                                    n          = pla.name;
                                }
                                else
                                {
                                    Console.WriteLine("You don't have enough money in your account !");
                                    Console.WriteLine("Press 9999 to cancel your bid");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Your bid is lower than the current amount !");
                                Console.WriteLine("The current bid is " + amount);
                                Console.WriteLine("Press 9999 to cancel your bid");
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine(pla.name + ", you can't play be in this action because you're in prison !");
                }
                pla = pla.next;
            }
            Console.WriteLine(pla.name + " won this auction");
            Console.WriteLine("He bought " + name + " for " + amount + " euros.");
            pla.account = pla.account - amount;
            return(pla);
        }