66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
namespace MiniJeuxFinal.Games.Trash;
|
|
|
|
public class Ppc
|
|
{
|
|
private static readonly Dictionary<string, int> Scores = new Dictionary<string, int>()
|
|
{
|
|
{"joueur", 0},
|
|
{"ordi", 0}
|
|
};
|
|
|
|
|
|
|
|
public Ppc()
|
|
{
|
|
Console.WriteLine("Bienvenue dans ");
|
|
Console.WriteLine("✊✋✌️ Pierre-Papier-Ciseaux !");
|
|
Console.WriteLine("Premier à 3 points gagne !");
|
|
Start();
|
|
// Résultat final
|
|
Console.WriteLine($"\n{(Scores["joueur"] == 3 ? "🎉 TU AS GAGNÉ !" : "😢 L\'ordinateur a gagné...")}");
|
|
Console.WriteLine($"Score final : {Scores["joueur"]} - {Scores["ordi"]}");
|
|
}
|
|
|
|
|
|
|
|
private static void Start()
|
|
{
|
|
var random = new Random();
|
|
var choix_possibles = new[] { "pierre", "papier", "ciseaux" };
|
|
|
|
while (Scores["joueur"] < 3 && Scores["ordi"] < 3)
|
|
{
|
|
Console.WriteLine($"\nScore : Toi {Scores["joueur"]} - {Scores["ordi"]} Ordinateur");
|
|
Console.WriteLine("Choisis (pierre, papier, ciseaux) : ");
|
|
var joueur = Console.ReadLine();
|
|
|
|
if (!choix_possibles.Contains(joueur?.ToLower()))
|
|
{
|
|
Console.WriteLine("❌ Choix invalide !");
|
|
continue;
|
|
}
|
|
|
|
|
|
var ordi = random.GetItems(choix_possibles, 1).FirstOrDefault();
|
|
Console.WriteLine($"🤖 L'ordinateur a choisi : {ordi}");
|
|
|
|
// Déterminer le gagnant
|
|
if (joueur == ordi)
|
|
{
|
|
Console.WriteLine("✨ Égalité !");
|
|
}
|
|
else if ((joueur == "pierre" && ordi == "ciseaux") ||
|
|
(joueur == "papier" && ordi == "pierre") ||
|
|
(joueur == "ciseaux" && ordi == "papier"))
|
|
{
|
|
Console.WriteLine("✅ Tu gagnes cette manche !");
|
|
Scores["joueur"] += 1;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("❌ L'ordinateur gagne cette manche !");
|
|
Scores["ordi"] += 1;
|
|
}
|
|
}
|
|
}
|
|
} |