The steplayer page WORKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKQKKKKKKKKKKKKKKKKKKKKKKK (you see q ?)
continuous-integration/drone/push Build is failing Details

test_old_branch
Jérémy Mouyon 11 months ago
parent 3bd2d79300
commit 617b9a9ce8

@ -56,41 +56,69 @@ namespace QwirkleClassLibrary.Games
/// </summary> /// </summary>
/// <param name="playerTag"></param> /// <param name="playerTag"></param>
/// <returns>boolean to check it</returns> /// <returns>boolean to check it</returns>
public bool AddPlayerInGame(string? playerTag) public bool AddPlayerInGame(List<string> PlayersTag)
{ {
if (string.IsNullOrWhiteSpace(playerTag)) for (int i = PlayersTag.Count - 1; i >= 0; i--)
{ {
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The name is null or white space.")); if (string.IsNullOrWhiteSpace(PlayersTag[i]))
return false; {
PlayersTag.RemoveAt(i);
}
} }
if (GameRunning) if (PlayersTag.Count <= 1 || PlayersTag.Count > 4)
{ {
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is running.")); PlayersTag.Clear();
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : It takes a minimum of 2 players and a maximum of 4 players to start a game."));
return false; return false;
} }
for (int i = PlayersTag.Count - 1; i >= 0; i--)
if (players.Count >= 4) {
if (!CheckPlayerTag(PlayersTag, i))
{ {
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is full.")); PlayersTag.RemoveAt(i);
return false; return false;
} }
}
foreach (var p in players) foreach (var tag in PlayersTag)
{ {
if (p.NameTag == playerTag) Player pl = CreatePlayer(tag);
players.Add(pl);
scoreBoard.Add(pl, 0);
}
OnPlayerNotified(new AddPlayerNotifiedEventArgs("Players were correctly added."));
return true;
}
public bool CheckPlayerTag(List<string> PlayersTag, int pos)
{ {
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : Name alreay taken")); if (string.IsNullOrWhiteSpace(PlayersTag[pos]))
{
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR with " + (pos + 1) + " entry : The name is null or white space."));
return false; return false;
} }
if (GameRunning)
{
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR with " + (pos + 1) + " entry : The game is running."));
return false;
} }
Player pl = CreatePlayer(playerTag); for(int i=0; i<PlayersTag.Count; i++)
{
if (i == pos)
{
continue;
}
if (PlayersTag[i] == PlayersTag[pos])
{
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR with " + (pos+1) + " entry : Name alreay taken"));
return false;
}
players.Add(pl); }
scoreBoard.Add(pl, 0);
OnPlayerNotified(new AddPlayerNotifiedEventArgs("Player was correctly added"));
return true; return true;
} }

@ -1,4 +1,5 @@
using QwirkleClassLibrary.Boards; using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Events;
using QwirkleClassLibrary.Games; using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Players; using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles; using QwirkleClassLibrary.Tiles;
@ -17,28 +18,23 @@ static void AddPlayers(Game game)
NotificationClass nc = new NotificationClass(); NotificationClass nc = new NotificationClass();
game.PlayerAddNotified += nc.NotificationPlayerAdd; game.PlayerAddNotified += nc.NotificationPlayerAdd;
List<string> playerstag = [];
while (game.PlayerList.Count < 4) while (game.PlayerList.Count < 4)
{ {
Write("Enter player tag : "); Write("Enter player tag : ");
string? playerTag = ReadLine(); string? tag = ReadLine();
game.AddPlayerInGame(playerTag); playerstag.Add(tag!);
Write("Do you want to add another player ? (y/n) : "); Write("Do you want to add another player ? (y/n) : ");
string? answer = ReadLine(); string? answer = ReadLine();
if (answer == "n" && game.PlayerList.Count >= 2) if (answer == "n" && game.AddPlayerInGame(playerstag))
{ {
break; break;
} }
if (answer == "n" && game.PlayerList.Count < 2)
{
ForegroundColor = ConsoleColor.Red;
WriteLine();
WriteLine("ERROR : You must have at least 2 players !");
ResetColor();
}
} }
} }

