Ejemplo n.º 1
0
        public static int RunMonopoly()
        {
            List <Joueur> players   = ShuffleListOfJoueur(CreateAllPlayers()); // create all the players
            Plateau       myPlateau = new Plateau(players);                    // initiate the plateau
            Random        rnd       = new Random();

            Console.Write("\nAppuyer sur une touche pour commencer..."); Console.ReadKey(); Console.Clear();

            while (InGamePlayer(players) > 1)
            {
                for (int index = 0; index < players.Count; index++)
                {
                    players[index].PreviousPosition = players[index].Position; players[index].PreviousMoney = players[index].Money;
                    if (players[index].IsInGame == true)
                    {
                        myPlateau.exitDoubleBoucle = false;
                        while (myPlateau.exitDoubleBoucle == false)
                        {
                            myPlateau.Des = new int[] { rnd.Next(1, 7), rnd.Next(1, 7) };
                            //myPlateau.Des = new int[] { 1, 1 }; ////test
                            DisplayInfoPreRound(myPlateau, players, index);
                            (myPlateau, players) = MoovePlayer(myPlateau, players, index);
                            DisplayMoveInfo(myPlateau, players, index);
                            (myPlateau, players) = InteractWithCurrentPosition(myPlateau, players, index); // interact with the player location.
                            if (myPlateau.Des[0] == myPlateau.Des[1] && myPlateau.DoublAmount < 3)
                            {
                                myPlateau.DoublAmount += 1;
                                Console.Write("\nVous avez fait un double. Appuyer sur une touche pour rejouer..."); Console.ReadKey(); Console.Clear();
                            }
                            else
                            {
                                myPlateau.DoublAmount      = 0;
                                myPlateau.exitDoubleBoucle = true;
                                Console.Write("\nAppuyer sur une touche pour terminer votre tour..."); Console.ReadKey(); Console.Clear();
                            }
                        }
                        //printMapStats(myPlateau, players);
                    }
                }
            }
            foreach (Joueur item in players)
            {
                if (item.IsInGame == true)
                {
                    Console.Clear(); Console.Write(item.Name + " A gagner la partie.Bravo !");
                }
            }
            Console.Write("\nAppuyer sur Q pour terminer le programme..."); for (ConsoleKeyInfo cki = Console.ReadKey(); cki.Key.ToString() != "Q"; cki = Console.ReadKey())
            {
                Console.Clear(); Console.Write("\nAppuyer sur Q pour terminer le programme...");
            }
            return(0);
        }
Ejemplo n.º 2
0
 public static (Plateau _myPlateau, List <Joueur> _players) MoovePlayer(Plateau myPlateau, List <Joueur> players, int index)
 {
     if (myPlateau.DoublAmount >= 3) // si trois double d'affilé on va en prison.
     {
         players[index].JailRemaining = 3;
         players[index].Position      = 10;
     }
     if (players[index].JailRemaining > 0 && myPlateau.Des[0] == myPlateau.Des[1])
     { // release prisoner if dices double.
         players[index].JailRemaining = 0;
     }
     if (players[index].JailRemaining <= 0 && myPlateau.DoublAmount < 3)
     { // move player only if he is not in jail
         players[index].Position += ((myPlateau.Des[0] + myPlateau.Des[1]));
         if (players[index].Position >= 40)
         { // give and display 200$ to player if he pass at the start
             players[index].Money   += 200;
             players[index].Position = players[index].Position % 40;
         }
     }
     return(myPlateau, players);
 }
