Ajout d'une correction possible
This commit is contained in:
53
Correction/MiniJeuxFinal.sln
Normal file
53
Correction/MiniJeuxFinal.sln
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniJeux", "MiniJeuxFinal\MiniJeuxFinal.csproj", "{5BA674C8-192C-47C8-8F50-F9F17A762B2C}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniJeuxFinal.Test", "Tests\MiniJeuxFinal.Test\MiniJeuxFinal.Test.csproj", "{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Release|x64.Build.0 = Release|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5BA674C8-192C-47C8-8F50-F9F17A762B2C}.Release|x86.Build.0 = Release|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Release|x64.Build.0 = Release|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{09AF8FA9-D62B-45DB-AC87-0BAE32811EAC} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
7
Correction/MiniJeuxFinal/Games/IAction.cs
Normal file
7
Correction/MiniJeuxFinal/Games/IAction.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace MiniJeuxFinal.Games
|
||||
{
|
||||
public interface IAction
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
||||
17
Correction/MiniJeuxFinal/Games/IGame.cs
Normal file
17
Correction/MiniJeuxFinal/Games/IGame.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
17
Correction/MiniJeuxFinal/Games/IPlayer.cs
Normal file
17
Correction/MiniJeuxFinal/Games/IPlayer.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Actions
|
||||
{
|
||||
public interface IActionPpc : IAction
|
||||
{
|
||||
bool ToWin(IActionPpc other);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
|
||||
namespace MiniJeuxFinal.Games.PierrePapierCiseaux.Factories
|
||||
{
|
||||
public interface IActionPpcFactory
|
||||
{
|
||||
IActionPpc GetAction(IList<IActionPpc> action);
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
87
Correction/MiniJeuxFinal/Games/Trash/Pendu.cs
Normal file
87
Correction/MiniJeuxFinal/Games/Trash/Pendu.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
66
Correction/MiniJeuxFinal/Games/Trash/Ppc.cs
Normal file
66
Correction/MiniJeuxFinal/Games/Trash/Ppc.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Correction/MiniJeuxFinal/MiniJeuxFinal.csproj
Normal file
10
Correction/MiniJeuxFinal/MiniJeuxFinal.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
34
Correction/MiniJeuxFinal/Program.cs
Normal file
34
Correction/MiniJeuxFinal/Program.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux;
|
||||
|
||||
class Program()
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var game = new PierrePapierCiseauxGame(3, "loic");
|
||||
game.TurnStarted += (sender, tuple) =>
|
||||
{
|
||||
Console.WriteLine($"Tu joues : {tuple.playerChoice}");
|
||||
Console.WriteLine($"L’ordinateur joue : {tuple.computerChoice}");
|
||||
};
|
||||
game.TurnEnded += (sender, result) =>
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
Console.Clear();
|
||||
if (result.winner == null)
|
||||
Console.WriteLine($"Egalitée !");
|
||||
else
|
||||
Console.WriteLine($"{result.winner.Name} gagne la manche");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Score : {result.players[0]} - {result.players[1]}");
|
||||
Console.WriteLine();
|
||||
};
|
||||
game.GameEnded += (sender, result) =>
|
||||
{
|
||||
Console.WriteLine($"{result.winner.Name} AS GAGNÉ ! 🎉🎉🎉");
|
||||
Console.WriteLine($"Score final : {result.winner.Score} - {result.players.FirstOrDefault(_ => _.Name != result.winner.Name)?.Score}");
|
||||
};
|
||||
Console.WriteLine(game.Name);
|
||||
Console.WriteLine();
|
||||
game.Start();
|
||||
}
|
||||
}
|
||||
11
Correction/MiniJeuxFinal/Wrappers/ConsoleService.cs
Normal file
11
Correction/MiniJeuxFinal/Wrappers/ConsoleService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace MiniJeuxFinal.Wrappers
|
||||
{
|
||||
internal class ConsoleService : IConsole
|
||||
{
|
||||
public string? ReadLine() =>
|
||||
Console.ReadLine();
|
||||
|
||||
public void WriteLine(string message) =>
|
||||
Console.WriteLine(message);
|
||||
}
|
||||
}
|
||||
9
Correction/MiniJeuxFinal/Wrappers/IConsole.cs
Normal file
9
Correction/MiniJeuxFinal/Wrappers/IConsole.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace MiniJeuxFinal.Wrappers
|
||||
{
|
||||
public interface IConsole
|
||||
{
|
||||
string? ReadLine();
|
||||
|
||||
void WriteLine(string message);
|
||||
}
|
||||
}
|
||||
3
Correction/ReadMe.md
Normal file
3
Correction/ReadMe.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Exemple final de se à quoi on pourrait aller
|
||||
|
||||
Cette solution est un aperçu des bonne pratique mise en place.
|
||||
@@ -0,0 +1,33 @@
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Actions
|
||||
{
|
||||
public class PaperActionTest
|
||||
{
|
||||
private PaperAction CreateTarget() => new PaperAction();
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_init()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.Name).IsEqualTo("Papier");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_win()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new StoneAction())).IsTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_loose()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new ScissorsAction())).IsFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Actions
|
||||
{
|
||||
public class ScissorsActionTest
|
||||
{
|
||||
private ScissorsAction CreateTarget() => new ScissorsAction();
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_init()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.Name).IsEqualTo("Ciseaux");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_win()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new PaperAction())).IsTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_loose()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new StoneAction())).IsFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Actions
|
||||
{
|
||||
public class StoneActionTest
|
||||
{
|
||||
private StoneAction CreateTarget() => new StoneAction();
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_init()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.Name).IsEqualTo("Pierre");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_win()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new ScissorsAction())).IsTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_loose()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new PaperAction())).IsFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using FakeItEasy;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories;
|
||||
using MiniJeuxFinal.Wrappers;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Factories
|
||||
{
|
||||
public class InputActionFactoryTest
|
||||
{
|
||||
private readonly IConsole _console = A.Fake<IConsole>();
|
||||
|
||||
|
||||
|
||||
private InputActionFactory CreateTarget() =>
|
||||
new InputActionFactory(_console);
|
||||
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData("0")]
|
||||
[InlineData("1")]
|
||||
[InlineData("2")]
|
||||
public void Should_get_selected_action(string selected)
|
||||
{
|
||||
var target = CreateTarget();
|
||||
A.CallTo(() => _console.ReadLine()).Returns(selected);
|
||||
var actions = new List<IActionPpc>
|
||||
{
|
||||
A.Fake<IActionPpc>(),
|
||||
A.Fake<IActionPpc>(),
|
||||
A.Fake<IActionPpc>()
|
||||
};
|
||||
|
||||
var result = target.GetAction(actions);
|
||||
Check.That(actions.Contains(result)).IsTrue();
|
||||
Check.That(result).IsEqualTo(actions[int.Parse(selected)]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_show_error_when_invalid_input()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
A.CallTo(() => _console.ReadLine()).ReturnsNextFromSequence("3", "0");
|
||||
var actions = new List<IActionPpc>
|
||||
{
|
||||
A.Fake<IActionPpc>(),
|
||||
A.Fake<IActionPpc>(),
|
||||
A.Fake<IActionPpc>()
|
||||
};
|
||||
|
||||
var result = target.GetAction(actions);
|
||||
Check.That(actions.Contains(result)).IsTrue();
|
||||
Check.That(result).IsEqualTo(actions[int.Parse("0")]);
|
||||
A.CallTo(() => _console.WriteLine("❌ Choix invalide !")).MustHaveHappenedOnceExactly();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using FakeItEasy;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Factories
|
||||
{
|
||||
public class RandomActionFactoryTest
|
||||
{
|
||||
private RandomActionFactory CreateTarget() => new RandomActionFactory();
|
||||
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData(2)]
|
||||
[InlineData(5)]
|
||||
[InlineData(3)]
|
||||
[InlineData(10)]
|
||||
public void Should_get_random_action(int actionNumber)
|
||||
{
|
||||
var target = CreateTarget();
|
||||
var actions = new List<IActionPpc>();
|
||||
for (int i = 0; i < actionNumber; i++)
|
||||
actions.Add(A.Fake<IActionPpc>());
|
||||
|
||||
Check.That(actions.Contains(target.GetAction(actions))).IsTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using FakeItEasy;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Players;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Players
|
||||
{
|
||||
public class PlayerPpcTest
|
||||
{
|
||||
private readonly IActionPpcFactory _actionPpcFactory = A.Fake<IActionPpcFactory>();
|
||||
|
||||
|
||||
|
||||
private PlayerPpc CreateTarget() => new PlayerPpc("Paul", _actionPpcFactory);
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_initialize_target()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
|
||||
Check.That(player.Name).IsEqualTo("Paul");
|
||||
Check.That(player.ToString()).IsEqualTo("Paul: 0");
|
||||
Check.That(player.Score).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_increment_score()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
Check.That(player.Score).IsEqualTo(0);
|
||||
player.IncrementScore();
|
||||
Check.That(player.Score).IsEqualTo(1);
|
||||
player.IncrementScore();
|
||||
player.IncrementScore();
|
||||
Check.That(player.Score).IsEqualTo(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_add_a_single_action_and_get()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
var action1 = A.Fake<IActionPpc>();
|
||||
A.CallTo(() => _actionPpcFactory.GetAction(A<IList<IActionPpc>>._)).Returns(action1);
|
||||
player.AddAction(action1);
|
||||
var result = player.Play();
|
||||
|
||||
Check.That(result).IsEqualTo(action1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_add_a_multiple_actions_and_get()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
var action1 = A.Fake<IActionPpc>();
|
||||
var action2 = A.Fake<IActionPpc>();
|
||||
var action3 = A.Fake<IActionPpc>();
|
||||
A.CallTo(() => _actionPpcFactory.GetAction(A<IList<IActionPpc>>._)).Returns(action2);
|
||||
player.AddAction(action1, action2, action3);
|
||||
var result = player.Play();
|
||||
|
||||
Check.That(result).IsEqualTo(action2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_throw_when_has_no_action()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
Check.ThatCode(() => player.Play()).Throws<InvalidOperationException>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FakeItEasy" Version="8.3.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NFluent" Version="3.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MiniJeuxFinal\MiniJeuxFinal.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
13
Correction/Tests/MiniJeuxFinal.Test/PpcTest.cs
Normal file
13
Correction/Tests/MiniJeuxFinal.Test/PpcTest.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test;
|
||||
|
||||
public class PpcTest
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
var i = 1;
|
||||
Check.That(i).IsEqualTo(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user