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.
61 lines
1.6 KiB
61 lines
1.6 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
|
|
{
|
|
public ICommand OnDrop => new Command<Cell>(OnDropTile);
|
|
|
|
private Game game = ((App)Application.Current!).Game;
|
|
|
|
private Tile? tiledrag;
|
|
|
|
public Gameboard()
|
|
{
|
|
InitializeComponent();
|
|
BindingContext = game;
|
|
|
|
}
|
|
private void OnDragStarting(object sender, DragStartingEventArgs e)
|
|
{
|
|
var tile = (sender as Element).BindingContext as Tile;
|
|
e.Data.Text = tile?.ToString();
|
|
tiledrag = tile;
|
|
}
|
|
|
|
private void OnDragOver(object sender, DragEventArgs e)
|
|
{
|
|
e.AcceptedOperation = DataPackageOperation.Copy;
|
|
}
|
|
|
|
|
|
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)
|
|
{
|
|
if(args.Tile != null)
|
|
{
|
|
DisplayAlert("Tile place notified", args.Tile.ToString() + args.Reason, "<3");
|
|
return;
|
|
}
|
|
DisplayAlert("Tile place notified", args.Tile.ToString() + args.Reason, "<3");
|
|
}
|
|
} |