Ejemplo n.º 3
0
 public static void DisplayInfoPostRound(Plateau myPlateau, List <Joueur> players, int index)
 {
     Console.WriteLine("------------------------------------------------------------------------------------------------------------");
     Console.WriteLine("Nouveau solde : " + players[index].Money + "$");
     if (players[index].IsInGame == true)
     {
         if (players[index].JailRemaining <= 0)
         {
             Console.WriteLine("Nouvelle position : " + myPlateau.Cases[players[index].Position].Name);
             if (myPlateau.Cases[players[index].Position].Owner == players[index].Name)
             {
                 Console.WriteLine("Vous etes chez vous.");
             }
             else if (myPlateau.Cases[players[index].Position].Owner == null)
             {
                 Console.WriteLine("Vous etes sur une cases n'apartenant a personne.");
             }
             else if (myPlateau.Cases[players[index].Position].Owner != null && myPlateau.Cases[players[index].Position].Owner != players[index].Name)
             {
                 Console.WriteLine("Vous etes chez : " + myPlateau.Cases[players[index].Position].Owner);
             }
         }
         else
         {
             Console.WriteLine("Nouvelle position : Prison");
         }
         if (players[index].JailRemaining < 0)
         {
             Console.WriteLine("Vous avez " + players[index].JailRemaining + " carte(s) libere de prison en stock");
         }
     }
     else
     {
         Console.WriteLine("Faillite. Vous etes elimine");
     }
     Console.WriteLine("------------------------------------------------------------------------------------------------------------");
 }
Ejemplo n.º 4
0
 public static void DisplayMoveInfo(Plateau myPlateau, List <Joueur> players, int index)
 {
     Console.WriteLine("Des : " + myPlateau.Des[0] + " & " + myPlateau.Des[1]);
     if (myPlateau.DoublAmount >= 3) // si trois double d'affilé on va en prison.
     {
         Console.WriteLine("vous avez fait trois double d'affile. Vous allez en prison.");
     }
     if (players[index].JailRemaining > 0 && myPlateau.Des[0] == myPlateau.Des[1] && myPlateau.DoublAmount < 3)
     { // release prisoner if dices double.
         Console.Write("Double. Libere de prison. ");
     }
     else if (players[index].JailRemaining > 0 && myPlateau.Des[0] != myPlateau.Des[1])
     { //say to the prisoners that he stay in jail for X more rounds
         Console.WriteLine("Bloque en prison, deplacement impossible. " + players[index].JailRemaining + " tour(s) restant.");
     }
     if (players[index].JailRemaining <= 0 && myPlateau.DoublAmount < 3)
     {     // move player only if he is not in jail
         if ((players[index].PreviousPosition + myPlateau.Des[0] + myPlateau.Des[1]) >= 40)
         { // give and display 200$ to player if he pass at the start
             Console.WriteLine("Passage par la case depart : +200$. ");
         }
         Console.WriteLine("Deplacement en : " + myPlateau.Cases[players[index].Position].Name);
     }  // display the player its new possition
 }
