|
|
|
@ -173,7 +173,7 @@ static void MenuSwitch(Game game)
|
|
|
|
|
{
|
|
|
|
|
int enter = 0;
|
|
|
|
|
|
|
|
|
|
while (enter != 3)
|
|
|
|
|
while (enter != 3 && game.GameRunning)
|
|
|
|
|
{
|
|
|
|
|
ShowBoard(game);
|
|
|
|
|
|
|
|
|
@ -186,6 +186,7 @@ static void MenuSwitch(Game game)
|
|
|
|
|
WriteLine("[1] Place your tiles");
|
|
|
|
|
WriteLine("[2] Swap your tiles");
|
|
|
|
|
WriteLine("[3] End your turn / Skip your turn");
|
|
|
|
|
WriteLine("[4] Save the game");
|
|
|
|
|
Write("Enter your choice : ");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
@ -215,7 +216,23 @@ static void MenuSwitch(Game game)
|
|
|
|
|
game.EmptyCellUsed();
|
|
|
|
|
game.DrawTiles(game.GetPlayingPlayer());
|
|
|
|
|
game.CheckGameOver(game.GetPlayingPlayer());
|
|
|
|
|
|
|
|
|
|
var inGameSerializer = new DataContractJsonSerializer(typeof(Game));
|
|
|
|
|
using (Stream s = File.Create("game.json"))
|
|
|
|
|
{
|
|
|
|
|
inGameSerializer.WriteObject(s, game);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
case 4:
|
|
|
|
|
var postGameSerializer = new DataContractJsonSerializer(typeof(Game));
|
|
|
|
|
using (Stream s = File.Create("game.json"))
|
|
|
|
|
{
|
|
|
|
|
postGameSerializer.WriteObject(s, game);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
game.GameRunning = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -231,20 +248,20 @@ static void ShowBoard(Game game)
|
|
|
|
|
Cell? cell = board.GetCell(y, i);
|
|
|
|
|
if (cell != null && !cell.IsFree)
|
|
|
|
|
{
|
|
|
|
|
Tile? tile = cell.GetTile;
|
|
|
|
|
Tile? tile = cell.Tile;
|
|
|
|
|
if (tile != null)
|
|
|
|
|
{
|
|
|
|
|
Console.Write("| " + tile.GetShape.ToString()[0] + tile.GetShape.ToString()[1] +
|
|
|
|
|
Write("| " + tile.GetShape.ToString()[0] + tile.GetShape.ToString()[1] +
|
|
|
|
|
tile.GetColor.ToString()[0] + " |");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.Write("| |");
|
|
|
|
|
Write("| |");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
WriteLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -281,9 +298,9 @@ static void MainMenu(Game game)
|
|
|
|
|
{
|
|
|
|
|
game.GiveTilesToPlayers();
|
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
|
|
|
ForegroundColor = ConsoleColor.Green;
|
|
|
|
|
WriteLine("Game is starting !");
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
ResetColor();
|
|
|
|
|
|
|
|
|
|
NotificationClass nc = new NotificationClass();
|
|
|
|
|
|
|
|
|
@ -309,12 +326,40 @@ static void MainMenu(Game game)
|
|
|
|
|
ShowScoreBoard(game);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MainMenuContinue(Game game)
|
|
|
|
|
{
|
|
|
|
|
ForegroundColor = ConsoleColor.Green;
|
|
|
|
|
WriteLine("Game loaded ! You can continue the game !");
|
|
|
|
|
ResetColor();
|
|
|
|
|
|
|
|
|
|
NotificationClass nc = new NotificationClass();
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
game.NextPlayerNotified += nc.NotificationNextPlayer;
|
|
|
|
|
game.EndOfGameNotified += nc.NotificationEndOfGame;
|
|
|
|
|
|
|
|
|
|
game.SetNextPlayer();
|
|
|
|
|
|
|
|
|
|
WriteLine(" --------------------- GAME ! ------------------------");
|
|
|
|
|
|
|
|
|
|
MenuSwitch(game);
|
|
|
|
|
|
|
|
|
|
game.NextPlayerNotified -= nc.NotificationNextPlayer;
|
|
|
|
|
game.EndOfGameNotified -= nc.NotificationEndOfGame;
|
|
|
|
|
|
|
|
|
|
} while (game.GameRunning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void MainGame()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\..\\..\\Files"));
|
|
|
|
|
|
|
|
|
|
Leaderboard leaderboard = new Leaderboard();
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
|
|
|
|
|
|
|
|
|
ForegroundColor = ConsoleColor.DarkGray;
|
|
|
|
|
WriteLine(" ===================== WELCOME TO QWIRKLE ! =====================");
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
ResetColor();
|
|
|
|
|
|
|
|
|
|
int enter = 0;
|
|
|
|
|
|
|
|
|
@ -322,8 +367,9 @@ static void MainGame()
|
|
|
|
|
{
|
|
|
|
|
ForegroundColor = ConsoleColor.DarkCyan;
|
|
|
|
|
WriteLine("[1] Create game");
|
|
|
|
|
WriteLine("[2] Show leaderboard");
|
|
|
|
|
WriteLine("[3] Exit");
|
|
|
|
|
WriteLine("[2] Load game");
|
|
|
|
|
WriteLine("[3] Show leaderboard");
|
|
|
|
|
WriteLine("[4] Exit");
|
|
|
|
|
WriteLine();
|
|
|
|
|
ResetColor();
|
|
|
|
|
WriteLine("Enter your choice : ");
|
|
|
|
@ -347,47 +393,52 @@ static void MainGame()
|
|
|
|
|
ForegroundColor = ConsoleColor.DarkYellow;
|
|
|
|
|
WriteLine("Enter minimun 2 player and max 4 player !\n");
|
|
|
|
|
ResetColor();
|
|
|
|
|
|
|
|
|
|
Game game = new Game();
|
|
|
|
|
AddPlayers(game);
|
|
|
|
|
|
|
|
|
|
game.StartGame();
|
|
|
|
|
MainMenu(game);
|
|
|
|
|
|
|
|
|
|
leaderboard.AddScoreInLead(game.ScoreBoard);
|
|
|
|
|
|
|
|
|
|
var leaderboardSerializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
|
|
|
|
using (Stream s = File.Create("LeaderBoard.json "))
|
|
|
|
|
{
|
|
|
|
|
leaderboardSerializer.WriteObject(s, leaderboard);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
ShowLeaderboard(leaderboard);
|
|
|
|
|
break;
|
|
|
|
|
Game loadedGame;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
return;
|
|
|
|
|
var serializer = new DataContractJsonSerializer(typeof(Game));
|
|
|
|
|
using (Stream s = File.OpenRead("game.json"))
|
|
|
|
|
{
|
|
|
|
|
loadedGame = (serializer.ReadObject(s) as Game)!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var loadedLeaderboardSerializer = new DataContractJsonSerializer(typeof(Leaderboard));
|
|
|
|
|
using (Stream s = File.OpenRead("leaderboard.json"))
|
|
|
|
|
{
|
|
|
|
|
leaderboard = (loadedLeaderboardSerializer.ReadObject(s) as Leaderboard)!;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MainGame();
|
|
|
|
|
|
|
|
|
|
var game = new Game();
|
|
|
|
|
game.AddPlayerInGame(["Player1", "Player2", "Player3", "Player4"]);
|
|
|
|
|
|
|
|
|
|
game.StartGame();
|
|
|
|
|
game.SetNextPlayer();
|
|
|
|
|
MainMenuContinue(loadedGame);
|
|
|
|
|
leaderboard.AddScoreInLead(loadedGame.ScoreBoard);
|
|
|
|
|
|
|
|
|
|
game.PlaceTile(game.GetPlayingPlayer(), new Tile(Shape.Round, Color.Blue), 0, 0);
|
|
|
|
|
game.PlaceTile(game.GetPlayingPlayer(), new Tile(Shape.Square, Color.Blue), 0, 1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\..\\..\\Files"));
|
|
|
|
|
case 3:
|
|
|
|
|
ShowLeaderboard(leaderboard);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
var serializer = new DataContractJsonSerializer(typeof(Game));
|
|
|
|
|
using (Stream s = File.Create("game.json"))
|
|
|
|
|
{
|
|
|
|
|
serializer.WriteObject(s, game);
|
|
|
|
|
case 4:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Game game2;
|
|
|
|
|
using (Stream s = File.OpenRead("game.json"))
|
|
|
|
|
{
|
|
|
|
|
game2 = (serializer.ReadObject(s) as Game)!;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteLine(game2.GetBoard()!.GetCell(0, 0)!.GetTile);
|
|
|
|
|
MainGame();
|