@ -14,6 +14,7 @@ namespace Qwirkle
MainPage = new AppShell(); MainPage = new AppShell();
Routing.RegisterRoute(nameof(SetPlayers), typeof(SetPlayers)); Routing.RegisterRoute(nameof(SetPlayers), typeof(SetPlayers));
Routing.RegisterRoute(nameof(Gameboard), typeof(Gameboard));
} }

@ -26,8 +26,6 @@
InfoClicked="OnInfoClicked" InfoClicked="OnInfoClicked"
/> />
<!-- <controls:ButtonShadow Text="{Binding button2.Text}"/> -->
<controls:ButtonShadow Text="Leaderboard"/> <controls:ButtonShadow Text="Leaderboard"/>
<controls:ButtonShadow Text="Rules"/> <controls:ButtonShadow Text="Rules"/>

@ -46,16 +46,15 @@ public partial class SetPlayers : ContentPage
{ {
game.PlayerAddNotified += Game_PlayerAddNotified; game.PlayerAddNotified += Game_PlayerAddNotified;
string entry1 = Entry1.TextIn!; List<string> playerstag = [Entry1.TextIn!, Entry2.TextIn!, Entry3.TextIn!, Entry3.TextIn!];
string entry2 = Entry2.TextIn!;
string entry3 = Entry3.TextIn!; if (game.AddPlayerInGame(playerstag))
string entry4 = Entry4.TextIn!; {
DisplayAlert("Game notification", entry1 + "\n" + entry2 + "\n" + entry3 + "\n" + entry4, "Ok ! Lets's go !"); Navigation.PushAsync(new Gameboard());
}
game.PlayerAddNotified -= Game_PlayerAddNotified;
game.AddPlayerInGame(entry1);
game.AddPlayerInGame(entry2);
game.AddPlayerInGame(entry3);
game.AddPlayerInGame(entry4);
} }
private void Game_PlayerAddNotified(object? sender, QwirkleClassLibrary.Events.AddPlayerNotifiedEventArgs args) private void Game_PlayerAddNotified(object? sender, QwirkleClassLibrary.Events.AddPlayerNotifiedEventArgs args)

