work.
continuous-integration/drone/push Build is passing Details

test_old_branch
Jérémy Mouyon 11 months ago
parent 0787add85f
commit ed05061476

@ -30,6 +30,7 @@ namespace QwirkleClassLibrary.Games
[DataMember] [DataMember]
private Board board = new Board(15, 12); private Board board = new Board(15, 12);
public Board Board => board;
public ObservableCollection<Cell> GetCellsInBoard => new ObservableCollection<Cell>(board!.GetCells()); public ObservableCollection<Cell> GetCellsInBoard => new ObservableCollection<Cell>(board!.GetCells());

@ -1,18 +1,24 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using QwirkleClassLibrary.Tiles; using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Players namespace QwirkleClassLibrary.Players
{ {
public class Player public class Player : INotifyPropertyChanged
{ {
public ReadOnlyCollection<Tile> Tiles => playerTiles.AsReadOnly(); public ReadOnlyCollection<Tile> Tiles => playerTiles.AsReadOnly();
private readonly List<Tile> playerTiles = new(); private readonly List<Tile> playerTiles = new();
public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName] string? propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
/// <summary> /// <summary>
/// Creates a player with a name /// Creates a player with a name
/// </summary> /// </summary>
@ -39,6 +45,7 @@ namespace QwirkleClassLibrary.Players
public void AddTileToPlayer(Tile tile) public void AddTileToPlayer(Tile tile)
{ {
playerTiles.Add(tile); playerTiles.Add(tile);
OnPropertyChanged();
} }
/// <summary> /// <summary>
@ -48,7 +55,12 @@ namespace QwirkleClassLibrary.Players
/// <returns>bool</returns> /// <returns>bool</returns>
public bool RemoveTileToPlayer(Tile tile) public bool RemoveTileToPlayer(Tile tile)
{ {
return playerTiles.Remove(tile); if (playerTiles.Remove(tile))
{
OnPropertyChanged();
return true;
}
return false;
} }
} }
} }

@ -9,24 +9,34 @@ using System.ComponentModel;
using Cell = QwirkleClassLibrary.Boards.Cell; using Cell = QwirkleClassLibrary.Boards.Cell;
namespace Qwirkle.Pages; namespace Qwirkle.Pages;
public partial class Gameboard : ContentPage public partial class Gameboard : ContentPage, INotifyPropertyChanged
{ {
public ICommand OnDrop => new Command<Cell>(OnDropTile); public ICommand OnDrop => new Command<Cell>(OnDropTile);
private Game game = ((App)Application.Current!).Game; private Game game = ((App)Application.Current!).Game;
private Tile? tiledrag; private Tile? tiledrag;
private ObservableCollection<Tile> playerCells1;
public ObservableCollection<Tile> PlayerCells1
{
get => playerCells1;
set
{
playerCells1 = value;
OnPropertyChanged(nameof(PlayerCells1));
}
}
public Gameboard() public Gameboard()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = game; BindingContext = game;
DisplayAlert("List", ((App)Application.Current!).Game.PlayerList[0].Tiles[0].ToString(), "chut"); PlayerCells1 = new ObservableCollection<Tile>(game.PlayerList[0].Tiles.ToList());
DisplayAlert("List", playerCells1[0].ToString(), "chut");
} }
public List<Tile> PlayerCells1 { get; set; } = ((App)Application.Current!).Game.PlayerList[0].Tiles.ToList();
private void OnDragOver(object sender, DragEventArgs e) private void OnDragOver(object sender, DragEventArgs e)
@ -59,4 +69,11 @@ public partial class Gameboard : ContentPage
{ {
DisplayAlert("Tile place notified", args.Reason, "<3"); DisplayAlert("Tile place notified", args.Reason, "<3");
} }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
} }

@ -10,43 +10,39 @@
<StackLayout> <StackLayout>
<CollectionView ItemsSource="{Binding GetCellsInBoard}" <CollectionView ItemsSource="{Binding GetCellsInBoard}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center"> VerticalOptions="Center">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" <GridItemsLayout Orientation="Vertical"
Span="{Binding Board.Columns}"/> Span="{Binding Board.Columns}"/>
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border WidthRequest="70" HeightRequest="70" <Border WidthRequest="70" HeightRequest="70"
BackgroundColor="WhiteSmoke" BackgroundColor="WhiteSmoke"
Margin="0"> Margin="0">
<Border.GestureRecognizers> <Border.GestureRecognizers>
<DropGestureRecognizer DragOver="OnDragOver" <DropGestureRecognizer DragOver="OnDragOver"
DropCommand="{Binding OnDrop, Source={x:Reference root}}" DropCommand="{Binding OnDrop, Source={x:Reference root}}"
DropCommandParameter="{Binding .}" /> DropCommandParameter="{Binding .}" />
</Border.GestureRecognizers> </Border.GestureRecognizers>
<Label Text="{Binding GetTile}"></Label> <Label Text="{Binding GetTile}" />
</Border> </Border>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<CollectionView ItemsSource="{Binding PlayerCells1, Source={x:Reference root}}" <CollectionView ItemsSource="{Binding PlayerCells1, Source={x:Reference root}}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Start" > VerticalOptions="Start" >
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal"/> <GridItemsLayout Orientation="Horizontal"/>
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border WidthRequest="70" HeightRequest="70" <Border WidthRequest="70" HeightRequest="70"
BackgroundColor="WhiteSmoke" BackgroundColor="WhiteSmoke"
Margin="0"> Margin="0">
<Label Text="{Binding}"> <Label Text="{Binding}">
<Label.GestureRecognizers> <Label.GestureRecognizers>
<DragGestureRecognizer /> <DragGestureRecognizer />
@ -54,11 +50,10 @@
</Label> </Label>
</Border> </Border>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
</StackLayout> </StackLayout>
</ScrollView> </ScrollView>
</ContentPage> </ContentPage>
Loading…
Cancel
Save