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

test_old_branch
Jérémy Mouyon 11 months ago
parent 566f6c2e09
commit bb50f74158

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Text;
@ -14,12 +16,21 @@ namespace QwirkleClassLibrary.Boards
/// This class is used to create the board for our Qwirkle Game. It uses others classes, such as Cell and Tile, to take care of the tiles placements during the game.
/// </summary>
[DataContract]
public class Board
public class Board : INotifyPropertyChanged
{
public ReadOnlyCollection<Cell> ReadCells => cells.AsReadOnly();
public event PropertyChangedEventHandler? PropertyChanged;
[DataMember]
private readonly List<Cell> cells = new();
private ObservableCollection<Cell> cells = new ObservableCollection<Cell>();
public ObservableCollection<Cell> ReadCells
{
get { return cells; }
set
{
cells = value;
OnPropertyChanged(nameof(ReadCells));
}
}
public int Rows { get; }
public int Columns { get; }
@ -54,6 +65,7 @@ namespace QwirkleClassLibrary.Boards
{
if (!cell.IsFree)
{
OnPropertyChanged(nameof(ReadCells));
return true;
}
}
@ -74,9 +86,11 @@ namespace QwirkleClassLibrary.Boards
if (t.GetX != x || t.GetY != y) continue;
if (t.IsFree)
{
OnPropertyChanged(nameof(ReadCells));
return t.SetTile(tile);
}
}
OnPropertyChanged(nameof(ReadCells));
return false;
}
@ -87,16 +101,7 @@ namespace QwirkleClassLibrary.Boards
/// <returns>The cells of the board in a List format.</returns>
public List<Cell> GetCells()
{
return cells;
}
/// <summary>
/// A getter for the ReadCells attribute of the Board Class.
/// </summary>
/// <returns>The cells of the board, but in a IReadOnlyCollection format.</returns>
public IReadOnlyCollection<Cell> GetReadCells()
{
return ReadCells;
return cells.ToList();
}
/// <summary>
@ -117,5 +122,9 @@ namespace QwirkleClassLibrary.Boards
return null;
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

