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

150 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 ShowTiles(Game game)
{
WriteLine("\n --------------------- YOUR TILES ------------------------");
var currentPlayer = game.GetPlayingPlayer();
var stringBuilder = new StringBuilder();
for (int i = 0; i < currentPlayer.Tiles.Count(); i++)
{
stringBuilder.Append("[" + (i+1) + "] ");
stringBuilder.AppendLine(currentPlayer.Tiles[i].ToString());
}
Write(stringBuilder);
}
static void AddTile(Game game)
{
Tile? tile = null;
Write("Enter the number of the tile you want to place : ");
int no = Convert.ToInt32(ReadLine());
while (no < 1 || no > 6)
{
Write("ERROR : Enter a number between 1 and 6 ! : ");
no = Convert.ToInt32(ReadLine());
}
tile = game.TileOfPlayerWithPos(no - 1);
Write("Enter the x of the cell: ");
int x = Convert.ToInt32(ReadLine());
Write("Enter the y of the cell : ");
int y = Convert.ToInt32(ReadLine());
if (game.PlaceTile(game.GetPlayingPlayer(), tile, x, y) == true)
{
WriteLine("ok ! your tile is placed");
}
else
{
WriteLine("ERROR : Cell already used");
}
}
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:
AddTile(game);
break;
case 2:
break;
case 3:
return;
}
}
}
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 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();