@ -8,33 +8,30 @@ namespace TestBase;
public class TestGame public class TestGame
{ {
[Theory] [Theory]
[InlineData(true, false, "testt")] [InlineData(true, false, "test", "test1")]
[InlineData(false, false, "testt")] [InlineData(false, false, "test", "test1")]
[InlineData(false, true, "testt")] [InlineData(false, true, "test", "test1")]
public void Test_GameAddPlayerIngame(bool result, bool gamestate, string p) public void Test_GameAddPlayerIngame(bool result, bool gamestate, string p1, string p2)
{ {
Game game = new Game(); Game game = new Game();
List<string> players = [p1, p2];
if (!result) if (!result)
{ {
game.AddPlayerInGame(p); game.AddPlayerInGame(players);
Assert.False(game.AddPlayerInGame(p)); Assert.False(game.AddPlayerInGame(players));
} }
else else
{ {
Assert.True(game.AddPlayerInGame(p)); Assert.True(game.AddPlayerInGame(players));
} }
if (gamestate) if (gamestate)
{ {
game.StartGame(); game.StartGame();
Assert.False(game.AddPlayerInGame(p)); Assert.False(game.AddPlayerInGame(players));
} }
} }
[Theory] [Theory]
@ -43,21 +40,32 @@ public class TestGame
public void Test_GameAddPlayerIngame2(bool result, string p) public void Test_GameAddPlayerIngame2(bool result, string p)
{ {
Game game = new Game(); Game game = new Game();
List<string> players = new List<string>();
if (!result) if (!result)
{ {
Assert.False(game.AddPlayerInGame(p)); players.Add(p);
Assert.False(game.AddPlayerInGame(players));
} }
players.Clear();
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
string name = p + i; string name = p + i;
game.AddPlayerInGame(name); players.Add(name);
}
Assert.True(game.AddPlayerInGame(players));
} }
Assert.False(game.AddPlayerInGame(p));
[Fact]
public void Test_AddPlayers()
{
Game game = new Game();
List<string> playerstest = new List<string> { "test", "test1" };
Assert.True(game.AddPlayerInGame(playerstest));
} }
[Theory] [Theory]
[InlineData("test")] [InlineData("test")]
public void Test_GameCreatePlayers(string p) public void Test_GameCreatePlayers(string p)
@ -79,8 +87,8 @@ public class TestGame
game.StartGame(); game.StartGame();
Assert.False(game.GameRunning); Assert.False(game.GameRunning);
} }
game.AddPlayerInGame(p1); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame(p2); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
Assert.True(game.GameRunning); Assert.True(game.GameRunning);
@ -93,9 +101,8 @@ public class TestGame
public void Test_GameGetPlayingPlayerPosition(bool result, string p1, string p2, string p3) public void Test_GameGetPlayingPlayerPosition(bool result, string p1, string p2, string p3)
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame(p1); List<string> playerstest = ["test", "test1", "test2"];
game.AddPlayerInGame(p2); game.AddPlayerInGame(playerstest);
game.AddPlayerInGame(p3);
if (!result) if (!result)
{ {
@ -113,8 +120,8 @@ public class TestGame
public void Test_GameGetPlaylingPlayer(bool result) public void Test_GameGetPlaylingPlayer(bool result)
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("patrick"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("jean"); game.AddPlayerInGame(playerstest);
if (!result) if (!result)
{ {
Assert.Throws<ArgumentException>(() => game.GetPlayingPlayer()); Assert.Throws<ArgumentException>(() => game.GetPlayingPlayer());
@ -130,8 +137,8 @@ public class TestGame
public void Test_BoardReturn() public void Test_BoardReturn()
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer();
@ -144,8 +151,8 @@ public class TestGame
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer();
@ -164,8 +171,8 @@ public class TestGame
public void Test_TileOfPlayer() public void Test_TileOfPlayer()
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer();
@ -181,8 +188,8 @@ public class TestGame
public void Test_SetFirstPlayer(bool except) public void Test_SetFirstPlayer(bool except)
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
if (except) if (except)
{ {
@ -201,8 +208,8 @@ public class TestGame
public void Test_Setnextplayer(bool except) public void Test_Setnextplayer(bool except)
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
if (except) if (except)
{ {
@ -224,8 +231,8 @@ public class TestGame
public void Test_PlaceTile(bool except) public void Test_PlaceTile(bool except)
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
if (except) if (except)
{ {
@ -247,7 +254,7 @@ public class TestGame
// { // {
// Game game = new Game(); // Game game = new Game();
// game.AddPlayerInGame("Test1"); // game.AddPlayerInGame("Test1");
// game.AddPlayerInGame("Test2"); // game.AddPlayerInGame(playerstest);
// //
// game.StartGame(); // game.StartGame();
// game.SetNextPlayer(); // game.SetNextPlayer();
@ -267,8 +274,8 @@ public class TestGame
public void Test_SwapTiles(bool except) public void Test_SwapTiles(bool except)
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetNextPlayer(); game.SetNextPlayer();
@ -302,8 +309,8 @@ public class TestGame
public void Test_IsMoveCorrectOne(bool except) public void Test_IsMoveCorrectOne(bool except)
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetNextPlayer(); game.SetNextPlayer();
@ -328,8 +335,8 @@ public class TestGame
public void Test_IsMoveCorrectSixLine() public void Test_IsMoveCorrectSixLine()
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetNextPlayer(); game.SetNextPlayer();
@ -392,8 +399,9 @@ public class TestGame
public void Test_EndOfGame() public void Test_EndOfGame()
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1");
game.AddPlayerInGame("Test2"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer();
@ -406,8 +414,8 @@ public class TestGame
public void Test_ClearGame() public void Test_ClearGame()
{ {
Game game = new Game(); Game game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer();
@ -421,3 +429,4 @@ public class TestGame
} }

@ -17,8 +17,8 @@ public class TestLeaderboard
var leaderboard = new Leaderboard(); var leaderboard = new Leaderboard();
var game = new Game(); var game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer();
@ -37,8 +37,8 @@ public class TestLeaderboard
var leaderboard = new Leaderboard(); var leaderboard = new Leaderboard();
var game = new Game(); var game = new Game();
game.AddPlayerInGame("Test1"); List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame("Test2"); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer();
@ -50,8 +50,7 @@ public class TestLeaderboard
var game2 = new Game(); var game2 = new Game();
game.AddPlayerInGame("Test1"); game.AddPlayerInGame(playerstest);
game.AddPlayerInGame("Test2");
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer();

Loading…
Cancel
Save