|
|
|
@ -1,31 +1,30 @@
|
|
|
|
|
using CoreLibrary;
|
|
|
|
|
using CoreLibrary.Events;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace ConsoleApp
|
|
|
|
|
{
|
|
|
|
|
internal class Utils
|
|
|
|
|
public class Utils
|
|
|
|
|
{
|
|
|
|
|
private static int nombreJoueurs = 0;
|
|
|
|
|
|
|
|
|
|
private readonly static int longueurTitre = 55;
|
|
|
|
|
|
|
|
|
|
private readonly static Dictionary<Couleur, ConsoleColor> convertirCouleurs = new Dictionary<Couleur, ConsoleColor>()
|
|
|
|
|
private readonly static Dictionary<Couleur, ConsoleColor> couleursTerminal = new Dictionary<Couleur, ConsoleColor>()
|
|
|
|
|
{
|
|
|
|
|
{Couleur.NOIR, ConsoleColor.Black },
|
|
|
|
|
{Couleur.BLANC, ConsoleColor.White },
|
|
|
|
|
{Couleur.ROUGE, ConsoleColor.Red },
|
|
|
|
|
{Couleur.VERT, ConsoleColor.Green },
|
|
|
|
|
{Couleur.BLEU, ConsoleColor.Blue },
|
|
|
|
|
{Couleur.JAUNE, ConsoleColor.Yellow }
|
|
|
|
|
{Couleur.JAUNE, ConsoleColor.DarkYellow }
|
|
|
|
|
};
|
|
|
|
|
private readonly static Dictionary<Indicateur, ConsoleColor> convertirIndicateurs = new Dictionary<Indicateur, ConsoleColor>()
|
|
|
|
|
|
|
|
|
|
private readonly static Dictionary<Indicateur, ConsoleColor> indicateursTerminal = new Dictionary<Indicateur, ConsoleColor>()
|
|
|
|
|
{
|
|
|
|
|
{Indicateur.BONNEPLACE, ConsoleColor.Black },
|
|
|
|
|
{Indicateur.BONNECOULEUR, ConsoleColor.White }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static void AfficherTitre()
|
|
|
|
|
public static void DessinerTitre()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("""
|
|
|
|
|
__ __ _ _ _
|
|
|
|
|
| \/ | __ _ ___| |_ ___ _ _ _ __ (_) _ _ __| |
|
|
|
|
@ -33,50 +32,28 @@ namespace ConsoleApp
|
|
|
|
|
|_| |_|\__,_|/__/ \__|\___||_| |_|_|_||_||_||_|\__,_|
|
|
|
|
|
""");
|
|
|
|
|
|
|
|
|
|
AfficherSeparateur();
|
|
|
|
|
DessinerSeparateur();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void AfficherTitre(string titre)
|
|
|
|
|
{
|
|
|
|
|
int taille = longueurTitre - titre.Length;
|
|
|
|
|
int gauche = taille > 0 ? taille / 2 : 0;
|
|
|
|
|
|
|
|
|
|
Console.Write(titre.PadLeft(titre.Length + gauche));
|
|
|
|
|
AfficherSeparateur();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AfficherSeparateur()
|
|
|
|
|
public static void DessinerSeparateur()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("""
|
|
|
|
|
|
|
|
|
|
_______________________________________________________
|
|
|
|
|
───────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string SaisirNom()
|
|
|
|
|
{
|
|
|
|
|
string nom = $"Joueur {++nombreJoueurs}";
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(nom);
|
|
|
|
|
Console.Write(">>> ");
|
|
|
|
|
nom = Console.ReadLine() ?? nom;
|
|
|
|
|
if (nom == "")
|
|
|
|
|
{
|
|
|
|
|
--nombreJoueurs;
|
|
|
|
|
throw new UtilsNomJoueurNullException();
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
|
|
|
|
|
return nom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DessinerJeton(Jeton jeton)
|
|
|
|
|
public static void DessinerPion(Enum pion)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = convertirCouleurs.GetValueOrDefault(jeton.Couleur);
|
|
|
|
|
Console.ForegroundColor = pion.GetType().Equals(typeof(Couleur)) ?
|
|
|
|
|
couleursTerminal.GetValueOrDefault((Couleur) pion) :
|
|
|
|
|
indicateursTerminal.GetValueOrDefault((Indicateur) pion);
|
|
|
|
|
|
|
|
|
|
Console.BackgroundColor = Console.ForegroundColor.Equals(ConsoleColor.Black) ? ConsoleColor.White : ConsoleColor.Black;
|
|
|
|
|
|
|
|
|
|
Console.Write("⬤");
|
|
|
|
@ -86,97 +63,113 @@ namespace ConsoleApp
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DessinerIndicateur(Indicateur indicateur)
|
|
|
|
|
public static void DessinerPlateau(IEnumerable<IEnumerable<Jeton?>> grille, IEnumerable<IEnumerable<Indicateur>> indicateurs)
|
|
|
|
|
{
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
IEnumerable<Jeton?>[] grilleTableau = (IEnumerable<Jeton?>[]) grille.ToArray();
|
|
|
|
|
IEnumerable<Indicateur>[] indicateursTableau = (IEnumerable<Indicateur>[]) indicateurs.ToArray();
|
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = convertirIndicateurs.GetValueOrDefault(indicateur);
|
|
|
|
|
Console.BackgroundColor = Console.ForegroundColor.Equals(ConsoleColor.Black) ? ConsoleColor.White : ConsoleColor.Black;
|
|
|
|
|
Console.WriteLine(" Codes Indicateurs ");
|
|
|
|
|
Console.WriteLine("──────────────── ────────────────");
|
|
|
|
|
Console.WriteLine("│ │ │ │");
|
|
|
|
|
|
|
|
|
|
Console.Write("⬤");
|
|
|
|
|
for (int i = 0; i < grille.Count(); ++i)
|
|
|
|
|
{
|
|
|
|
|
Console.Write("│ ");
|
|
|
|
|
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
Jeton?[] ligneGrille = grilleTableau[i].ToArray();
|
|
|
|
|
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
}
|
|
|
|
|
for (int j = 0; j < ligneGrille.Length; ++j)
|
|
|
|
|
{
|
|
|
|
|
Jeton? jeton = ligneGrille[j];
|
|
|
|
|
|
|
|
|
|
public static void DessinerCode(IEnumerable<Jeton?> jetons)
|
|
|
|
|
{
|
|
|
|
|
foreach (Jeton? jeton in jetons)
|
|
|
|
|
{
|
|
|
|
|
if (jeton.HasValue)
|
|
|
|
|
if(jeton.HasValue)
|
|
|
|
|
{
|
|
|
|
|
DessinerPion(jeton.Value.Couleur);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.Write(" │ │ ");
|
|
|
|
|
|
|
|
|
|
if(indicateursTableau[i] != null)
|
|
|
|
|
{
|
|
|
|
|
DessinerJeton(jeton.Value);
|
|
|
|
|
Indicateur[] ligneIndicateurs = indicateursTableau[i].ToArray();
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < ligneIndicateurs.Length; ++j)
|
|
|
|
|
{
|
|
|
|
|
DessinerPion(ligneIndicateurs[j]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ligneIndicateurs.Length < 4)
|
|
|
|
|
{
|
|
|
|
|
Console.Write("".PadLeft((4 - ligneIndicateurs.Length) * 3));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(" │");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("│ │ │ │");
|
|
|
|
|
Console.WriteLine("──────────────── ────────────────");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void DessinerIndicateurs(IEnumerable<Indicateur> indicateurs)
|
|
|
|
|
public static string? DemanderJoueur(Object? sender, DemanderJoueurEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (indicateurs == null)
|
|
|
|
|
{
|
|
|
|
|
indicateurs = [];
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine($"Joueur {e.Numero}");
|
|
|
|
|
Console.Write(">>> ");
|
|
|
|
|
|
|
|
|
|
foreach (Indicateur indicateur in indicateurs)
|
|
|
|
|
{
|
|
|
|
|
DessinerIndicateur(indicateur);
|
|
|
|
|
}
|
|
|
|
|
string? nom = Console.ReadLine();
|
|
|
|
|
|
|
|
|
|
if (indicateurs.Count() < 4)
|
|
|
|
|
Console.Write("".PadLeft((4 - indicateurs.Count()) * 3));
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
|
|
|
|
|
return nom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DessinerPlateau(IEnumerable<IEnumerable<Jeton?>> grille, IEnumerable<IEnumerable<Indicateur>> indicateurs)
|
|
|
|
|
|
|
|
|
|
public static void CommencerLaPartie(Object? sender, DebutPartieEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<Jeton?>[] grilleT = grille.ToArray();
|
|
|
|
|
IEnumerable<Indicateur>[] indicateursT = indicateurs.ToArray();
|
|
|
|
|
DessinerSeparateur();
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("La partie commence, bonne chance à tous !\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(" Codes Indicateurs ");
|
|
|
|
|
Console.WriteLine("──────────────── ────────────────");
|
|
|
|
|
Console.WriteLine("│ │ │ │");
|
|
|
|
|
|
|
|
|
|
public static void NouveauTour(Object? sender, NouveauTourEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DessinerSeparateur();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < grilleT.Length; ++i)
|
|
|
|
|
{
|
|
|
|
|
Console.Write("│ ");
|
|
|
|
|
DessinerCode(grilleT[i]);
|
|
|
|
|
Console.Write(" │");
|
|
|
|
|
Console.WriteLine($"Tour {e.Tour} - {e.Joueur.Nom}\n");
|
|
|
|
|
|
|
|
|
|
Console.Write(" ");
|
|
|
|
|
DessinerPlateau(e.Grille, e.Indicateurs);
|
|
|
|
|
|
|
|
|
|
Console.Write("│ ");
|
|
|
|
|
DessinerIndicateurs(indicateursT[i]);
|
|
|
|
|
Console.WriteLine(" │");
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("│ │ │ │");
|
|
|
|
|
Console.WriteLine("──────────────── ────────────────");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Jeton? ChoixJeton()
|
|
|
|
|
public static Jeton DemanderJeton(Object? sender, DemanderJetonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.TreatControlCAsInput = true;
|
|
|
|
|
|
|
|
|
|
bool aChoisi = false;
|
|
|
|
|
int indice = 0;
|
|
|
|
|
Couleur[] couleurs = (Couleur[])Enum.GetValues(typeof(Couleur));
|
|
|
|
|
Couleur couleur = couleurs[indice];
|
|
|
|
|
|
|
|
|
|
while (!aChoisi)
|
|
|
|
|
{
|
|
|
|
|
DessinerJeton(new Jeton(couleur));
|
|
|
|
|
DessinerPion(couleurs[indice]);
|
|
|
|
|
Console.Write("\b\b\b");
|
|
|
|
|
|
|
|
|
|
ConsoleKey touche = Console.ReadKey(true).Key;
|
|
|
|
|
|
|
|
|
|
switch (touche)
|
|
|
|
|
switch (Console.ReadKey(true).Key)
|
|
|
|
|
{
|
|
|
|
|
case ConsoleKey.Enter:
|
|
|
|
|
aChoisi = true;
|
|
|
|
@ -190,8 +183,8 @@ namespace ConsoleApp
|
|
|
|
|
++indice;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ConsoleKey.Escape:
|
|
|
|
|
return null;
|
|
|
|
|
/*case ConsoleKey.Escape:
|
|
|
|
|
return null;*/
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
@ -201,38 +194,40 @@ namespace ConsoleApp
|
|
|
|
|
indice = couleurs.Length - 1;
|
|
|
|
|
else if (indice >= couleurs.Length)
|
|
|
|
|
indice = 0;
|
|
|
|
|
|
|
|
|
|
couleur = couleurs[indice];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.TreatControlCAsInput = false;
|
|
|
|
|
return new Jeton(couleur);
|
|
|
|
|
|
|
|
|
|
return new Jeton(couleurs[indice]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ChoixCode(ref Code code)
|
|
|
|
|
public static void AjouterJeton(Object? sender, AjouterJetonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
while (!code.EstComplet())
|
|
|
|
|
{
|
|
|
|
|
Jeton? jeton = ChoixJeton();
|
|
|
|
|
DessinerPion(e.Jeton.Couleur);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (jeton.HasValue)
|
|
|
|
|
{
|
|
|
|
|
DessinerJeton(jeton.Value);
|
|
|
|
|
code.AjouterJeton(jeton.Value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.Write("\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
code.SupprimerDernierJeton();
|
|
|
|
|
}
|
|
|
|
|
catch(CodeTableauLesJetonsVideException)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Il n'y a pas de jetons! Impossible de supprimer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public static void AjouterCode(Object? sender, AjouterCodeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
|
|
|
|
|
DessinerSeparateur();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void PartieTerminee(Object? sender, PartieTermineeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Joueur[] gagnants = e.Gagnants.ToArray();
|
|
|
|
|
|
|
|
|
|
if (gagnants.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("C'est une égalité !");
|
|
|
|
|
}
|
|
|
|
|
else if (gagnants.Length == 1)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"C'est une victoire de {gagnants[0].Nom}.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("C'est une défaite des deux joueurs...");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|