Ajout d'une correction possible

This commit is contained in:
Grizouille
2025-12-12 09:10:08 +01:00
parent 6e2c554af9
commit 7cec5696dc
28 changed files with 828 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
namespace MiniJeuxFinal.Games
{
public interface IAction
{
string Name { get; }
}
}

View File

@@ -0,0 +1,17 @@
namespace MiniJeuxFinal.Games
{
internal interface IGame
{
event EventHandler<(IPlayer winner, IPlayer[] players)>? GameEnded;
event EventHandler<(string playerChoice, string computerChoice)>? TurnStarted;
event EventHandler<(IPlayer? winner, IPlayer[] players)>? TurnEnded;
string Name { get; }
void Start();
}
}

View File

@@ -0,0 +1,17 @@
namespace MiniJeuxFinal.Games
{
internal interface IPlayer
{
string Name { get; }
int Score { get; }
void AddAction(params IAction[] action);
IAction Play();
void IncrementScore();
}
}

View File

@@ -0,0 +1,7 @@
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Actions
{
public interface IActionPpc : IAction
{
bool ToWin(IActionPpc other);
}
}

View File

@@ -0,0 +1,12 @@
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Actions
{
public class PaperAction : IActionPpc
{
public string Name => "Papier";
public bool ToWin(IActionPpc other)
{
return other is not ScissorsAction;
}
}
}

View File

@@ -0,0 +1,12 @@
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Actions
{
public class ScissorsAction : IActionPpc
{
public string Name => "Ciseaux";
public bool ToWin(IActionPpc other)
{
return other is not StoneAction;
}
}
}

View File

@@ -0,0 +1,12 @@
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Actions
{
public class StoneAction : IActionPpc
{
public string Name => "Pierre";
public bool ToWin(IActionPpc other)
{
return other is not PaperAction;
}
}
}

View File

@@ -0,0 +1,9 @@
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Factories
{
public interface IActionPpcFactory
{
IActionPpc GetAction(IList<IActionPpc> action);
}
}

View File

@@ -0,0 +1,33 @@
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
using MiniJeuxFinal.Wrappers;
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Factories
{
public class InputActionFactory : IActionPpcFactory
{
private readonly IConsole _console;
public InputActionFactory(IConsole console)
{
_console = console;
}
public IActionPpc GetAction(IList<IActionPpc> action)
{
_console.WriteLine("Choisis (pierre, papier, ciseaux) : ");
for (int i = 0; i < action.Count; i++)
Console.WriteLine($"{i}: {action[i].Name}");
var result = _console.ReadLine();
if (!int.TryParse(result, out var shootId) || shootId >= action.Count)
{
_console.WriteLine("❌ Choix invalide !");
return GetAction(action);
}
return action[shootId];
}
}
}

View File

@@ -0,0 +1,17 @@
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Factories
{
public class RandomActionFactory : IActionPpcFactory
{
private static Random rnd = new Random();
public IActionPpc GetAction(IList<IActionPpc> action)
{
int n = rnd.Next(action.Count);
return action[n];
}
}
}

View File

