diff --git a/Program.cs b/Program.cs index 712509a..2574250 100644 --- a/Program.cs +++ b/Program.cs @@ -9,20 +9,11 @@ public class Program { - public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Cyan; - public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.Yellow; - /* - - public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Cyan; - public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.Yellow; + public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Magenta; + public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.DarkMagenta; - - public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.DarkGreen; - public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.DarkYellow; - - */ - const ConsoleColor backgroundColor = ConsoleColor.DarkCyan; - const ConsoleColor forgroundColor = ConsoleColor.Green; + const ConsoleColor backgroundColor = ConsoleColor.DarkYellow; + const ConsoleColor forgroundColor = ConsoleColor.Black; public void SetColor(ConsoleColor backgroundColor = backgroundColor, ConsoleColor forgroundColor = forgroundColor) { @@ -54,6 +45,7 @@ Console.Clear(); d.DrawPlayGroundBorder(board); d.DrawBorder(board); + d.DrawHelp(board); while (!CheckWin(board)) { @@ -63,6 +55,11 @@ d.DrawPlayGround(board, currentPlayer, pos); ConsoleKey key = Console.ReadKey(true).Key; + if (key == ConsoleKey.Escape) + { + currentPlayer = Token.None; + break; + } switch (key) { case ConsoleKey.RightArrow: @@ -83,13 +80,14 @@ else if (placed && currentPlayer == Token.SecondPlayer) currentPlayer = Token.FirstPlayer; - break; + break; } } d.DrawBoard(board); d.DrawPlayGround(board, currentPlayer, pos); p.SetColor(); - Console.Clear(); + //Console.Clear(); + Console.SetCursorPosition(0, board.GetLength(1) * 2 + d.topSpacing + 4); // currentplayer est inversé if (CheckDraw(board)) Console.WriteLine("il y a eu une égalité"); @@ -109,8 +107,11 @@ Console.Write("joueur 1"); p.SetColor(); Console.WriteLine(" a gagné"); + } else if (currentPlayer == Token.None) + { + Console.WriteLine("La partie à été arrêtée"); } - Console.WriteLine("La partie à été gagnée en " + Turn(board) + " tours"); + Console.WriteLine("La partie à duré " + Turn(board) + " tours"); Console.ReadLine(); } @@ -278,10 +279,11 @@ public class Draw { private Program p = new Program(); - private int topSpacing = 2; + public int topSpacing = 2; + private int leftSpacing = 10; public void DrawPlayGroundBorder(Token[,] board) { - Console.SetCursorPosition(0, topSpacing); + Console.SetCursorPosition(leftSpacing, topSpacing); Console.Write("╔═══"); for (int x = 0; x < board.GetLength(0) - 1; x++) { @@ -293,13 +295,13 @@ { for (int x = 0; x < board.GetLength(0); x++) { - Console.SetCursorPosition(x * 4, y * 2 + topSpacing + 1); + Console.SetCursorPosition(leftSpacing + x * 4, y * 2 + topSpacing + 1); Console.Write("║"); } Console.Write(" ║"); } - Console.SetCursorPosition(0, topSpacing + 2); + Console.SetCursorPosition(leftSpacing, topSpacing + 2); Console.Write("╚═══"); for (int x = 0; x < board.GetLength(0) - 1; x++) { @@ -312,7 +314,7 @@ { for (int x = 0; x < board.GetLength(0); x++) { - Console.SetCursorPosition(x*4+2, topSpacing + 1); + Console.SetCursorPosition(leftSpacing + x * 4+2, topSpacing + 1); if (pos == x) Console.Write(DrawToken(currentPlayer)); else Console.Write(DrawToken(Token.None)); @@ -322,7 +324,7 @@ public void DrawBorder(Token[,] board) { int playgroundSpacing = topSpacing + 3; - Console.SetCursorPosition(0, playgroundSpacing); + Console.SetCursorPosition(leftSpacing, playgroundSpacing); Console.Write("╔═══"); for (int x = 0; x < board.GetLength(0) - 1; x++) { @@ -334,7 +336,7 @@ { for (int x = 0; x < board.GetLength(0); x++) { - Console.SetCursorPosition(x * 4, y * 2 + playgroundSpacing + 1); + Console.SetCursorPosition(leftSpacing + x * 4, y * 2 + playgroundSpacing + 1); Console.Write("║"); } Console.Write(" ║"); @@ -342,17 +344,17 @@ for (int y = 0; y < board.GetLength(1) - 1; y++) { - Console.SetCursorPosition(0, y * 2 + playgroundSpacing + 2); + Console.SetCursorPosition(leftSpacing, y * 2 + playgroundSpacing + 2); Console.Write("╠═══"); for (int x = 1; x < board.GetLength(0); x++) { - Console.SetCursorPosition(x * 4, y * 2 + playgroundSpacing + 2); + Console.SetCursorPosition(leftSpacing + x * 4, y * 2 + playgroundSpacing + 2); Console.Write("╬═══"); } Console.Write("╣"); } - Console.SetCursorPosition(0, board.GetLength(1) * 2 + playgroundSpacing); + Console.SetCursorPosition(leftSpacing, board.GetLength(1) * 2 + playgroundSpacing); Console.Write("╚═══"); for (int x = 0; x < board.GetLength(0) - 1; x++) { @@ -367,7 +369,7 @@ for (int y = 0; y < board.GetLength(1); y++) for (int x = 0; x < board.GetLength(0); x++) { - Console.SetCursorPosition(x*4+2, y*2 + playgroundSpacing + 1); + Console.SetCursorPosition(leftSpacing + x * 4+2, y*2 + playgroundSpacing + 1); Console.Write("{0}", DrawToken(board[x, y])); } } @@ -389,5 +391,28 @@ return default; } } + + 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"); + p.SetColor(forgroundColor: p.FIRSTPLAYERCOLOR); + WriteHelp(board, 4, 6, "Joueur 1: "); + p.SetColor(p.FIRSTPLAYERCOLOR); + WriteHelp(board, 14, 6, " "); + p.SetColor(forgroundColor: p.SECONDPLAYERCOLOR); + WriteHelp(board, 18, 6, "Joueur 2: "); + p.SetColor(p.SECONDPLAYERCOLOR); + WriteHelp(board, 28, 6, " "); + } + + private void WriteHelp(Token[,] board, int x, int y, string text) + { + Console.SetCursorPosition(leftSpacing + board.GetLength(0) * 4 + 8 + x, topSpacing + y); + Console.Write(text); + } } }