You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sae201_qwirkle/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs

79 lines
2.0 KiB

using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles;
using QwirkleClassLibrary.Events;
using QwirkleClassLibrary.Boards;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.ComponentModel;
using Cell = QwirkleClassLibrary.Boards.Cell;
namespace Qwirkle.Pages;
public partial class Gameboard : ContentPage, INotifyPropertyChanged
{
public ICommand OnDrop => new Command<Cell>(OnDropTile);
private Game game = ((App)Application.Current!).Game;
private Tile? tiledrag;
private ObservableCollection<Tile> playerCells1;
public ObservableCollection<Tile> PlayerCells1
{
get => playerCells1;
set
{
playerCells1 = value;
OnPropertyChanged(nameof(PlayerCells1));
}
}
public Gameboard()
{
InitializeComponent();
BindingContext = game;
PlayerCells1 = new ObservableCollection<Tile>(game.PlayerList[0].Tiles.ToList());
DisplayAlert("List", playerCells1[0].ToString(), "chut");
}
private void OnDragOver(object sender, DragEventArgs e)
{
foreach (var t in PlayerCells1)
{
if (e.Data.Text == t.ToString())
{
tiledrag = t;
break;
}
}
}
private void OnDropTile(Cell cell)
{
game.PlaceTileNotified += Game_PlaceTileNotified;
int x = cell.GetX;
int y = cell.GetY;
game.PlaceTile(game.GetPlayingPlayer(), tiledrag!, x, y);
game.PlaceTileNotified -= Game_PlaceTileNotified;
}
private void Game_PlaceTileNotified(object? sender, PlaceTileNotifiedEventArgs args)
{
DisplayAlert("Tile place notified", args.Reason, "<3");
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}