You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sae201_qwirkle/Qwirkle/QwirkleConsoleApp/Program.cs

157 lines
3.4 KiB

using QwirkleClassLibrary;
using System.Net.Quic;
using System.Text;
using System.Transactions;
using static System.Console;
static void AddPlayers(Game game)
{
while (game.PlayerList.Count < 4)
{
Write("Enter player tag : ");
string? playerTag = ReadLine();
if (game.AddPlayerInGame(playerTag) == false)
{
WriteLine("ERROR : Player already exist or game is running !");
}
else
{
WriteLine("Player " + playerTag + " added !");
}
Write("Do you want to add another player ? (y/n) : ");
string? answer = ReadLine();
if (answer == "n" && game.PlayerList.Count >= 2)
{
break;
}
if (answer == "n" && game.PlayerList.Count < 2)
{
WriteLine("ERROR : You must have at least 2 players !");
}
}
}
static void MainMenu(Game game)
{
game.GiveTilesToPlayers();
Console.ForegroundColor = ConsoleColor.Green;
WriteLine("Game is starting !");
Console.ResetColor();
do
{
string tagPlayerPlay = game.SetNextPlayer();
WriteLine(" --------------------- GAME ! ------------------------");
WriteLine(tagPlayerPlay + "'s turn !");
MenuSwitch(game);
} while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1);
}
static void ShowTiles(Game game)
{
WriteLine("\n --------------------- YOUR TILES ------------------------");
int pos = game.GetPlayingPlayerPosition();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < game.PlayerList[pos].Tiles.Count(); i++)
{
stringBuilder.Append("[" + (i+1) + "] ");
stringBuilder.AppendLine(game.PlayerList[pos].Tiles[i].ToString());
}
Write(stringBuilder);
}
static void MenuSwitch(Game game)
{
int enter = 0;
while (enter != 3)
{
ShowTiles(game);
WriteLine("\n --------------------- CHOICES ------------------------");
WriteLine("[1] Place your tiles");
WriteLine("[2] Swap your tiles");
WriteLine("[3] Skip your turn");
enter = Convert.ToInt32(ReadLine());
switch (enter)
{
case 1:
CaseOneAddTile(game);
break;
case 2:
break;
case 3:
return;
}
}
}
static void CaseOneAddTile(Game game)
{
Tile? tile = null;
Write("Enter no tile : ");
int no = Convert.ToInt32(ReadLine());
if (no >= 0 && no <= 5)
{
tile = game.TileOfPlayerWithPos(no+1);
Write("Enter x : ");
int x = Convert.ToInt32(ReadLine());
Write("Enter y : ");
int y = Convert.ToInt32(ReadLine());
if (game.PlaceTileGame(tile, x, y) == true)
{
Write("ok ! your tile is placed \n");
}
else
{
Write("ERROR : Cell already use \n");
}
}
else
{
Write("No is out of range\n");
}
}
static void MainGame()
{
Game game = new Game();
Console.ForegroundColor = ConsoleColor.DarkGreen;
WriteLine(" ===================== WELCOME TO QWIRKLE ! =====================");
WriteLine("Enter the players' nametags (2 to 4 players) : ");
Console.ResetColor();
AddPlayers(game);
game.StartGame();
MainMenu(game);
}
MainGame();