@ -1,4 +1,5 @@
// ReSharper disable All
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using QwirkleClassLibrary.Tiles;
@ -6,8 +7,10 @@ using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Boards;
[DataContract]
public class Cell
public class Cell : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
[DataMember]
private readonly int x;
@ -15,7 +18,7 @@ public class Cell
private readonly int y;
[DataMember]
private Tile? tile = null;
public Tile? Tile { get; private set;}
/// <summary>
/// This is the constructor for a Cell.
@ -58,17 +61,9 @@ public class Cell
/// <returns>True if the cell is empty, false if the cell contains a tile.</returns>
public bool IsFree
{
get { return tile == null; }
get { return Tile == null; }
}
/// <summary>
/// A getter for the tile in the cell.
/// </summary>
/// <returns>The tile if the cell isn't empty, null otherwise.</returns>
public Tile? GetTile
{
get { return tile; }
}
/// <summary>
/// A setter for the tile in the cell.
@ -77,9 +72,11 @@ public class Cell
/// <returns>True if added succefully (if the cell didn't already contain a tile), false if there already was a tile in this cell.</returns>
public bool SetTile(Tile addedTile)
{
if (tile == null)
if (Tile == null)
{
tile = addedTile;
Tile = addedTile;
OnPropertyChanged(nameof(Tile));
return true;
}
else
@ -87,4 +84,9 @@ public class Cell
return false;
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

@ -32,8 +32,6 @@ namespace QwirkleClassLibrary.Games
private Board board = new Board(15, 12);
public Board Board => board;
public ObservableCollection<Cell> GetCellsInBoard => new ObservableCollection<Cell>(board!.GetCells());
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
private readonly List<Player> players = new();
@ -411,18 +409,18 @@ namespace QwirkleClassLibrary.Games
{
var extendedCell = b.GetCell(x + i * dx, y + i * dy);
if (extendedCell?.GetTile == null)
if (extendedCell?.Tile == null)
{
break;
}
if (extendedCell.GetTile.GetColor != tile.GetColor && extendedCell.GetTile.GetShape != tile.GetShape)
if (extendedCell.Tile.GetColor != tile.GetColor && extendedCell.Tile.GetShape != tile.GetShape)
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, " : Color / Shape does not match with the surrounding tiles !"));
return false;
}
if (extendedCell.GetTile.GetColor == tile.GetColor && extendedCell.GetTile.GetShape == tile.GetShape)
if (extendedCell.Tile.GetColor == tile.GetColor && extendedCell.Tile.GetShape == tile.GetShape)
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, " : Tile already placed on the same line / column !"));
return false;
@ -496,7 +494,7 @@ namespace QwirkleClassLibrary.Games
return true;
}
if (b.GetCell(x, y)!.GetTile == null)
if (b.GetCell(x, y)!.Tile == null)
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, ": Cell already used !"));
}
@ -511,18 +509,18 @@ namespace QwirkleClassLibrary.Games
foreach (var cell in surroundingCells)
{
if (cell?.GetTile == null)
if (cell?.Tile == null)
{
continue;
}
if (cell.GetTile.GetColor != t.GetColor && cell.GetTile.GetShape != t.GetShape)
if (cell.Tile.GetColor != t.GetColor && cell.Tile.GetShape != t.GetShape)
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Colors / Shapes do not match with the surrounding tiles !"));
return false;
}
if (cell.GetTile.GetColor == t.GetColor && cell.GetTile.GetShape == t.GetShape)
if (cell.Tile.GetColor == t.GetColor && cell.Tile.GetShape == t.GetShape)
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " is already placed on the same line / column !"));
@ -545,7 +543,7 @@ namespace QwirkleClassLibrary.Games
return false;
}
if (surroundingCells.All(cell => cell?.GetTile == null))
if (surroundingCells.All(cell => cell?.Tile == null))
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't place a tile that isn't adjacent to another one !"));
return false;
@ -641,7 +639,7 @@ namespace QwirkleClassLibrary.Games
foreach (var adjacentCell in surroundingCells)
{
if (adjacentCell?.GetTile == null || cellsPlayed.Contains(adjacentCell) || checkedSurroundingCells.Contains(adjacentCell))
if (adjacentCell?.Tile == null || cellsPlayed.Contains(adjacentCell) || checkedSurroundingCells.Contains(adjacentCell))
{
continue;
}
@ -675,7 +673,7 @@ namespace QwirkleClassLibrary.Games
{
var extendedCell = b.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2);
if (extendedCell?.GetTile == null || cellsPlayed.Contains(extendedCell))
if (extendedCell?.Tile == null || cellsPlayed.Contains(extendedCell))
{
break;
}

@ -7,9 +7,10 @@ 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 partial class Gameboard : ContentPage
{
public ICommand OnDrop => new Command<Cell>(OnDropTile);
@ -17,31 +18,15 @@ public partial class Gameboard : ContentPage, INotifyPropertyChanged
private Tile? tiledrag;
private ObservableCollection<Tile> playerCells1;
public ObservableCollection<Tile> PlayerCells1
{
get => playerCells1;
set
{
playerCells1 = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("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)
foreach (var t in game.PlayerList[game.GetPlayingPlayerPosition()].Tiles)
{
if (e.Data.Text == t.ToString())
{
@ -62,14 +47,10 @@ public partial class Gameboard : ContentPage, INotifyPropertyChanged
game.PlaceTile(game.GetPlayingPlayer(), tiledrag!, x, y);
game.PlaceTileNotified -= Game_PlaceTileNotified;
PlayerCells1 = new ObservableCollection<Tile>(game.PlayerList[0].Tiles.ToList());
}
private void Game_PlaceTileNotified(object? sender, PlaceTileNotifiedEventArgs args)
{
DisplayAlert("Tile place notified", args.Reason, "<3");
}
public event PropertyChangedEventHandler? PropertyChanged;
}

@ -9,7 +9,7 @@
<StackLayout>
<CollectionView ItemsSource="{Binding GetCellsInBoard}"
<CollectionView ItemsSource="{Binding Board.ReadCells}"
HorizontalOptions="Center"
VerticalOptions="Center">
<CollectionView.ItemsLayout>
@ -26,13 +26,13 @@
DropCommand="{Binding OnDrop, Source={x:Reference root}}"
DropCommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<Label Text="{Binding GetTile.Name}" />
<Label Text="{Binding tile}" />
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<CollectionView ItemsSource="{Binding PlayerCells1, Source={x:Reference root}}"
<CollectionView ItemsSource="{Binding PlayerList[0].Tiles}"
HorizontalOptions="Center"
VerticalOptions="Start" >
<CollectionView.ItemsLayout>
@ -51,8 +51,34 @@
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<CollectionView ItemsSource="{Binding PlayerList[1].Tiles}"
HorizontalOptions="End"
VerticalOptions="End" >
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border WidthRequest="70" HeightRequest="70"
BackgroundColor="WhiteSmoke"
Margin="0">
<Label Text="{Binding}">
<Label.GestureRecognizers>
<DragGestureRecognizer />
</Label.GestureRecognizers>
</Label>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</ScrollView>

@ -66,25 +66,6 @@ public class TestBoard
Assert.Equal((12 * 12), board.GetCells().Count);
}
[Fact]
public void Test_GetReadCells()
{
Board board = new Board(12, 12);
List<Cell> cells = new List<Cell>();
for (int a = 0; a < 12; a++)
{
for (int b = 0; b < 12; b++)
{
Cell localcell = new(a, b);
cells.Add(localcell);
}
}
ReadOnlyCollection<Cell> readCells = cells.AsReadOnly();
Assert.Equal(readCells.Count, board.GetReadCells().Count);
}
[Theory]
[InlineData(true)]

Loading…
Cancel
Save