rportet 11 months ago
commit 86f31a0843

@ -22,7 +22,7 @@ namespace QwirkleClassLibrary.Games
public bool GameRunning { get; set; }
[DataMember]
private Board board = new(15, 12);
private Board board = new(17, 14);
public bool PlayerSwapping { get; set; }
public Board Board => board;
@ -184,7 +184,7 @@ namespace QwirkleClassLibrary.Games
/// <returns>Board</returns>
public Board CreateBoard()
{
board = new Board(15, 12);
board = new Board(17, 14);
return board;
}
@ -292,16 +292,31 @@ namespace QwirkleClassLibrary.Games
/// </summary>
/// <returns>string</returns>
/// <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;
OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0]));
return players[0].NameTag;
var colorGroups = player.Tiles.GroupBy(t => t.GetColor).Select(g => g.Count());
var shapeGroups = player.Tiles.GroupBy(t => t.GetShape).Select(g => g.Count());
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>
@ -314,7 +329,7 @@ namespace QwirkleClassLibrary.Games
if (i == -1)
{
return SetFirstPlayer();
return SetFirstPlayer(PlayerList);
}
players[i].IsPlaying = false;

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

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

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

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

@ -23,7 +23,7 @@ public partial class Gameboard : ContentPage
private List<Tile> tilesSwap = [];
public Color ColorBC1 { get; set; } = Colors.White;
public Color ColorBC1 { get; set; } = Colors.Transparent;
public Color ColorBC2 { get; set; } = Colors.Transparent;
public Color ColorBC3 { get; set; } = Colors.Transparent;
public Color ColorBC4 { get; set; } = Colors.Transparent;
@ -31,10 +31,22 @@ public partial class Gameboard : ContentPage
public Gameboard()
{
InitializeComponent();
BindingContext = game;
ChangeColorBC();
}
private void Game_EndOfGameNotified(object? sender, EndOfGameNotifiedEventArgs e)
{
DisplayAlert("THE END.", "FAUT QU'ON PARLE DE CE QUE QU'ON VEUT FAIRE ICI !!!" ,"<3");
Navigation.PushAsync(new MainPage());
game.ClearGame();
}
private void OnDragStarting(object sender, DragStartingEventArgs e)
{
var tile = ((Element)sender).BindingContext as Tile;
@ -78,6 +90,7 @@ public partial class Gameboard : ContentPage
private void OnButtonSkipClicked(object sender, EventArgs e)
{
game.NextPlayerNotified += Game_NextPlayerNotified;
game.EndOfGameNotified += Game_EndOfGameNotified;
if (game.PlayerSwapping)
{
@ -95,6 +108,7 @@ public partial class Gameboard : ContentPage
game.CheckGameOver(game.GetPlayingPlayer());
game.SetNextPlayer();
game.NextPlayerNotified -= Game_NextPlayerNotified;
game.EndOfGameNotified -= Game_EndOfGameNotified;
ChangeColorBC();
}
@ -159,14 +173,27 @@ public partial class Gameboard : ContentPage
if (game.CellsUsed.Count == 0 && !game.PlayerSwapping)
{
DisplayAlert("Swap system", "\r\nWelcome to the swap system! To use the system, take the tiles you wish to swap and place them in the bag (you will not see the tiles disappear). Then, click on the skip button. /!\\ Attention, during the swap phase, you cannot play /!\\", "Copy !");
game.PlayerSwapping = true;
//DisplayAlert("Swap system", "\r\nWelcome to the swap system! To use the system, take the tiles you wish to swap and place them in the bag (you will not see the tiles disappear). Then, click on the skip button. /!\\ Attention, during the swap phase, you cannot play /!\\", "Copy !");
AnswerSwap();
}
game.SwapTilesNotified -= Game_SwapTilesNotified;
game.PlaceTileNotified -= Game_PlaceTileNotified;
}
private async void AnswerSwap()
{
bool answer = await DisplayAlert("Swap System", "Etes vous sur de vouloir swap vos tuiles ? Attention, si vous swapez vous ne pouvez pu jouer", "Yes", "No");
if (answer)
{
game.PlayerSwapping = true;
}
}
private void Game_SwapTilesNotified(object? sender, SwapTilesNotifiedEventArgs args)
{
DisplayAlert("Swap system", args.Reason, "<3");

@ -35,7 +35,7 @@
DropCommand="{Binding OnDropB, Source={x:Reference root}}"
/>
</Border.GestureRecognizers>
<Image Source="bag.png"></Image>
<Image Source="bag.png" ToolTipProperties.Text="Pour m'utiliser il faut cliquer sur le boutton swap avant ^^"></Image>
</Border>
<Button
@ -43,6 +43,7 @@
Grid.Row="0" Grid.Column="1"
Text="Swap"
Clicked="OnButtonSwapClicked"
ToolTipProperties.Text="Click to swap your tiles !"
Style="{StaticResource GameButton}"/>
<Button
@ -50,12 +51,14 @@
Grid.Row="2" Grid.Column="1"
Text="Skip / End Turn" WidthRequest="200"
Clicked="OnButtonSkipClicked"
ToolTipProperties.Text="Click for skip / end your turn ;)"
Style="{StaticResource GameButton}"/>
<Button
HorizontalOptions="Start"
Grid.Row="2" Grid.Column="1"
Text="Settings"
ToolTipProperties.Text="Click to check your settings -_-"
Style="{StaticResource GameButton}"/>
<CollectionView Grid.Row="0" Grid.Column="1" ItemsSource="{Binding PlayerList[0].Tiles}"

@ -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" />
</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">
<Setter Property="TextColor" Value="Black" />
@ -261,6 +268,12 @@
<Setter Property="HorizontalOptions" Value="Center" />
</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">
<Setter Property="TextColor" Value="Black" />
<Setter Property="FontSize" Value="20" />

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

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

@ -104,6 +104,7 @@ public class TestGame
Game game = new Game();
List<string> playerstest = [p1, p2, p3];
game.AddPlayerInGame(playerstest);
int i = 0;
if (!result)
{
@ -111,8 +112,19 @@ public class TestGame
return;
}
game.StartGame();
game.SetFirstPlayer();
Assert.Equal(0, game.GetPlayingPlayerPosition());
game.GiveTilesToPlayers();
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]
@ -121,6 +133,7 @@ public class TestGame
public void Test_GameGetPlaylingPlayer(bool result)
{
Game game = new Game();
Player? p = null;
List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame(playerstest);
if (!result)
@ -128,9 +141,19 @@ public class TestGame
Assert.Throws<ArgumentException>(() => game.GetPlayingPlayer());
}
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.StartGame();
game.SetFirstPlayer();
game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
Assert.IsType<Board>(game.GetBoard());
}
@ -156,7 +180,8 @@ public class TestGame
game.AddPlayerInGame(playerstest);
game.StartGame();
game.SetFirstPlayer();
game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
Board? b = game.GetBoard();
Cell? c = b!.GetCell(1, 1);
@ -172,15 +197,24 @@ public class TestGame
public void Test_TileOfPlayer()
{
Game game = new Game();
Player? p = null;
List<string> playerstest = ["test", "test1"];
game.AddPlayerInGame(playerstest);
game.StartGame();
game.SetFirstPlayer();
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]
@ -195,11 +229,12 @@ public class TestGame
if (except)
{
game.StartGame();
Assert.IsType<string>(game.SetFirstPlayer());
game.GiveTilesToPlayers();
Assert.IsType<string>(game.SetFirstPlayer(game.PlayerList));
return;
}
Assert.Throws<ArgumentException>(() => game.SetFirstPlayer());
Assert.Throws<ArgumentException>(() => game.SetFirstPlayer(game.PlayerList));
}
@ -215,13 +250,15 @@ public class TestGame
if (except)
{
game.StartGame();
game.GiveTilesToPlayers();
game.SetNextPlayer();
Assert.IsType<string>(game.SetNextPlayer());
return;
}
game.StartGame();
Assert.Equal(game.SetNextPlayer(), game.SetFirstPlayer());
game.GiveTilesToPlayers();
Assert.Equal(game.SetNextPlayer(), game.SetFirstPlayer(game.PlayerList));
return;
}
@ -279,6 +316,7 @@ public class TestGame
game.AddPlayerInGame(playerstest);
game.StartGame();
game.GiveTilesToPlayers();
game.SetNextPlayer();
List<Tile> list = [];
@ -304,38 +342,6 @@ public class TestGame
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]
public void Test_IsMoveCorrectSixLine()
{
@ -344,6 +350,7 @@ public class TestGame
game.AddPlayerInGame(playerstest);
game.StartGame();
game.GiveTilesToPlayers();
game.SetNextPlayer();
Tile t1 = new Tile(Shape.Square, Color.Red);
@ -416,7 +423,8 @@ public class TestGame
game.AddPlayerInGame(playerstest);
game.StartGame();
game.SetFirstPlayer();
game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
game.CheckGameOver(game.GetPlayingPlayer());
@ -430,7 +438,8 @@ public class TestGame
game.AddPlayerInGame(playerstest);
game.StartGame();
game.SetFirstPlayer();
game.GiveTilesToPlayers();
game.SetFirstPlayer(game.PlayerList);
game.ClearGame();

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

Loading…
Cancel
Save