Uhhh, too many things done here, don't wanna explain
continuous-integration/drone/push Build is passing Details

test_old_branch
Jules LASCRET 11 months ago
parent 4297dd49a8
commit 1cdcf68f4f

@ -22,7 +22,7 @@ namespace QwirkleClassLibrary.Games
public bool GameRunning { get; set; } public bool GameRunning { get; set; }
[DataMember] [DataMember]
private Board board = new(15, 12); private Board board = new(17, 14);
public bool PlayerSwapping { get; set; } public bool PlayerSwapping { get; set; }
public Board Board => board; public Board Board => board;
@ -184,7 +184,7 @@ namespace QwirkleClassLibrary.Games
/// <returns>Board</returns> /// <returns>Board</returns>
public Board CreateBoard() public Board CreateBoard()
{ {
board = new Board(15, 12); board = new Board(17, 14);
return board; return board;
} }
@ -292,16 +292,31 @@ namespace QwirkleClassLibrary.Games
/// </summary> /// </summary>
/// <returns>string</returns> /// <returns>string</returns>
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
public string SetFirstPlayer() public string SetFirstPlayer(ReadOnlyCollection<Player> playingPlayers)
{ {
if (GameRunning) if (!GameRunning) throw new ArgumentException("Game is not running");
Player? startingPlayer = null;
int maxGroupSize = 0;
foreach (var player in players)
{ {
players[0].IsPlaying = true; var colorGroups = player.Tiles.GroupBy(t => t.GetColor).Select(g => g.Count());
OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0])); var shapeGroups = player.Tiles.GroupBy(t => t.GetShape).Select(g => g.Count());
return players[0].NameTag;
int playerMaxGroupSize = Math.Max(colorGroups.Max(), shapeGroups.Max());
if (playerMaxGroupSize > maxGroupSize)
{
maxGroupSize = playerMaxGroupSize;
startingPlayer = player;
}
} }
throw new ArgumentException("Game is not running"); startingPlayer!.IsPlaying = true;
OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0]));
return startingPlayer.NameTag;
} }
/// <summary> /// <summary>
@ -314,7 +329,7 @@ namespace QwirkleClassLibrary.Games
if (i == -1) if (i == -1)
{ {
return SetFirstPlayer(); return SetFirstPlayer(PlayerList);
} }
players[i].IsPlaying = false; players[i].IsPlaying = false;

@ -11,7 +11,7 @@ public interface IPlayer
public string SetNextPlayer(); public string SetNextPlayer();
public string SetFirstPlayer(); public string SetFirstPlayer(ReadOnlyCollection<Player> playingPlayers);
public bool PlaceTile(Player player, Tile tile, int x, int y); public bool PlaceTile(Player player, Tile tile, int x, int y);

@ -15,6 +15,7 @@ namespace Qwirkle
Routing.RegisterRoute(nameof(SetPlayers), typeof(SetPlayers)); Routing.RegisterRoute(nameof(SetPlayers), typeof(SetPlayers));
Routing.RegisterRoute(nameof(Gameboard), typeof(Gameboard)); Routing.RegisterRoute(nameof(Gameboard), typeof(Gameboard));
Routing.RegisterRoute(nameof(Rules), typeof(Rules));
} }

@ -28,7 +28,8 @@
<controls:ButtonShadow Text="Leaderboard"/> <controls:ButtonShadow Text="Leaderboard"/>
<controls:ButtonShadow Text="Rules"/> <controls:ButtonShadow Text="Rules"
InfoClicked="OnRulesClicked"/>
<controls:ButtonShadow Text="Settings"/> <controls:ButtonShadow Text="Settings"/>

@ -23,7 +23,10 @@ namespace Qwirkle
} }
public void OnRulesClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Rules());
}
} }

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Qwirkle.Pages.Rules"
xmlns:controls="clr-namespace:Qwirkle.Views"
Title="Rules">
<ScrollView>
<VerticalStackLayout>
<Grid Style="{StaticResource GridMain}">
<controls:GoBack></controls:GoBack>
<Label Text="Qwirkle Rules"
Style="{StaticResource Title}" />
</Grid>
<Label
Text="Game Composition"
Style="{StaticResource RulesSubTitle}"/>
<Label
Text="The game is composed of 3 sets of 36 tiles, each set containing 6 tiles of each of the 6 colors and 6 shapes."
Style="{StaticResource RulesContent}"/>
<Label
Text="Who Starts ?"
Style="{StaticResource RulesSubTitle}" />
<Label
Text="In order to determine who starts, the algorithm checks which player has the most tiles with the same shape or color."
Style="{StaticResource RulesContent}" />
<Label
Text="Then, the first player can place his tiles wherever he wants on the board."
Style="{StaticResource RulesContent}" />
<Label
Text="Progress of the game"
Style="{StaticResource RulesSubTitle}" />
<Label
Text="Each player can then place as many tiles as they want on the board, as long as they respect these 3 rules:"
Style="{StaticResource RulesContent}" />
<Label
Text="1. The tiles must be placed in a straight line/column."
Style="{StaticResource RulesContent}" />
<Label
Text="2. On a line assigned to a certain color/shape, the tiles must have the same color/shape."
Style="{StaticResource RulesContent}" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Qwirkle.Pages;
public partial class Rules : ContentPage
{
public Rules()
{
InitializeComponent();
}
}

