using QwirkleClassLibrary; using QwirkleConsoleApp; using System.Collections.Immutable; using System.Collections.ObjectModel; using System.Diagnostics.Metrics; 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 = -1; int x = -1; int y = -1; try { while (no is < 1 or > 6) { Write("ERROR : Enter a number between 1 and 6 ! : "); no = Convert.ToInt32(ReadLine()); } } catch { WriteLine("ERROR : You must type. Please retry : "); } tile = game.TileOfPlayerWithPos(no - 1); Write("Enter the x of the cell: "); try { x = Convert.ToInt32(ReadLine()); } catch { WriteLine("ERROR : You must type. Please retry : "); } Write("Enter the y of the cell: "); try { y = Convert.ToInt32(ReadLine()); } catch { WriteLine("ERROR : You must type. Please retry : "); } game.PlaceTile(game.GetPlayingPlayer(), tile, x, y); 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"); Write("Enter your choice : "); 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(); game.DrawTiles(game.GetPlayingPlayer()); return; } } } static void ShowBoard(Game game) { Board board = game.GetBoard(); 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; if (tile != null) { Console.Write("| " + tile.GetShape.ToString()[0] + tile.GetShape.ToString()[1] + tile.GetColor.ToString()[0] + " |"); } } else { Console.Write("| |"); } } Console.WriteLine(); } } static void ShowScoreBoard(Game g) { int i = 0; foreach (KeyValuePair pair in g.ScoreBoard) { i++; WriteLine("[" + i + "] " + pair.Key.NameTag + " with " + pair.Value.ToString() + " points."); } } static void MainMenu(Game game) { game.GiveTilesToPlayers(); Console.ForegroundColor = ConsoleColor.Green; WriteLine("Game is starting !"); Console.ResetColor(); do { NotificationClass nc = new NotificationClass(); game.NextPlayerNotified += nc.NotificationNextPlayer; game.EndOfGameNotified += nc.NotificationEndOfGame; game.SetNextPlayer(); WriteLine(" --------------------- GAME ! ------------------------"); MenuSwitch(game); game.NextPlayerNotified -= nc.NotificationNextPlayer; } while (game.GameRunning); WriteLine(" --------------------- END OF GAME ! ------------------------"); WriteLine(" --------------------- THE BOARD : --------------------------"); ShowBoard(game); WriteLine(" --------------------- THE SCORE BOARD : ---------------------"); ShowScoreBoard(game); } static void MainGame() { Console.ForegroundColor = ConsoleColor.DarkGray; WriteLine(" ===================== WELCOME TO QWIRKLE ! ====================="); Console.ResetColor(); int enter = 0; while (enter != 3) { WriteLine("[1] Create game"); WriteLine("[2] Show leaderboard"); WriteLine("[3] Exit"); Write("Enter your choice : "); try { enter = Convert.ToInt32(ReadLine()); } catch { WriteLine("ERROR : You must type (1 / 2 / 3). Please retry : "); } switch (enter) { case 1: WriteLine("Enter minimun 2 player and max 4 player !"); Game game = new Game(); AddPlayers(game); game.StartGame(); MainMenu(game); break; case 2: //ShowLeaderboard(); break; case 3: return; } } } MainGame();