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.AddCellUsed(game.GetBoard().GetCell(x, y)); } else { WriteLine("ERROR : Cell already used"); } } else { WriteLine("ERROR : Move not correct"); } /* game.IsMoveCorrect(tile, x, y, game.GetBoard()); game.PlaceTileNotified -= nc.NotificationAddTile;*/ } static void SwapTile(Game game) { var tilesToSwap = new List(); bool continueSwap = true; ShowTiles(game); while (continueSwap) { 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] End your turn / 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: WriteLine("Your score on this turn : " + game.GetPlayerScore(game.GetPlayingPlayer(), game.CellsUsed, game.GetBoard())); game.EmptyCellUsed(); return; } } } static void ShowBoard(Game game) { Board board = game.GetBoard(); for(int i = 0; i