@ -254,6 +254,13 @@
<Setter Property="FontAttributes" Value="Bold" /> <Setter Property="FontAttributes" Value="Bold" />
</Style> </Style>
<Style TargetType="Label" x:Key="RulesSubTitle">
<Setter Property="TextColor" Value="Black" />
<Setter Property="FontSize" Value="25" />
<Setter Property="Padding" Value="30" />
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="FontAttributes" Value="Bold" />
</Style>
<Style TargetType="Label" x:Key="ContentCenter"> <Style TargetType="Label" x:Key="ContentCenter">
<Setter Property="TextColor" Value="Black" /> <Setter Property="TextColor" Value="Black" />
@ -261,6 +268,12 @@
<Setter Property="HorizontalOptions" Value="Center" /> <Setter Property="HorizontalOptions" Value="Center" />
</Style> </Style>
<Style TargetType="Label" x:Key="RulesContent">
<Setter Property="TextColor" Value="Black" />
<Setter Property="FontSize" Value="16" />
<Setter Property="HorizontalOptions" Value="Center" />
</Style>
<Style TargetType="Label" x:Key="ContentStart"> <Style TargetType="Label" x:Key="ContentStart">
<Setter Property="TextColor" Value="Black" /> <Setter Property="TextColor" Value="Black" />
<Setter Property="FontSize" Value="20" /> <Setter Property="FontSize" Value="20" />

@ -3,5 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Qwirkle.Views.GoBack"> x:Class="Qwirkle.Views.GoBack">
<Button Text="Go Back" <Button Text="Go Back"
Style="{StaticResource BackButton}"/> Style="{StaticResource BackButton}"
Clicked="Button_OnClicked"/>
</ContentView> </ContentView>

@ -6,4 +6,9 @@ public partial class GoBack : ContentView
{ {
InitializeComponent(); InitializeComponent();
} }
private void Button_OnClicked(object? sender, EventArgs e)
{
Navigation.PopAsync();
}
} }