Ejemplo n.º 5
0
        public static (Plateau _myPlateau, List <Joueur> _players) InteractWithProperty(Plateau myPlateau, List <Joueur> players, int index)
        {
            bool EndOfWhile = false;

            while (EndOfWhile != true)
            {
                Console.Clear();
                DisplayInfoPreRound(myPlateau, players, index);
                DisplayMoveInfo(myPlateau, players, index);
                Console.WriteLine("Vous etes chez vous. que voulez vous faire : [A/B/C/D/Enter]");
                if (myPlateau.Cases[players[index].Position].House < 5 && myPlateau.Cases[players[index].Position].IsHypoteque == false && players[index].Money >= (myPlateau.Cases[players[index].Position].Corner * 50) && myPlateau.Cases[players[index].Position].Family != "gare" && myPlateau.Cases[players[index].Position].Family != "compagnie")
                {
                    Console.WriteLine("A : Acheter une ou plusieurs maisons/hotel (" + (myPlateau.Cases[players[index].Position].Corner * 50) + "$)");
                }
                if (myPlateau.Cases[players[index].Position].House > 0 && myPlateau.Cases[players[index].Position].IsHypoteque == false)
                {
                    Console.WriteLine("B : Vendre une maisons/hotel (" + (myPlateau.Cases[players[index].Position].Corner * 25) + "$)");
                }
                if (myPlateau.Cases[players[index].Position].IsHypoteque == false && myPlateau.Cases[players[index].Position].House == 0)
                {
                    Console.WriteLine("C : Hypotequer");
                }
                if (myPlateau.Cases[players[index].Position].IsHypoteque == true && players[index].Money >= (myPlateau.Cases[players[index].Position].Loyer[6] + Convert.ToInt32(myPlateau.Cases[players[index].Position].Loyer[6] * 0.1)))
                {
                    Console.WriteLine("D : Lever l'hypoteque");
                }
                Console.WriteLine("Enter : Ne rien faire");
                ConsoleKeyInfo cki = Console.ReadKey();
                switch (cki.Key.ToString())
                {
                case "Enter":
                    EndOfWhile = true;
                    break;

                case "A":     // acheter une maison
                    if (myPlateau.Cases[players[index].Position].House < 5 &&
                        myPlateau.Cases[players[index].Position].IsHypoteque == false &&
                        players[index].Money >= (myPlateau.Cases[players[index].Position].Corner * 50) &&
                        myPlateau.Cases[players[index].Position].Family != "gare" &&
                        myPlateau.Cases[players[index].Position].Family != "compagnie")
                    {
                        myPlateau.Cases[players[index].Position].House += 1;
                        players[index].Money -= (myPlateau.Cases[players[index].Position].Corner * 50);
                    }
                    break;

                case "B":     // vendre une maison
                    if (myPlateau.Cases[players[index].Position].House > 0 &&
                        myPlateau.Cases[players[index].Position].IsHypoteque == false)
                    {
                        myPlateau.Cases[players[index].Position].House -= 1;
                        players[index].Money += (myPlateau.Cases[players[index].Position].Corner * 25);
                    }
                    break;

                case "C":     //hypotequer
                    if (myPlateau.Cases[players[index].Position].IsHypoteque == false && myPlateau.Cases[players[index].Position].House == 0)
                    {
                        myPlateau.Cases[players[index].Position].IsHypoteque = true;
                        players[index].Money += myPlateau.Cases[players[index].Position].Loyer[6];     // ajoute la valeur de l'hypoteque
                    }
                    break;

                case "D":     // lever une hypoteque
                    if (myPlateau.Cases[players[index].Position].IsHypoteque == true &&
                        players[index].Money >= (myPlateau.Cases[players[index].Position].Loyer[6] + Convert.ToInt32(myPlateau.Cases[players[index].Position].Loyer[6] * 0.1)))
                    {
                        myPlateau.Cases[players[index].Position].IsHypoteque = false;
                        players[index].Money -= (myPlateau.Cases[players[index].Position].Loyer[6] + Convert.ToInt32(myPlateau.Cases[players[index].Position].Loyer[6] * 0.1));    // preleve la valeur de la levée d'hypoteque.
                    }
                    break;

                default:
                    break;
                }
            }
            return(myPlateau, players);
        }
