IS THE END OF THE GAMEBOARD MATE
continuous-integration/drone/push Build is passing Details

test_old_branch
Jérémy Mouyon 11 months ago
parent 933a18e5aa
commit 15f0c4e1ef

@ -28,7 +28,8 @@ namespace QwirkleClassLibrary.Games
[DataMember] [DataMember]
private Board board = new Board(15, 12); private Board board = new Board(15, 12);
public bool PlayerSwapping { get; set; }
public Board Board => board; public Board Board => board;
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly(); public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
@ -325,9 +326,14 @@ namespace QwirkleClassLibrary.Games
/// <returns>bool</returns> /// <returns>bool</returns>
public bool PlaceTile(Player player, Tile tile, int x, int y) public bool PlaceTile(Player player, Tile tile, int x, int y)
{ {
if (PlayerSwapping)
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "you are swapping, you can't place tile !"));
return false;
}
if(!TileInbag(player, tile)) if(!TileInbag(player, tile))
{ {
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "you cant play")); OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "you can't play"));
return false; return false;
} }
if (!IsMoveCorrect(tile, x, y, board!)) return false; if (!IsMoveCorrect(tile, x, y, board!)) return false;

@ -15,11 +15,14 @@ namespace Qwirkle.Pages;
public partial class Gameboard : ContentPage public partial class Gameboard : ContentPage
{ {
public ICommand OnDrop => new Command<Cell>(OnDropTile); public ICommand OnDrop => new Command<Cell>(OnDropTile);
public ICommand OnDropB => new Command(OnDropBag);
private Game game = ((App)Application.Current!).Game; private Game game = ((App)Application.Current!).Game;
private Tile? tiledrag; private Tile? tiledrag;
private List<Tile> tilesSwap = [];
public Color ColorBC1 { get; set; } = Colors.White; public Color ColorBC1 { get; set; } = Colors.White;
public Color ColorBC2 { get; set; } = Colors.Transparent; public Color ColorBC2 { get; set; } = Colors.Transparent;
public Color ColorBC3 { get; set; } = Colors.Transparent; public Color ColorBC3 { get; set; } = Colors.Transparent;
@ -44,6 +47,11 @@ public partial class Gameboard : ContentPage
e.AcceptedOperation = DataPackageOperation.Copy; e.AcceptedOperation = DataPackageOperation.Copy;
} }
private void OnDragOverBag(object sender, DragEventArgs e)
{
e.AcceptedOperation = DataPackageOperation.Copy;
}
private void OnDropTile(Cell cell) private void OnDropTile(Cell cell)
{ {
@ -71,14 +79,21 @@ public partial class Gameboard : ContentPage
{ {
game.NextPlayerNotified += Game_NextPlayerNotified; game.NextPlayerNotified += Game_NextPlayerNotified;
if (game.PlayerSwapping)
{
game.SwapTiles(game.GetPlayingPlayer(), tilesSwap);
tilesSwap.Clear();
game.PlayerSwapping = false;
}
else
{
game.GetPlayerScore(game.GetPlayingPlayer(), game.CellsUsed, game.GetBoard()!);
game.EmptyCellUsed();
game.DrawTiles(game.GetPlayingPlayer());
}
game.GetPlayerScore(game.GetPlayingPlayer(), game.CellsUsed, game.GetBoard()!);
game.EmptyCellUsed();
game.DrawTiles(game.GetPlayingPlayer());
game.CheckGameOver(game.GetPlayingPlayer()); game.CheckGameOver(game.GetPlayingPlayer());
game.SetNextPlayer(); game.SetNextPlayer();
game.NextPlayerNotified -= Game_NextPlayerNotified; game.NextPlayerNotified -= Game_NextPlayerNotified;
ChangeColorBC(); ChangeColorBC();
@ -89,6 +104,8 @@ public partial class Gameboard : ContentPage
if (game.GetPlayingPlayerPosition() == 0) if (game.GetPlayingPlayerPosition() == 0)
{ {
ColorBC1 = Colors.White; ColorBC1 = Colors.White;
ColorBC2 = Colors.Transparent;
ColorBC3 = Colors.Transparent;
ColorBC4 = Colors.Transparent; ColorBC4 = Colors.Transparent;
OnPropertyChanged(nameof(ColorBC1)); OnPropertyChanged(nameof(ColorBC1));
OnPropertyChanged(nameof(ColorBC4)); OnPropertyChanged(nameof(ColorBC4));
@ -97,20 +114,26 @@ public partial class Gameboard : ContentPage
{ {
ColorBC2 = Colors.White; ColorBC2 = Colors.White;
ColorBC1 = Colors.Transparent; ColorBC1 = Colors.Transparent;
ColorBC3 = Colors.Transparent;
ColorBC4 = Colors.Transparent;
OnPropertyChanged(nameof(ColorBC1)); OnPropertyChanged(nameof(ColorBC1));
OnPropertyChanged(nameof(ColorBC2)); OnPropertyChanged(nameof(ColorBC2));
} }
if (game.GetPlayingPlayerPosition() == 2) if (game.GetPlayingPlayerPosition() == 2)
{ {
ColorBC3 = Colors.White; ColorBC3 = Colors.White;
ColorBC1 = Colors.Transparent;
ColorBC2 = Colors.Transparent; ColorBC2 = Colors.Transparent;
ColorBC4 = Colors.Transparent;
OnPropertyChanged(nameof(ColorBC3)); OnPropertyChanged(nameof(ColorBC3));
OnPropertyChanged(nameof(ColorBC2)); OnPropertyChanged(nameof(ColorBC2));
} }
if (game.GetPlayingPlayerPosition() == 3) if (game.GetPlayingPlayerPosition() == 3)
{ {
ColorBC4 = Colors.White; ColorBC4 = Colors.White;
ColorBC1 = Colors.Transparent;
ColorBC3 = Colors.Transparent; ColorBC3 = Colors.Transparent;
ColorBC2 = Colors.Transparent;
OnPropertyChanged(nameof(ColorBC4)); OnPropertyChanged(nameof(ColorBC4));
OnPropertyChanged(nameof(ColorBC3)); OnPropertyChanged(nameof(ColorBC3));
} }
@ -121,8 +144,31 @@ public partial class Gameboard : ContentPage
DisplayAlert("Player switch !", "It's your turn : " + args.Player.NameTag, "<3"); DisplayAlert("Player switch !", "It's your turn : " + args.Player.NameTag, "<3");
} }
private void OnTileClickedP1(object? sender, EventArgs args) private void OnButtonSwapClicked(object sender, EventArgs e)
{
game.PlaceTileNotified += Game_PlaceTileNotified;
game.SwapTilesNotified += Game_SwapTilesNotified;
if(game.CellsUsed.Count == 0 && game.PlayerSwapping==false)
{
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;
}
game.SwapTilesNotified -= Game_SwapTilesNotified;
game.PlaceTileNotified -= Game_PlaceTileNotified;
}
private void Game_SwapTilesNotified(object? sender, SwapTilesNotifiedEventArgs args)
{ {
DisplayAlert("Swap system", args.Reason, "<3");
}
private void OnDropBag()
{
if (game.PlayerSwapping)
{
tilesSwap.Add(tiledrag!);
}
} }
} }

@ -17,7 +17,19 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label Text="{Binding bag.TilesBag.Count}"></Label>
<Border WidthRequest="80" HeightRequest="80"
BackgroundColor="WhiteSmoke"
Margin="0" >
<Border.GestureRecognizers >
<DropGestureRecognizer DragOver="OnDragOverBag"
DropCommand="{Binding OnDropB, Source={x:Reference root}}"
/>
</Border.GestureRecognizers>
<Image Source="bag.png"></Image>
</Border>
<Button HorizontalOptions="Start" Grid.Row="0" Grid.Column="1" Text="Swap" WidthRequest="200" HeightRequest="10" FontSize="20" Margin="20" Clicked="OnButtonSwapClicked"></Button>
<Button HorizontalOptions="End" Grid.Row="2" Grid.Column="1" Text="Skip / End Turn" WidthRequest="200" HeightRequest="10" FontSize="20" Margin="20" Clicked="OnButtonSkipClicked"></Button> <Button HorizontalOptions="End" Grid.Row="2" Grid.Column="1" Text="Skip / End Turn" WidthRequest="200" HeightRequest="10" FontSize="20" Margin="20" Clicked="OnButtonSkipClicked"></Button>
<Button HorizontalOptions="Start" Grid.Row="2" Grid.Column="1" Text="Settings" WidthRequest="200" HeightRequest="10" FontSize="20" Margin="20" ></Button> <Button HorizontalOptions="Start" Grid.Row="2" Grid.Column="1" Text="Settings" WidthRequest="200" HeightRequest="10" FontSize="20" Margin="20" ></Button>
@ -38,7 +50,7 @@
<Border.GestureRecognizers> <Border.GestureRecognizers>
<DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting"/> <DragGestureRecognizer CanDrag="True" DragStarting="OnDragStarting"/>
</Border.GestureRecognizers> </Border.GestureRecognizers>
<controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}" InfoClicked="OnTileClickedP1"></controls:TileView> <controls:TileView Shape="{Binding GetShape}" Color="{Binding GetColor}"></controls:TileView>
</Border> </Border>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
@ -122,7 +134,7 @@
DropCommand="{Binding OnDrop, Source={x:Reference root}}" DropCommand="{Binding OnDrop, Source={x:Reference root}}"
DropCommandParameter="{Binding .}"/> DropCommandParameter="{Binding .}"/>
</Border.GestureRecognizers> </Border.GestureRecognizers>
<controls:TileView HorizontalOptions="Start" Shape="{Binding Tile.GetShape}" Color="{Binding Tile.GetColor}"></controls:TileView> <controls:TileView HorizontalOptions="Center" Shape="{Binding Tile.GetShape}" Color="{Binding Tile.GetColor}"></controls:TileView>
</Border> </Border>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Loading…
Cancel
Save