ajout de couleur modifiable
This commit is contained in:
parent
893ce8e735
commit
5fb82d9b23
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,4 +1,8 @@
|
|||||||
.git
|
.git
|
||||||
.idea
|
.idea
|
||||||
|
.idea/
|
||||||
bin
|
bin
|
||||||
obj
|
bin/
|
||||||
|
obj
|
||||||
|
obj/
|
||||||
|
.vs
|
42
Program.cs
42
Program.cs
@ -1,4 +1,5 @@
|
|||||||
namespace P4
|
|
||||||
|
namespace P4
|
||||||
{
|
{
|
||||||
public enum Token
|
public enum Token
|
||||||
{
|
{
|
||||||
@ -9,6 +10,9 @@
|
|||||||
|
|
||||||
public class Program
|
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)
|
public void SetColor(ConsoleColor backgroundColor = ConsoleColor.Black, ConsoleColor forgroundColor = ConsoleColor.White)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = forgroundColor;
|
Console.ForegroundColor = forgroundColor;
|
||||||
@ -27,6 +31,7 @@
|
|||||||
public class Game
|
public class Game
|
||||||
{
|
{
|
||||||
private Draw d = new Draw();
|
private Draw d = new Draw();
|
||||||
|
private Program p = new Program();
|
||||||
public void Start(Token[,] board)
|
public void Start(Token[,] board)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
@ -44,10 +49,12 @@
|
|||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case ConsoleKey.RightArrow:
|
case ConsoleKey.RightArrow:
|
||||||
pos++;
|
if (pos < board.GetLength(0) - 1)
|
||||||
|
pos++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConsoleKey.LeftArrow:
|
case ConsoleKey.LeftArrow:
|
||||||
|
if (pos > 0)
|
||||||
pos--;
|
pos--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -64,15 +71,30 @@
|
|||||||
}
|
}
|
||||||
d.DrawBoard(board);
|
d.DrawBoard(board);
|
||||||
d.DrawPlayGround(board, currentPlayer, pos);
|
d.DrawPlayGround(board, currentPlayer, pos);
|
||||||
|
p.SetColor();
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
// currentplayer est inversé
|
// currentplayer est inversé
|
||||||
if (CheckDraw(board))
|
if (CheckDraw(board))
|
||||||
Console.WriteLine("il y a eu une égalité");
|
Console.WriteLine("il y a eu une égalité");
|
||||||
else if (currentPlayer == Token.FirstPlayer)
|
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)
|
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.WriteLine("La partie à été gagnée en " + Turn(board) + " tours");
|
||||||
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Turn(Token[,] board)
|
static int Turn(Token[,] board)
|
||||||
@ -238,6 +260,7 @@
|
|||||||
|
|
||||||
public class Draw
|
public class Draw
|
||||||
{
|
{
|
||||||
|
private Program p = new Program();
|
||||||
public void DrawPlayGround(Token[,] board, Token currentPlayer, int pos)
|
public void DrawPlayGround(Token[,] board, Token currentPlayer, int pos)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < board.GetLength(0); x++)
|
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)
|
switch (token)
|
||||||
{
|
{
|
||||||
case Token.FirstPlayer:
|
case Token.FirstPlayer:
|
||||||
return 'X';
|
p.SetColor(default, p.FIRSTPLAYERCOLOR);
|
||||||
|
return "■";
|
||||||
case Token.SecondPlayer:
|
case Token.SecondPlayer:
|
||||||
return 'O';
|
p.SetColor(default, p.SECONDPLAYERCOLOR);
|
||||||
|
return "o";
|
||||||
case Token.None:
|
case Token.None:
|
||||||
return '.';
|
p.SetColor(default, ConsoleColor.DarkGray);
|
||||||
|
return "#";
|
||||||
default:
|
default:
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user