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.
226 lines
5.2 KiB
226 lines
5.2 KiB
using QwirkleClassLibrary;
|
|
using QwirkleConsoleApp;
|
|
using System.Net.Quic;
|
|
using System.Text;
|
|
using System.Transactions;
|
|
using static System.Console;
|
|
|
|
|
|
static void AddPlayers(Game game)
|
|
{
|
|
NotificationClass nc = new NotificationClass();
|
|
game.PlayerAddNotified += nc.NotificationPlayerAdd;
|
|
|
|
while (game.PlayerList.Count < 4)
|
|
{
|
|
Write("Enter player tag : ");
|
|
string? playerTag = ReadLine();
|
|
|
|
game.AddPlayerInGame(playerTag);
|
|
|
|
|
|
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)
|
|
{
|
|
|
|
NotificationClass nc = new NotificationClass();
|
|
|
|
game.PlaceTileNotified += nc.NotificationAddTile;
|
|
|
|
Tile? tile = null;
|
|
Write("Enter the number of the tile you want to place : ");
|
|
int no = Convert.ToInt32(ReadLine());
|
|
|
|
while (no is < 1 or > 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.IsMoveCorrect(tile, x, y, game.GetBoard()) == true)
|
|
{
|
|
if (game.PlaceTile(game.GetPlayingPlayer(), tile, x, y) == true)
|
|
{
|
|
WriteLine("ok ! your tile is placed");
|
|
|
|
}*/
|
|
|
|
game.IsMoveCorrect(tile, x, y, game.GetBoard());
|
|
game.PlaceTileNotified -= nc.NotificationAddTile;
|
|
}
|
|
|
|
static void SwapTile(Game game)
|
|
{
|
|
var tilesToSwap = new List<Tile>();
|
|
bool continueSwap = true;
|
|
|
|
ShowTiles(game);
|
|
|
|
while (continueSwap == true)
|
|
{
|
|
Write("Enter the number of the tile you want to swap : ");
|
|
int no = Convert.ToInt32(ReadLine());
|
|
|
|
if (no is < 1 or > 6)
|
|
{
|
|
WriteLine("ERROR : Enter a number between 1 and 6 !");
|
|
}
|
|
else
|
|
{
|
|
tilesToSwap.Add(game.TileOfPlayerWithPos(no - 1));
|
|
}
|
|
|
|
Write("Do you want to swap another tile ? (y/n) : ");
|
|
string? answer = ReadLine();
|
|
|
|
if (answer == "n")
|
|
{
|
|
continueSwap = false;
|
|
}
|
|
}
|
|
|
|
game.SwapTiles(game.GetPlayingPlayer(), tilesToSwap);
|
|
}
|
|
|
|
static void MenuSwitch(Game game)
|
|
{
|
|
int enter = 0;
|
|
|
|
while (enter != 3)
|
|
{
|
|
ShowBoard(game);
|
|
|
|
ShowTiles(game);
|
|
|
|
WriteLine("\n --------------------- CHOICES ------------------------");
|
|
|
|
WriteLine("[1] Place your tiles");
|
|
WriteLine("[2] Swap your tiles");
|
|
WriteLine("[3] Skip your turn");
|
|
|
|
try
|
|
{
|
|
enter = Convert.ToInt32(ReadLine());
|
|
}
|
|
catch {
|
|
WriteLine("ERROR : You must type (1 / 2 / 3). Please retry : ");
|
|
}
|
|
|
|
|
|
switch (enter)
|
|
{
|
|
case 1:
|
|
AddTile(game);
|
|
break;
|
|
case 2:
|
|
SwapTile(game);
|
|
enter = 3;
|
|
break;
|
|
case 3:
|
|
game.EmptyCellUsed();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void ShowBoard(Game game)
|
|
{
|
|
Board board = game.GetBoard();
|
|
List<Cell> cells = board.GetCells();
|
|
|
|
for(int i = 0; i<board.Rows; i++)
|
|
{
|
|
for(int y = 0; y<board.Columns; y++)
|
|
{
|
|
if(board.GetCell(y, i)!.IsFree == false)
|
|
{
|
|
Tile? tile = board.GetCell(y, i)?.GetTile;
|
|
Console.Write("| " + tile.GetShape.ToString()[0] + tile.GetShape.ToString()[1] + tile.GetColor.ToString()[0] + " |");
|
|
}
|
|
else
|
|
{
|
|
Console.Write("| |");
|
|
}
|
|
}
|
|
Console.WriteLine();
|
|
}
|
|
}
|
|
|
|
static void MainMenu(Game game)
|
|
{
|
|
game.GiveTilesToPlayers();
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
WriteLine("Game is starting !");
|
|
Console.ResetColor();
|
|
|
|
NotificationClass nc = new NotificationClass();
|
|
game.NextPlayerNotified += nc.NotificationNextPlayer;
|
|
|
|
do
|
|
{
|
|
game.SetNextPlayer();
|
|
|
|
WriteLine(" --------------------- GAME ! ------------------------");
|
|
|
|
game.DrawTiles(game.GetPlayingPlayer());
|
|
MenuSwitch(game);
|
|
|
|
} while (game.IsGameOver()); //while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1);
|
|
}
|
|
|
|
static void MainGame()
|
|
{
|
|
Game game = new Game();
|
|
|
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
|
WriteLine(" ===================== WELCOME TO QWIRKLE ! =====================");
|
|
WriteLine("Enter the players' nametags (2 to 4 players) : ");
|
|
Console.ResetColor();
|
|
|
|
AddPlayers(game);
|
|
|
|
game.StartGame();
|
|
|
|
MainMenu(game);
|
|
}
|
|
|
|
MainGame(); |