added the title improved the help and now you can replay the game after a party end
This commit is contained in:
parent
8e98e930e2
commit
57d169531c
67
Program.cs
67
Program.cs
@ -9,11 +9,17 @@
|
|||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Magenta;
|
/*public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Magenta;
|
||||||
public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.DarkMagenta;
|
public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.DarkMagenta;
|
||||||
|
|
||||||
const ConsoleColor backgroundColor = ConsoleColor.DarkYellow;
|
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)
|
public void SetColor(ConsoleColor backgroundColor = backgroundColor, ConsoleColor forgroundColor = forgroundColor)
|
||||||
{
|
{
|
||||||
@ -25,10 +31,12 @@
|
|||||||
{
|
{
|
||||||
new Program().SetColor();
|
new Program().SetColor();
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
new Draw().DrawTitle();
|
||||||
Console.CursorVisible = false;
|
Console.CursorVisible = false;
|
||||||
int[] boardSize = new Board().BoardSize();
|
int[] boardSize = new Board().BoardSize();
|
||||||
Token[,] board = new Token[boardSize[0], boardSize[1]];
|
Token[,] board = new Token[boardSize[0], boardSize[1]];
|
||||||
new Game().Start(board);
|
new Game().Start(board);
|
||||||
|
new Game().replay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +44,30 @@
|
|||||||
{
|
{
|
||||||
private Draw d = new Draw();
|
private Draw d = new Draw();
|
||||||
private Program p = new Program();
|
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)
|
public void Start(Token[,] board)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
@ -43,6 +75,7 @@
|
|||||||
bool placed = false;
|
bool placed = false;
|
||||||
|
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
d.DrawTitle(d.leftSpacing);
|
||||||
d.DrawPlayGroundBorder(board);
|
d.DrawPlayGroundBorder(board);
|
||||||
d.DrawBorder(board);
|
d.DrawBorder(board);
|
||||||
d.DrawHelp(board);
|
d.DrawHelp(board);
|
||||||
@ -80,7 +113,7 @@
|
|||||||
else if (placed && currentPlayer == Token.SecondPlayer)
|
else if (placed && currentPlayer == Token.SecondPlayer)
|
||||||
currentPlayer = Token.FirstPlayer;
|
currentPlayer = Token.FirstPlayer;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d.DrawBoard(board);
|
d.DrawBoard(board);
|
||||||
@ -112,7 +145,6 @@
|
|||||||
Console.WriteLine("La partie à été arrêtée");
|
Console.WriteLine("La partie à été arrêtée");
|
||||||
}
|
}
|
||||||
Console.WriteLine("La partie à duré " + Turn(board) + " tours");
|
Console.WriteLine("La partie à duré " + Turn(board) + " tours");
|
||||||
Console.ReadLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Turn(Token[,] board)
|
static int Turn(Token[,] board)
|
||||||
@ -158,7 +190,7 @@
|
|||||||
for (int x = 0; x < board.GetLength(0); x++)
|
for (int x = 0; x < board.GetLength(0); x++)
|
||||||
{
|
{
|
||||||
// on check les bordures horizontales
|
// 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
|
// on check les 4 prochains jetons dans le sens horizontal
|
||||||
if (board[x, y] == j &&
|
if (board[x, y] == j &&
|
||||||
@ -279,8 +311,8 @@
|
|||||||
public class Draw
|
public class Draw
|
||||||
{
|
{
|
||||||
private Program p = new Program();
|
private Program p = new Program();
|
||||||
public int topSpacing = 2;
|
public int topSpacing = 4;
|
||||||
private int leftSpacing = 10;
|
public int leftSpacing = 10;
|
||||||
public void DrawPlayGroundBorder(Token[,] board)
|
public void DrawPlayGroundBorder(Token[,] board)
|
||||||
{
|
{
|
||||||
Console.SetCursorPosition(leftSpacing, topSpacing);
|
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)
|
public void DrawHelp(Token[,] board)
|
||||||
{
|
{
|
||||||
WriteHelp(board, 0, 0, "Mode d'utilisation");
|
WriteHelp(board, 0, 0, "Mode d'utilisation");
|
||||||
WriteHelp(board, 0, 1, "-------------------");
|
WriteHelp(board, 0, 1, "-------------------");
|
||||||
WriteHelp(board, 4, 2, "Déplacement\tTouches directionnelles");
|
WriteHelp(board, 4, 2, "Déplacement");
|
||||||
WriteHelp(board, 4, 3, "Tir\t\tSpacebar ou Enter");
|
WriteHelp(board, 18, 2, "Touches directionnelles");
|
||||||
WriteHelp(board, 4, 4, "Quitter\tEscape");
|
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);
|
p.SetColor(forgroundColor: p.FIRSTPLAYERCOLOR);
|
||||||
WriteHelp(board, 4, 6, "Joueur 1: ");
|
WriteHelp(board, 4, 6, "Joueur 1: ");
|
||||||
p.SetColor(p.FIRSTPLAYERCOLOR);
|
p.SetColor(p.FIRSTPLAYERCOLOR);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user