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>
/// <param name="playerTag"></param>
/// <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."));
return false;
if (string.IsNullOrWhiteSpace(PlayersTag[i]))
{
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;
}
if (players.Count >= 4)
for (int i = PlayersTag.Count - 1; i >= 0; i--)
{
if (!CheckPlayerTag(PlayersTag, i))
{
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is full."));
PlayersTag.RemoveAt(i);
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;
}
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;
}

@ -1,4 +1,5 @@
using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Events;
using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles;
@ -17,28 +18,23 @@ static void AddPlayers(Game game)
NotificationClass nc = new NotificationClass();
game.PlayerAddNotified += nc.NotificationPlayerAdd;
List<string> playerstag = [];
while (game.PlayerList.Count < 4)
{
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) : ");
string? answer = ReadLine();
if (answer == "n" && game.PlayerList.Count >= 2)
if (answer == "n" && game.AddPlayerInGame(playerstag))
{
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();
Routing.RegisterRoute(nameof(SetPlayers), typeof(SetPlayers));
Routing.RegisterRoute(nameof(Gameboard), typeof(Gameboard));
}

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

@ -46,16 +46,15 @@ public partial class SetPlayers : ContentPage
{
game.PlayerAddNotified += Game_PlayerAddNotified;
string entry1 = Entry1.TextIn!;
string entry2 = Entry2.TextIn!;
string entry3 = Entry3.TextIn!;
string entry4 = Entry4.TextIn!;
DisplayAlert("Game notification", entry1 + "\n" + entry2 + "\n" + entry3 + "\n" + entry4, "Ok ! Lets's go !");
List<string> playerstag = [Entry1.TextIn!, Entry2.TextIn!, Entry3.TextIn!, Entry3.TextIn!];
if (game.AddPlayerInGame(playerstag))
{
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)

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

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

Loading…
Cancel
Save