diff --git a/.gitignore b/.gitignore index 5468834..0498878 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ .git .idea +.idea/ bin -obj \ No newline at end of file +bin/ +obj +obj/ +.vs \ No newline at end of file diff --git a/Program.cs b/Program.cs index 0e8ffa3..37ada32 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,5 @@ -namespace P4 + +namespace P4 { public enum Token { @@ -9,6 +10,9 @@ public class Program { + public readonly ConsoleColor FIRSTPLAYERCOLOR = ConsoleColor.Green; + public readonly ConsoleColor SECONDPLAYERCOLOR = ConsoleColor.Red; + public void SetColor(ConsoleColor backgroundColor = ConsoleColor.Black, ConsoleColor forgroundColor = ConsoleColor.White) { Console.ForegroundColor = forgroundColor; @@ -27,6 +31,7 @@ public class Game { private Draw d = new Draw(); + private Program p = new Program(); public void Start(Token[,] board) { int pos = 0; @@ -44,10 +49,12 @@ switch (key) { case ConsoleKey.RightArrow: - pos++; + if (pos < board.GetLength(0) - 1) + pos++; break; case ConsoleKey.LeftArrow: + if (pos > 0) pos--; break; @@ -64,15 +71,30 @@ } d.DrawBoard(board); d.DrawPlayGround(board, currentPlayer, pos); + p.SetColor(); Console.Clear(); // currentplayer est inversé if (CheckDraw(board)) Console.WriteLine("il y a eu une égalité"); else if (currentPlayer == Token.FirstPlayer) - Console.WriteLine("Le joueur " + "2" + " a gagné"); + { + Console.Write("Le "); + p.SetColor(default, p.SECONDPLAYERCOLOR); + Console.Write("joueur 2"); + p.SetColor(); + Console.WriteLine(" a gagné"); + + } else if (currentPlayer == Token.SecondPlayer) - Console.WriteLine("Le joueur " + "1" + " a gagné"); + { + Console.Write("Le "); + p.SetColor(default, p.FIRSTPLAYERCOLOR); + Console.Write("joueur 1"); + p.SetColor(); + Console.WriteLine(" a gagné"); + } Console.WriteLine("La partie à été gagnée en " + Turn(board) + " tours"); + Console.ReadLine(); } static int Turn(Token[,] board) @@ -238,6 +260,7 @@ public class Draw { + private Program p = new Program(); public void DrawPlayGround(Token[,] board, Token currentPlayer, int pos) { for (int x = 0; x < board.GetLength(0); x++) @@ -261,16 +284,19 @@ } } - public char DrawToken(Token token) + public string DrawToken(Token token) { switch (token) { case Token.FirstPlayer: - return 'X'; + p.SetColor(default, p.FIRSTPLAYERCOLOR); + return "■"; case Token.SecondPlayer: - return 'O'; + p.SetColor(default, p.SECONDPLAYERCOLOR); + return "o"; case Token.None: - return '.'; + p.SetColor(default, ConsoleColor.DarkGray); + return "#"; default: return default; }