@ -104,6 +104,7 @@ public class TestGame
Game game = new Game(); Game game = new Game();
List<string> playerstest = [p1, p2, p3]; List<string> playerstest = [p1, p2, p3];
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
int i = 0;
if (!result) if (!result)
{ {
@ -111,8 +112,19 @@ public class TestGame
return; return;
} }
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.GiveTilesToPlayers();
Assert.Equal(0, game.GetPlayingPlayerPosition()); game.SetFirstPlayer(game.PlayerList);
for(int j = 0; j < game.PlayerList.Count; j++)
{
if (game.PlayerList[j] == game.GetPlayingPlayer())
{
i = j;
break;
}
}
Assert.Equal(i, game.GetPlayingPlayerPosition());
} }
[Theory] [Theory]
@ -121,6 +133,7 @@ public class TestGame
public void Test_GameGetPlaylingPlayer(bool result) public void Test_GameGetPlaylingPlayer(bool result)
{ {
Game game = new Game(); Game game = new Game();
Player? p = null;
List<string> playerstest = ["test", "test1"]; List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
if (!result) if (!result)
@ -128,9 +141,19 @@ public class TestGame
Assert.Throws<ArgumentException>(() => game.GetPlayingPlayer()); Assert.Throws<ArgumentException>(() => game.GetPlayingPlayer());
} }
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
Assert.Equal(game.PlayerList[0], game.GetPlayingPlayer()); foreach (var pl in game.PlayerList)
{
if (pl == game.GetPlayingPlayer())
{
p = pl;
break;
}
}
Assert.Equal(p, game.GetPlayingPlayer());
} }
@ -142,7 +165,8 @@ public class TestGame
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
Assert.IsType<Board>(game.GetBoard()); Assert.IsType<Board>(game.GetBoard());
} }
@ -156,7 +180,8 @@ public class TestGame
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
Board? b = game.GetBoard(); Board? b = game.GetBoard();
Cell? c = b!.GetCell(1, 1); Cell? c = b!.GetCell(1, 1);
@ -172,15 +197,24 @@ public class TestGame
public void Test_TileOfPlayer() public void Test_TileOfPlayer()
{ {
Game game = new Game(); Game game = new Game();
Player? p = null;
List<string> playerstest = ["test", "test1"]; List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer();
game.GiveTilesToPlayers(); game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
foreach (var pl in game.PlayerList)
{
if (pl == game.GetPlayingPlayer())
{
p = pl;
break;
}
}
Assert.Equal(game.PlayerList[0].Tiles[0], game.TileOfPlayerWithPos(0)); Assert.Equal(p!.Tiles[0], game.TileOfPlayerWithPos(0));
} }
[Theory] [Theory]
@ -195,11 +229,12 @@ public class TestGame
if (except) if (except)
{ {
game.StartGame(); game.StartGame();
Assert.IsType<string>(game.SetFirstPlayer()); game.GiveTilesToPlayers();
Assert.IsType<string>(game.SetFirstPlayer(game.PlayerList));
return; return;
} }
Assert.Throws<ArgumentException>(() => game.SetFirstPlayer()); Assert.Throws<ArgumentException>(() => game.SetFirstPlayer(game.PlayerList));
} }
@ -215,13 +250,15 @@ public class TestGame
if (except) if (except)
{ {
game.StartGame(); game.StartGame();
game.GiveTilesToPlayers();
game.SetNextPlayer(); game.SetNextPlayer();
Assert.IsType<string>(game.SetNextPlayer()); Assert.IsType<string>(game.SetNextPlayer());
return; return;
} }
game.StartGame(); game.StartGame();
Assert.Equal(game.SetNextPlayer(), game.SetFirstPlayer()); game.GiveTilesToPlayers();
Assert.Equal(game.SetNextPlayer(), game.SetFirstPlayer(game.PlayerList));
return; return;
} }
@ -279,6 +316,7 @@ public class TestGame
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.GiveTilesToPlayers();
game.SetNextPlayer(); game.SetNextPlayer();
List<Tile> list = []; List<Tile> list = [];
@ -304,38 +342,6 @@ public class TestGame
Assert.Equal(p, events.Player); Assert.Equal(p, events.Player);
} }
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Test_IsMoveCorrectOne(bool except)
{
Game game = new Game();
List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame(playerstest);
game.StartGame();
game.SetNextPlayer();
Tile t1 = new Tile(Shape.Square, Color.Red);
Tile t2 = new Tile(Shape.Club, Color.Purple);
Tile t3 = new Tile(Shape.Round, Color.Red);
game.GetPlayingPlayer().Tiles.Add(t1);
game.GetPlayingPlayer().Tiles.Add(t2);
game.GetPlayingPlayer().Tiles.Add(t3);
game.PlaceTile(game.GetPlayingPlayer(), game.GetPlayingPlayer().Tiles[0], 0, 0);
if (except)
{
Assert.True(game.IsMoveCorrect(game.GetPlayingPlayer().Tiles[1], 0, 1, game.GetBoard()!));
}
else
{
Assert.False(game.IsMoveCorrect(game.GetPlayingPlayer().Tiles[0], 0, 1, game.GetBoard()!));
}
}
[Fact] [Fact]
public void Test_IsMoveCorrectSixLine() public void Test_IsMoveCorrectSixLine()
{ {
@ -344,6 +350,7 @@ public class TestGame
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.GiveTilesToPlayers();
game.SetNextPlayer(); game.SetNextPlayer();
Tile t1 = new Tile(Shape.Square, Color.Red); Tile t1 = new Tile(Shape.Square, Color.Red);
@ -416,7 +423,8 @@ public class TestGame
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
game.CheckGameOver(game.GetPlayingPlayer()); game.CheckGameOver(game.GetPlayingPlayer());
@ -430,7 +438,8 @@ public class TestGame
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
game.ClearGame(); game.ClearGame();

@ -21,7 +21,8 @@ public class TestLeaderboard
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
var tile = new Tile(Shape.Club, Color.Blue); var tile = new Tile(Shape.Club, Color.Blue);
game.PlaceTile(game.GetPlayingPlayer(), tile, 1, 1); game.PlaceTile(game.GetPlayingPlayer(), tile, 1, 1);
@ -41,7 +42,8 @@ public class TestLeaderboard
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
var tile = new Tile(Shape.Club, Color.Blue); var tile = new Tile(Shape.Club, Color.Blue);
game.PlaceTile(game.GetPlayingPlayer(), tile, 1, 1); game.PlaceTile(game.GetPlayingPlayer(), tile, 1, 1);
@ -53,7 +55,7 @@ public class TestLeaderboard
game.AddPlayerInGame(playerstest); game.AddPlayerInGame(playerstest);
game.StartGame(); game.StartGame();
game.SetFirstPlayer(); game.SetFirstPlayer(game.PlayerList);
game.PlaceTile(game.GetPlayingPlayer(), tile, 1, 1); game.PlaceTile(game.GetPlayingPlayer(), tile, 1, 1);

Loading…
Cancel
Save