added the title improved the help and now you can replay the game after a party end

This commit is contained in:
bwbl 2024-10-23 14:22:27 +02:00
parent 8e98e930e2
commit 57d169531c

View File

@ -9,11 +9,17 @@
public class Program
{
public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Magenta;
/*public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Magenta;
public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.DarkMagenta;
const ConsoleColor backgroundColor = ConsoleColor.DarkYellow;
const ConsoleColor forgroundColor = ConsoleColor.Black;
const ConsoleColor forgroundColor = ConsoleColor.Black;*/
public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Red;
public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.Yellow;
const ConsoleColor backgroundColor = ConsoleColor.Black;
const ConsoleColor forgroundColor = ConsoleColor.White;
public void SetColor(ConsoleColor backgroundColor = backgroundColor, ConsoleColor forgroundColor = forgroundColor)
{
@ -25,10 +31,12 @@
{
new Program().SetColor();
Console.Clear();
new Draw().DrawTitle();
Console.CursorVisible = false;
int[] boardSize = new Board().BoardSize();
Token[,] board = new Token[boardSize[0], boardSize[1]];
new Game().Start(board);
new Game().replay();
}
}
@ -36,6 +44,30 @@
{
private Draw d = new Draw();
private Program p = new Program();
public void replay()
{
Console.WriteLine("Voulez-vous rejouer ? (o/n)");
switch (Console.ReadKey().Key)
{
case ConsoleKey.O:
new Program().SetColor();
Console.Clear();
new Draw().DrawTitle();
int[] boardSize = new Board().BoardSize();
Token[,] board = new Token[boardSize[0], boardSize[1]];
new Game().Start(board);
new Game().replay();
break;
case ConsoleKey.N:
return;
default:
Console.WriteLine("Entrée invalide");
replay();
break;
}
}
public void Start(Token[,] board)
{
int pos = 0;
@ -43,6 +75,7 @@
bool placed = false;
Console.Clear();
d.DrawTitle(d.leftSpacing);
d.DrawPlayGroundBorder(board);
d.DrawBorder(board);
d.DrawHelp(board);
@ -80,7 +113,7 @@
else if (placed && currentPlayer == Token.SecondPlayer)
currentPlayer = Token.FirstPlayer;
break;
break;
}
}
d.DrawBoard(board);
@ -112,7 +145,6 @@
Console.WriteLine("La partie à été arrêtée");
}
Console.WriteLine("La partie à duré " + Turn(board) + " tours");
Console.ReadLine();
}
static int Turn(Token[,] board)
@ -158,7 +190,7 @@
for (int x = 0; x < board.GetLength(0); x++)
{
// on check les bordures horizontales
if (x + 3 < board.GetLength(0))
if (x + 3 < board.GetLength(0))
{
// on check les 4 prochains jetons dans le sens horizontal
if (board[x, y] == j &&
@ -279,8 +311,8 @@
public class Draw
{
private Program p = new Program();
public int topSpacing = 2;
private int leftSpacing = 10;
public int topSpacing = 4;
public int leftSpacing = 10;
public void DrawPlayGroundBorder(Token[,] board)
{
Console.SetCursorPosition(leftSpacing, topSpacing);
@ -392,13 +424,28 @@
}
}
public void DrawTitle(int spacing = 0)
{
Console.SetCursorPosition(spacing, 0);
Console.WriteLine("╔═══════════════════════════════════╗");
Console.SetCursorPosition(spacing, 1);
Console.WriteLine("║ Bienvenue dans le jeu Puissance 4 ║");
Console.SetCursorPosition(spacing, 2);
Console.WriteLine("║ Réalisé par Théophile Borboën ║");
Console.SetCursorPosition(spacing, 3);
Console.WriteLine("╚═══════════════════════════════════╝");
}
public void DrawHelp(Token[,] board)
{
WriteHelp(board, 0, 0, "Mode d'utilisation");
WriteHelp(board, 0, 1, "-------------------");
WriteHelp(board, 4, 2, "Déplacement\tTouches directionnelles");
WriteHelp(board, 4, 3, "Tir\t\tSpacebar ou Enter");
WriteHelp(board, 4, 4, "Quitter\tEscape");
WriteHelp(board, 4, 2, "Déplacement");
WriteHelp(board, 18, 2, "Touches directionnelles");
WriteHelp(board, 4, 3, "Tir");
WriteHelp(board, 18, 3, "Spacebar ou Enter");
WriteHelp(board, 4, 4, "Quitter");
WriteHelp(board, 18, 4, "Escape");
p.SetColor(forgroundColor: p.FIRSTPLAYERCOLOR);
WriteHelp(board, 4, 6, "Joueur 1: ");
p.SetColor(p.FIRSTPLAYERCOLOR);