@@ -0,0 +1,58 @@
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories;
using MiniJeuxFinal.Games.PierrePapierCiseaux.Players;
using MiniJeuxFinal.Wrappers;
namespace MiniJeuxFinal.Games.PierrePapierCiseaux
{
internal class PierrePapierCiseauxGame : IGame
{
public string Name => "Jeu du Pierre, Papier, Ciseaux 🧱 📄 ✂️";
private readonly int _totalRounds;
private readonly string _playerName;
public event EventHandler<(IPlayer winner, IPlayer[] players)>? GameEnded;
public event EventHandler<(IPlayer? winner, IPlayer[] players)>? TurnEnded;
public event EventHandler<(string playerChoice, string computerChoice)>? TurnStarted;
public PierrePapierCiseauxGame(int totalRound, string playerName)
{
_totalRounds = totalRound;
_playerName = playerName;
}
public void Start()
{
IAction[] lstActions = [new StoneAction(), new PaperAction(), new ScissorsAction()];
var player = new PlayerPpc(_playerName, new InputActionFactory(new ConsoleService()));
player.AddAction(lstActions);
var computer = new PlayerPpc("Ordi", new RandomActionFactory());
computer.AddAction(lstActions);
while (player.Score < _totalRounds && computer.Score < _totalRounds)
{
var actionPLayer = (IActionPpc)player.Play();
var actionComputer = (IActionPpc)computer.Play();
TurnStarted?.Invoke(this, (actionPLayer.Name, actionComputer.Name));
if (actionPLayer.ToWin(actionComputer))
player.IncrementScore();
else if (actionComputer.ToWin(actionPLayer))
computer.IncrementScore();
else
{
TurnEnded?.Invoke(this, (null, [player, computer]));
continue;
}
TurnEnded?.Invoke(this, (actionPLayer.ToWin(actionComputer) ? player : computer, [player, computer]));
}
GameEnded?.Invoke(this, (player.Score > computer.Score ? player : computer, [player, computer]));
}
}
}

View File

@@ -0,0 +1,50 @@
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories;
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Players
{
public class PlayerPpc : IPlayer
{
private readonly List<IActionPpc> _actions = [];
private readonly IActionPpcFactory _actionPpcFactory;
public PlayerPpc(string name, IActionPpcFactory actionPpcFactory)
{
Name = name;
_actionPpcFactory = actionPpcFactory;
}
public string Name { get; }
public int Score { get; private set; }
public void AddAction(params IAction[] action)
{
_actions.AddRange(action.Cast<IActionPpc>());
}
public void IncrementScore()
{
Score++;
}
public IAction Play()
{
if (!_actions.Any())
throw new InvalidOperationException("You don't have a action");
return _actionPpcFactory.GetAction(_actions);
}
public override string ToString()
{
return $"{Name}: {Score}";
}
}
}

View File

@@ -0,0 +1,87 @@
namespace MiniJeuxFinal.Games.Trash;
public class Pendu
{
public Pendu()
{
Start();
}
private void Start()
{
string[] mots = { "ordinateur", "programmation", "developpement", "algorithmie", "variable" };
Random random = new Random();
string motSecret = mots[random.Next(0, mots.Length)];
char[] lettresTrouvees = new char[motSecret.Length];
for (int i = 0; i < lettresTrouvees.Length; i++)
{
lettresTrouvees[i] = '_';
}
int vies = 7;
bool motComplet = false;
Console.WriteLine("=== JEU DU PENDU ===");
Console.WriteLine($"Le mot a {motSecret.Length} lettres");
while (vies > 0 && !motComplet)
{
// Afficher l'état actuel
Console.WriteLine($"\nVies restantes : {vies}");
Console.WriteLine("Mot : " + string.Join(" ", lettresTrouvees));
// Demander une lettre
Console.Write("Propose une lettre : ");
var infoLettre = Console.ReadLine();
var lettre = infoLettre[0];
// Vérifier si la lettre est dans le mot
bool lettreTrouvee = false;
for (int i = 0; i < motSecret.Length; i++)
{
if (motSecret[i] == lettre)
{
lettresTrouvees[i] = lettre;
lettreTrouvee = true;
}
}
if (!lettreTrouvee)
{
vies--;
Console.WriteLine($"❌ La lettre '{lettre}' n'est pas dans le mot.");
}
else
{
Console.WriteLine($"✅ Bonne lettre !");
}
// Vérifier si le mot est complet
motComplet = true;
foreach (char c in lettresTrouvees)
{
if (c == '_')
{
motComplet = false;
break;
}
}
}
// Résultat final
if (motComplet)
{
Console.WriteLine($"\n🎉 FÉLICITATIONS ! Tu as trouvé le mot : {motSecret}");
}
else
{
Console.WriteLine($"\n💀 PERDU ! Le mot était : {motSecret}");
}
Console.WriteLine("\nAppuyez sur une touche pour quitter...");
Console.ReadLine();
}
}

View File

@@ -0,0 +1,66 @@
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;
}
}
}
}