Ejemplo n.º 6
0
        public static (Plateau _myPlateau, List <Joueur> _players) InteractWithCurrentPosition(Plateau myPlateau, List <Joueur> players, int index)
        {
            switch (myPlateau.Cases[players[index].Position].Type)
            {
            case "propriete":
                if (myPlateau.Cases[players[index].Position].IsByable == true && players[index].Money < myPlateau.Cases[players[index].Position].Price)     // chez personne & pas assez de sous pour acheter..
                {
                    Console.WriteLine("\nVous n'avez pas assez de sous pour acheter");
                }
                else if (myPlateau.Cases[players[index].Position].IsByable == true && players[index].Money >= myPlateau.Cases[players[index].Position].Price)     // chez personne & assez de sous pour acheter!
                {
                    Console.Write(myPlateau.Cases[players[index].Position].Name + " coute : " + myPlateau.Cases[players[index].Position].Price + "$. Acheter ?  [Enter/n]");
                    ConsoleKeyInfo cki = Console.ReadKey();

                    if (cki.Key.ToString() != "Enter")     // ne veux pas acheter
                    {
                        Console.WriteLine("Vous n'avez pas acheter :" + myPlateau.Cases[players[index].Position].Name);
                    }
                    else     // veux acheter
                    {
                        Console.WriteLine("Vous avez acheter : " + myPlateau.Cases[players[index].Position].Name);
                        players[index].Money     -= myPlateau.Cases[players[index].Position].Price;
                        players[index].OwnedPlace = players[index].OwnedPlace.Concat(new int[] { players[index].Position }).ToArray();
                        myPlateau.Cases[players[index].Position].Owner    = players[index].Name;
                        myPlateau.Cases[players[index].Position].IsByable = false;
                    }
                }
                else if (myPlateau.Cases[players[index].Position].IsByable == false && myPlateau.Cases[players[index].Position].Owner != players[index].Name)
                {    // chez quelqun d'autre
                    if (myPlateau.Cases[players[index].Position].IsHypoteque == true)
                    {
                        Console.WriteLine("La propriete est hypotequee, vous ne payez pas de loyer.");
                    }
                    else
                    {
                        if (myPlateau.Cases[players[index].Position].Family == "gare")
                        {
                            int nbrOfGare = 0;
                            foreach (Propriete caseI in myPlateau.Cases)
                            {
                                if (caseI.Family == "gare" && caseI.Owner == myPlateau.Cases[players[index].Position].Owner)
                                {
                                    nbrOfGare++;
                                }
                            }
                            players[index].Money -= myPlateau.Cases[players[index].Position].Loyer[nbrOfGare];     // prend le loyé au locataire
                            int destLoyer = players.FindIndex(a => a.Name == myPlateau.Cases[players[index].Position].Owner);
                            players[destLoyer].Money += myPlateau.Cases[players[index].Position].Loyer[nbrOfGare]; //done le loyé au proprio
                            Console.WriteLine("vous donnez " + myPlateau.Cases[players[index].Position].Loyer[nbrOfGare] + "$ a " + myPlateau.Cases[players[index].Position].Owner + " car il possede " + nbrOfGare + " gare(s)");
                        }
                        else if (myPlateau.Cases[players[index].Position].Family == "compagnie")
                        {
                            int nbrOfCompagnie = 0;
                            foreach (Propriete caseI in myPlateau.Cases)
                            {
                                if (caseI.Family == "gare" && caseI.Owner == myPlateau.Cases[players[index].Position].Owner)
                                {
                                    nbrOfCompagnie++;
                                }
                            }
                            if (nbrOfCompagnie == 1)
                            {
                                players[index].Money -= (myPlateau.Des[0] + myPlateau.Des[1]) * 4;     // prend le loyé au locataire
                                int destLoyer = players.FindIndex(a => a.Name == myPlateau.Cases[players[index].Position].Owner);
                                players[destLoyer].Money += (myPlateau.Des[0] + myPlateau.Des[1]) * 4; //done le loyé au proprio
                                Console.WriteLine("vous donnez " + ((myPlateau.Des[0] + myPlateau.Des[1]) * 4) + "$ a " + myPlateau.Cases[players[index].Position].Owner + " car il possede 1 compagnie");
                            }
                            if (nbrOfCompagnie == 2)
                            {
                                players[index].Money -= (myPlateau.Des[0] + myPlateau.Des[1]) * 10;     // prend le loyé au locataire
                                int destLoyer = players.FindIndex(a => a.Name == myPlateau.Cases[players[index].Position].Owner);
                                players[destLoyer].Money += (myPlateau.Des[0] + myPlateau.Des[1]) * 10; //done le loyé au proprio
                                Console.WriteLine("vous donnez " + ((myPlateau.Des[0] + myPlateau.Des[1]) * 10) + "$ a " + myPlateau.Cases[players[index].Position].Owner + " car il possede 2 compagnies");
                            }
                        }
                        else
                        {
                            players[index].Money -= myPlateau.Cases[players[index].Position].Loyer[myPlateau.Cases[players[index].Position].House];     // prend le loyé au locataire
                            int destLoyer = players.FindIndex(a => a.Name == myPlateau.Cases[players[index].Position].Owner);
                            players[destLoyer].Money += myPlateau.Cases[players[index].Position].Loyer[myPlateau.Cases[players[index].Position].House]; //done le loyé au proprio
                            Console.WriteLine("vous donnez " + myPlateau.Cases[players[index].Position].Loyer[myPlateau.Cases[players[index].Position].House] + "$ a " + myPlateau.Cases[players[index].Position].Owner);
                        }
                        if (players[index].Money < 0)
                        {
                            players[index].IsInGame = false; Console.WriteLine("Faillite. Vous etes elimine"); (myPlateau, players) = ResetPlayerProperty(myPlateau, players, index);
                        }
                    }
                }
                else                                                                        //chez sois
                {
                    (myPlateau, players) = InteractWithProperty(myPlateau, players, index); // interact with the player property.
                }
                DisplayInfoPostRound(myPlateau, players, index);
                break;

            case "taxe":
                players[index].Money  -= myPlateau.Cases[players[index].Position].Loyer[0];
                myPlateau.ParcGratuit += myPlateau.Cases[players[index].Position].Loyer[0];
                Console.WriteLine("Vous devez payer :" + myPlateau.Cases[players[index].Position].Loyer[0] + "$");
                if (players[index].Money < 0)
                {
                    players[index].IsInGame = false; Console.WriteLine("Faillite. Vous etes elimine"); (myPlateau, players) = ResetPlayerProperty(myPlateau, players, index);
                }
                DisplayInfoPostRound(myPlateau, players, index);
                break;

            case "card":
                //random carte
                DisplayInfoPostRound(myPlateau, players, index);
                break;

            case "start":
                players[index].Money += 200;
                Console.WriteLine("Vous etes sur la case depart. +200$ suplementaire");
                DisplayInfoPostRound(myPlateau, players, index);
                break;

            case "jail":
                Console.WriteLine("Vous allez directement en prison");
                players[index].Position = 10;
                if (players[index].JailRemaining >= 0)
                {
                    players[index].JailRemaining = 3;
                }
                else if (players[index].JailRemaining < 0)
                {
                    players[index].JailRemaining += 1; Console.WriteLine("Vous venez d'etre libere de prison");
                }
                DisplayInfoPostRound(myPlateau, players, index);
                break;

            case "parc":
                players[index].Money += myPlateau.ParcGratuit;
                Console.WriteLine("Parc gratuit. Vous gagnez :" + myPlateau.ParcGratuit + "$");
                myPlateau.ParcGratuit = 0;
                DisplayInfoPostRound(myPlateau, players, index);
                break;

            case "jailStanding":
                if (players[index].JailRemaining > 0)
                {
                    players[index].JailRemaining -= 1;
                }
                DisplayInfoPostRound(myPlateau, players, index);
                break;

            default:
                break;
            }
            //DisplayInfoPostRound(myPlateau, players, index);
            return(myPlateau, players);
        }
Ejemplo n.º 7
0
 public static (Plateau _myPlateau, List <Joueur> _players) ResetPlayerProperty(Plateau myPlateau, List <Joueur> players, int index)
 {
     for (int i = 0; i < 40; i++)
     {
         if (myPlateau.Cases[i].Owner == players[index].Name)
         {
             Console.WriteLine("La propriete " + myPlateau.Cases[i].Name + " est de nouveau disponiblea l'achat");
             myPlateau.Cases[i].House       = 0;
             myPlateau.Cases[i].IsByable    = true;
             myPlateau.Cases[i].IsHypoteque = false;
             myPlateau.Cases[i].Owner       = null;
         }
     }
     return(myPlateau, players);
 }