Merge branch 'master' of https://codefirst.iut.uca.fr/git/jeremy.mouyon/sae201_qwirkle
continuous-integration/drone/push Build is failing Details

test_old_branch
Jérémy Mouyon 11 months ago
commit 6067b0e54b

File diff suppressed because one or more lines are too long

@ -1 +1,16 @@
{"leaderboard":[]}
{
"leaderboard": [
{
"Date": "\/Date(1717432093871+0200)\/",
"PlayerName": "Jérémy",
"Points": 30,
"Victories": 2
},
{
"Date": "\/Date(1717432093871+0200)\/",
"PlayerName": "Jules",
"Points": 4,
"Victories": 0
}
]
}

@ -1,13 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Collections.ObjectModel;
using System.Security.Cryptography;
using System.Collections;
using System.Collections.Immutable;
using System.Runtime.Serialization;
using QwirkleClassLibrary.Tiles;
using QwirkleClassLibrary.Boards;
@ -21,13 +13,13 @@ namespace QwirkleClassLibrary.Games
public class Game : IPlayer, IRules
{
[DataMember]
public TileBag? bag = null;
private TileBag? bag = null;
[DataMember]
public bool GameRunning { get; set; }
[DataMember]
private Board board = new Board(15, 12);
private Board board = new(15, 12);
public bool PlayerSwapping { get; set; }
public Board Board => board;
@ -35,15 +27,15 @@ namespace QwirkleClassLibrary.Games
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
[DataMember]
private readonly List<Player> players = new();
private readonly List<Player> players = [];
[DataMember]
private readonly Dictionary<Player, int> scoreBoard = new();
private readonly Dictionary<Player, int> scoreBoard = [];
public ReadOnlyDictionary<Player, int> ScoreBoard => scoreBoard.AsReadOnly();
[DataMember]
private readonly List<Cell> cellUsed = new();
private readonly List<Cell> cellUsed = [];
public ReadOnlyCollection<Cell> CellsUsed => cellUsed.AsReadOnly();
@ -270,7 +262,7 @@ namespace QwirkleClassLibrary.Games
{
if (bag != null && p.Tiles.Count < 6)
{
int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count);
int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag!.Count);
p.AddTileToPlayer(bag.TilesBag[val]);
bag.RemoveTileInBag(bag.TilesBag[val]);
@ -362,7 +354,7 @@ namespace QwirkleClassLibrary.Games
{
while (player.Tiles.Count < 6)
{
if (bag!.TilesBag.Count == 0)
if (bag!.TilesBag!.Count == 0)
{
return false;
}
@ -384,13 +376,19 @@ namespace QwirkleClassLibrary.Games
/// <returns>bool</returns>
public bool SwapTiles(Player player, List<Tile> tilesToSwap)
{
if (cellUsed.Count != 0)
{
OnSwapTiles(new SwapTilesNotifiedEventArgs("You can't swap tiles after placing some !"));
return false;
}
if (tilesToSwap.Count == 0)
{
OnSwapTiles(new SwapTilesNotifiedEventArgs("You must select at least one tile to swap !"));
return false;
}
if (bag!.TilesBag.Count < tilesToSwap.Count)
if (bag!.TilesBag!.Count < tilesToSwap.Count)
{
OnSwapTiles(new SwapTilesNotifiedEventArgs("Not enough tiles in the bag to swap !"));
return false;
@ -719,7 +717,7 @@ namespace QwirkleClassLibrary.Games
{
List<int> playerTilesBagPos = [];
if (bag!.TilesBag.Count == 0)
if (bag!.TilesBag!.Count == 0)
{
for (int i = 0; i < players.Count; i++)
{
@ -771,7 +769,7 @@ namespace QwirkleClassLibrary.Games
{
List<int> playerTilesBagPos = CheckTilesBag();
if (playerTilesBagPos.Count != 0 && !CheckPlacementPossibilities(playerTilesBagPos) || bag!.TilesBag.Count == 0 && players[GetPlayingPlayerPosition()].Tiles.Count==0)
if (playerTilesBagPos.Count != 0 && !CheckPlacementPossibilities(playerTilesBagPos) || bag!.TilesBag!.Count == 0 && players[GetPlayingPlayerPosition()].Tiles.Count==0)
{
OnEndOfGame(new EndOfGameNotifiedEventArgs(player));
GameRunning = false;

@ -20,9 +20,17 @@ public class GamePersistenceXml : IGamePersistence
{
var serializer = new DataContractSerializer(typeof(Game));
using (Stream reader = File.OpenRead("Game.xml"))
try
{
return serializer.ReadObject(reader) as Game ?? throw new InvalidOperationException();
using (Stream reader = File.OpenRead("Game.xml"))
{
var newGame = serializer.ReadObject(reader) as Game;
return newGame!;
}
}
catch
{
return new Game();
}
}
}

@ -41,7 +41,7 @@ namespace QwirkleClassLibrary.Players
/// <param name="scoreBoard"></param>
public void AddScoreInLead(ReadOnlyDictionary<Player, int> scoreBoard)
{
DateTime now = DateTime.Today;
DateTime now = DateTime.Now;
bool first = true;
var sb = scoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag);
@ -59,7 +59,10 @@ namespace QwirkleClassLibrary.Players
leaderboard[i].Victories++;
}
leaderboard[i].Points = pair.Value;
if (pair.Value > leaderboard[i].Points)
{
leaderboard[i].Points = pair.Value;
}
}
else

@ -37,7 +37,7 @@ namespace QwirkleClassLibrary.Players
}
NameTag = name;
Tiles = new ObservableCollection<Tile>();
Tiles = [];
}
[DataMember]

@ -12,9 +12,9 @@ namespace QwirkleClassLibrary.Tiles
public class TileBag
{
[DataMember]
private readonly List<Tile> tiles = new List<Tile>();
private readonly List<Tile> tiles = [];
public ReadOnlyCollection<Tile> TilesBag { get; private set; }
public ReadOnlyCollection<Tile>? TilesBag { get; private set; }
/// <summary>
@ -35,7 +35,7 @@ namespace QwirkleClassLibrary.Tiles
{
foreach (Color c in Enum.GetValues(typeof(Color)))
{
Tile t = new Tile(s, c);
Tile t = new(s, c);
tiles.Add(t);
}
}

@ -1,17 +1,9 @@
using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Events;
using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles;
using QwirkleConsoleApp;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Diagnostics.Metrics;
using System.Net.Quic;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Transactions;
using QwirkleClassLibrary.Persistences;
using static System.Console;
@ -407,12 +399,10 @@ static void MainGame()
game.StartGame();
MainMenu(game);
foreach (var player in game.PlayerList)
if (!game.GameRunning)
{
if (game.CheckGameOver(player))
{
leaderboard.AddScoreInLead(game.ScoreBoard);
}
leaderboard.AddScoreInLead(game.ScoreBoard);
break;
}
ILeaderboardPersistence leaderboardSave = new LeaderboardPersistenceJson();
@ -424,17 +414,50 @@ static void MainGame()
Game loadedGame;
IGamePersistence gameLoad = new GamePersistenceXml();
loadedGame = gameLoad.LoadGame();
try
{
loadedGame = gameLoad.LoadGame();
}
catch
{
ForegroundColor = ConsoleColor.Yellow;
WriteLine("WARNING : No game saved ! Creating a new game !");
ResetColor();
loadedGame = new Game();
}
ILeaderboardPersistence leaderboardLoad = new LeaderboardPersistenceJson();
leaderboard = leaderboardLoad.LoadLeaderboard();
MainMenuContinue(loadedGame);
leaderboard.AddScoreInLead(loadedGame.ScoreBoard);
if (loadedGame.GameRunning)
{
MainMenuContinue(loadedGame);
}
else
{
loadedGame = new Game();
ForegroundColor = ConsoleColor.Yellow;
WriteLine("WARNING : The previous saved game was over ! Creating a new game !");
ResetColor();
AddPlayers(loadedGame);
loadedGame.StartGame();
MainMenu(loadedGame);
}
if (!loadedGame.GameRunning)
{
leaderboard.AddScoreInLead(loadedGame.ScoreBoard);
}
ILeaderboardPersistence leaderboardSave2 = new LeaderboardPersistenceJson();
leaderboardSave2.SaveLeaderboard(leaderboard);
break;
case 3:
ILeaderboardPersistence leaderboardLoad2 = new LeaderboardPersistenceJson();
leaderboard = leaderboardLoad2.LoadLeaderboard();
ShowLeaderboard(leaderboard);
break;

@ -7,14 +7,14 @@ public class TestPlayers
[Theory]
[InlineData(true, "Mathis")]
[InlineData(false, null)]
public void Test_CreatePlayer(bool isValid, string playertag)
public void Test_CreatePlayer(bool isValid, string? playertag)
{
if (!isValid)
{
Assert.Throws<ArgumentNullException>(() => new Player(playertag));
Assert.Throws<ArgumentNullException>(() => new Player(playertag!));
return;
}
Player player = new Player(playertag);
Player player = new Player(playertag!);
Assert.Equal(playertag, player.NameTag);
}

@ -16,7 +16,7 @@ public class TestTileBag
return;
}
TileBag bag = new TileBag(nbset);
Assert.Equal(bag.TilesBag.Count, nbset * 36);
Assert.Equal(bag.TilesBag!.Count, nbset * 36);
}
@ -30,11 +30,11 @@ public class TestTileBag
if (except)
{
Assert.True(bag.RemoveTileInBag(bag.TilesBag[1]));
Assert.True(bag.RemoveTileInBag(bag.TilesBag![1]));
return;
}
Tile tile = bag.TilesBag[0];
Tile tile = bag.TilesBag![0];
bag.RemoveTileInBag(tile);
Assert.False(bag.RemoveTileInBag(tile));

Loading…
Cancel
Save