Merge branch 'master' of https://codefirst.iut.uca.fr/git/jeremy.mouyon/sae201_qwirkle
continuous-integration/drone/push Build is passing Details

master
rportet 11 months ago
commit d9afae006d

File diff suppressed because one or more lines are too long

@ -64,7 +64,7 @@ public class Cell : INotifyPropertyChanged
/// <returns>True if the cell is empty, false if the cell contains a tile.</returns> /// <returns>True if the cell is empty, false if the cell contains a tile.</returns>
public bool IsFree public bool IsFree
{ {
get { return Tile == null; } get { return Tile! == null!; }
} }
@ -75,7 +75,7 @@ public class Cell : INotifyPropertyChanged
/// <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> /// <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) public bool SetTile(Tile addedTile)
{ {
if (Tile == null) if (Tile! == null!)
{ {
Tile = addedTile; Tile = addedTile;

@ -7,7 +7,6 @@ using QwirkleClassLibrary.Events;
using QwirkleClassLibrary.Players; using QwirkleClassLibrary.Players;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using static System.Formats.Asn1.AsnWriter;
namespace QwirkleClassLibrary.Games namespace QwirkleClassLibrary.Games
{ {
@ -167,7 +166,7 @@ namespace QwirkleClassLibrary.Games
/// Returns the Board of the game /// Returns the Board of the game
/// </summary> /// </summary>
/// <returns>Board</returns> /// <returns>Board</returns>
public Board? GetBoard() public Board GetBoard()
{ {
return board; return board;
} }
@ -365,8 +364,8 @@ namespace QwirkleClassLibrary.Games
return false; return false;
} }
if (!IsMoveCorrect(tile, x, y, board!)) return false; if (!IsMoveCorrect(tile, x, y, board)) return false;
if (board!.AddTileInCell(x, y, tile)) if (board.AddTileInCell(x, y, tile))
{ {
AddCellUsed(board.GetCell(x, y)); AddCellUsed(board.GetCell(x, y));
return player.RemoveTileToPlayer(tile); return player.RemoveTileToPlayer(tile);
@ -477,12 +476,12 @@ namespace QwirkleClassLibrary.Games
previousTilesFound = true; previousTilesFound = true;
} }
if (cellUsed.Contains(extendedCell)) if (cellUsed.Contains(extendedCell!))
{ {
previousTilesFound = true; previousTilesFound = true;
} }
if (extendedCell?.Tile == null) if (extendedCell?.Tile! == null!)
{ {
break; break;
} }
@ -554,8 +553,43 @@ namespace QwirkleClassLibrary.Games
return false; return false;
} }
/// <summary>
/// Check that there isn't any same tile on a said line when a tile is forming a line
/// </summary>
/// <param name="t1"></param>
/// <param name="nbTiles"></param>
/// <param name="checkdoubles"></param>
/// <returns></returns>
public static bool CheckTileInCompletedLines(Tile? t1, ref int nbTiles, ref List<Tile> checkdoubles)
{
if (t1! != null!)
{
nbTiles++;
if (checkdoubles.Any(t => t.CompareTo(t1) == 0))
{
return false;
}
checkdoubles.Add(t1);
}
return true;
}
public bool CheckWrongCompletedLines(Tile tile, int x, int y, int dx, int dy, Board b, ref List<Tile> checkdoubles) /// <summary>
/// Check if the line is completed with the tile placed
/// </summary>
/// <param name="tile"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="dx"></param>
/// <param name="dy"></param>
/// <param name="b"></param>
/// <param name="checkdoubles"></param>
/// <returns></returns>
public static bool CheckWrongCompletedLines(int x, int y, int dx, int dy, Board b, ref List<Tile> checkdoubles)
{ {
int nbTiles = 1; int nbTiles = 1;
@ -564,67 +598,30 @@ namespace QwirkleClassLibrary.Games
var extendedCell = b.GetCell(x + i * dx, y + i * dy); var extendedCell = b.GetCell(x + i * dx, y + i * dy);
var extendedCell2 = b.GetCell(x - i * dx, y - i * dy); var extendedCell2 = b.GetCell(x - i * dx, y - i * dy);
if (extendedCell?.Tile == null && extendedCell2?.Tile == null) if (extendedCell?.Tile! == null! && extendedCell2?.Tile! == null!)
{ {
break; break;
} }
if (extendedCell?.Tile != null)
{
nbTiles++;
foreach (var t in checkdoubles)
{
if (t.CompareTo(extendedCell.Tile) == 0)
{
return false;
}
}
checkdoubles.Add(extendedCell.Tile);
}
if (extendedCell2?.Tile != null)
{
nbTiles++;
foreach (var t in checkdoubles) if(!CheckTileInCompletedLines(extendedCell?.Tile, ref nbTiles, ref checkdoubles)) return false;
{
if (t.CompareTo(extendedCell2.Tile) == 0) if(!CheckTileInCompletedLines(extendedCell2?.Tile, ref nbTiles, ref checkdoubles)) return false;
{
return false;
}
}
checkdoubles.Add(extendedCell2.Tile);
}
} }
return nbTiles <= 6; return nbTiles <= 6;
} }
/// <summary>
/// Main method to check if the move the player is trying to make is correct
/// </summary>
/// <param name="t"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="b"></param>
/// <returns>bool</returns>
public bool IsMoveCorrect(Tile t, int x, int y, Board b) public bool IsMoveCorrect(Tile t, int x, int y, Board b)
{ {
bool previousTilesFound = false;
var checkDoubles = new List<Tile>();
if (!b.HasOccupiedCase()) if (!b.HasOccupiedCase())
{ {
return true; return true;
} }
if (b.GetCell(x, y)!.Tile != null) if (b.GetCell(x, y)!.Tile! != null!)
{ {
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Cell already used !")); OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Cell already used !"));
return false;
} }
var surroundingCells = new List<Cell?> var surroundingCells = new List<Cell?>
@ -634,10 +631,26 @@ namespace QwirkleClassLibrary.Games
b.GetCell(x, y + 1), b.GetCell(x, y + 1),
b.GetCell(x, y - 1) b.GetCell(x, y - 1)
}; };
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;
}
return IsTilePlacementCorrect(t, x, y, b, surroundingCells);
}
public bool IsTilePlacementCorrect(Tile t, int x, int y, Board b, List<Cell?> surroundingCells)
{
bool previousTilesFound = false;
var checkDoubles = new List<Tile>();
foreach (var cell in surroundingCells) foreach (var cell in surroundingCells)
{ {
if (cell?.Tile == null) if (cell?.Tile! == null!)
{ {
continue; continue;
} }
@ -652,7 +665,6 @@ namespace QwirkleClassLibrary.Games
if (cell.Tile.GetColor == t.GetColor && cell.Tile.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 !")); OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " is already placed on the same line / column !"));
return false; return false;
} }
@ -663,26 +675,17 @@ namespace QwirkleClassLibrary.Games
{ {
return false; return false;
} }
if (!CheckWrongCompletedLines(t, x, y, dx, dy, b, ref checkDoubles))
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : You can't complete this line ! (More than 6 tiles / same tiles on the line)"));
return false;
}
}
if (!CheckTilesInLine(cellUsed, b, x, y)) if (CheckWrongCompletedLines(x, y, dx, dy, b, ref checkDoubles)) continue;
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, OnPlaceTile(new PlaceTileNotifiedEventArgs(t,
"isn't on the same line as the ones previously placed !")); " : You can't complete this line ! (More than 6 tiles / same tiles on the line)"));
return false; return false;
} }
if (surroundingCells.All(cell => cell?.Tile == null)) if (!CheckTilesInLine(cellUsed, b, x, y))
{ {
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, OnPlaceTile(new PlaceTileNotifiedEventArgs(t,
" : You can't place a tile that isn't adjacent to another one !")); "isn't on the same line as the ones previously placed !"));
return false; return false;
} }
@ -690,7 +693,6 @@ namespace QwirkleClassLibrary.Games
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, OnPlaceTile(new PlaceTileNotifiedEventArgs(t,
" : You must place your tile next / on the same line as the ones previously placed !")); " : You must place your tile next / on the same line as the ones previously placed !"));
return false; return false;
} }
@ -710,6 +712,9 @@ namespace QwirkleClassLibrary.Games
int score = cellsPlayed.Count; int score = cellsPlayed.Count;
int nbCellsInLine = cellsPlayed.Count; int nbCellsInLine = cellsPlayed.Count;
int nbCellsInPerpLine = 1;
var checkedCells = new List<Cell>();
if (cellsPlayed.Count == 6) if (cellsPlayed.Count == 6)
{ {
@ -740,9 +745,9 @@ namespace QwirkleClassLibrary.Games
} }
score += cellsPlayed.Sum(cell => score += cellsPlayed.Sum(cell =>
CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY, ref nbCellsInLine)); CalculateAdjacentScore(cell, b, cellsPlayed, new Tuple<int, int>(cellsX, cellsY), ref nbCellsInLine, ref nbCellsInPerpLine, ref checkedCells));
if (nbCellsInLine == 6) if (nbCellsInLine == 6 || nbCellsInPerpLine == 6)
{ {
score += 6; score += 6;
} }
@ -762,12 +767,12 @@ namespace QwirkleClassLibrary.Games
/// <param name="cell"></param> /// <param name="cell"></param>
/// <param name="b"></param> /// <param name="b"></param>
/// <param name="cellsPlayed"></param> /// <param name="cellsPlayed"></param>
/// <param name="cellsX"></param> /// <param name="orientation"></param>
/// <param name="cellsY"></param> /// <param name="nbCellsInPerpLine"></param>
/// <param name="checkedCells"></param>
/// <param name="nbCellsInLine"></param> /// <param name="nbCellsInLine"></param>
/// <returns>int</returns> /// <returns>int</returns>
public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, Tuple<int, int> orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells)
int cellsY, ref int nbCellsInLine)
{ {
int score = 0; int score = 0;
@ -779,12 +784,10 @@ namespace QwirkleClassLibrary.Games
b.GetCell(cell.GetX, cell.GetY - 1) b.GetCell(cell.GetX, cell.GetY - 1)
}; };
var checkedSurroundingCells = new List<Cell>();
foreach (var adjacentCell in surroundingCells) foreach (var adjacentCell in surroundingCells)
{ {
if (adjacentCell?.Tile == null || cellsPlayed.Contains(adjacentCell) || if (adjacentCell?.Tile! == null! || cellsPlayed.Contains(adjacentCell) ||
checkedSurroundingCells.Contains(adjacentCell)) checkedCells.Contains(adjacentCell))
{ {
continue; continue;
} }
@ -792,10 +795,10 @@ namespace QwirkleClassLibrary.Games
int dx = adjacentCell.GetX - cell.GetX; int dx = adjacentCell.GetX - cell.GetX;
int dy = adjacentCell.GetY - cell.GetY; int dy = adjacentCell.GetY - cell.GetY;
score += CalculateLineScore(cellsPlayed, cell, new Tuple<int, int>(dx, dy), b, score += CalculateLineScore(cellsPlayed, cell, new Tuple<int, int>(dx, dy),
new Tuple<int, int>(cellsX, cellsY), ref nbCellsInLine); new Tuple<int, int>(orientation.Item1, orientation.Item2), ref nbCellsInLine, ref nbCellsInPerpLine, ref checkedCells);
checkedSurroundingCells.Add(adjacentCell); checkedCells.Add(adjacentCell);
} }
return score; return score;
@ -807,20 +810,20 @@ namespace QwirkleClassLibrary.Games
/// <param name="cellsPlayed"></param> /// <param name="cellsPlayed"></param>
/// <param name="cell"></param> /// <param name="cell"></param>
/// <param name="direction"></param> /// <param name="direction"></param>
/// <param name="b"></param>
/// <param name="orientation"></param> /// <param name="orientation"></param>
/// <param name="nbCellsInLine"></param> /// <param name="nbCellsInLine"></param>
/// <param name="nbCellsInPerpLine"></param>
/// <param name="checkedCells"></param>
/// <returns>int</returns> /// <returns>int</returns>
public int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction, public int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction, Tuple<int, int> orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells)
Board b, Tuple<int, int> orientation, ref int nbCellsInLine)
{ {
int score = 0; int score = 0;
for (int i = 1; i < 6; i++) for (int i = 1; i < 6; i++)
{ {
var extendedCell = b.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2); var extendedCell = board.GetCell(cell.GetX + i * direction.Item1, cell.GetY + i * direction.Item2);
if (extendedCell?.Tile == null || cellsPlayed.Contains(extendedCell)) if (extendedCell?.Tile! == null! || cellsPlayed.Contains(extendedCell) || checkedCells.Contains(extendedCell))
{ {
break; break;
} }
@ -829,12 +832,17 @@ namespace QwirkleClassLibrary.Games
{ {
nbCellsInLine++; nbCellsInLine++;
} }
if (direction.Item1 != 0 && orientation.Item1 != -1 || direction.Item2 != 0 && orientation.Item2 != -1)
{
nbCellsInPerpLine++;
}
checkedCells.Add(extendedCell);
score++; score++;
} }
if (direction.Item1 == 0 && orientation.Item1 == -1 && orientation.Item2 != -1 || if (ShouldIncreaseScore(direction, orientation))
direction.Item2 == 0 && orientation.Item2 == -1 && orientation.Item1 != -1)
{ {
score += 1; score += 1;
} }
@ -842,7 +850,12 @@ namespace QwirkleClassLibrary.Games
return score; return score;
} }
public static bool ShouldIncreaseScore(Tuple<int, int> direction, Tuple<int, int> orientation)
{
return direction.Item1 == 0 && orientation.Item1 == -1 && orientation.Item2 != -1 ||
direction.Item2 == 0 && orientation.Item2 == -1 && orientation.Item1 != -1;
}
/// <summary> /// <summary>
/// Returns the list of the positions of the players who still have tiles in their bag /// Returns the list of the positions of the players who still have tiles in their bag
/// </summary> /// </summary>
@ -876,7 +889,7 @@ namespace QwirkleClassLibrary.Games
{ {
foreach (var t in players[t1].Tiles) foreach (var t in players[t1].Tiles)
{ {
for (int b = 0; b < board!.ReadCells.Count; b++) for (int b = 0; b < board.ReadCells.Count; b++)
{ {
int x = board.ReadCells[b].GetX; int x = board.ReadCells[b].GetX;
int y = board.ReadCells[b].GetY; int y = board.ReadCells[b].GetY;

@ -24,7 +24,9 @@ public interface IPlayer
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b); public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b);
int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, int cellsX, int cellsY, ref int nbCellsInLine); int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, Tuple<int, int> orientation,
ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells);
int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction, Board b, Tuple<int, int> orientation, ref int nbCellsInLine); int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction,
Tuple<int, int> orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells);
} }

@ -41,19 +41,13 @@ namespace QwirkleClassLibrary.Tiles
/// A getter for the shape of the Tile. /// A getter for the shape of the Tile.
/// </summary> /// </summary>
/// <returns>The shape attribute of the Tile.</returns> /// <returns>The shape attribute of the Tile.</returns>
public Shape GetShape public Shape GetShape => shape;
{
get { return shape; }
}
/// <summary> /// <summary>
/// A getter for the color of the Tile. /// A getter for the color of the Tile.
/// </summary> /// </summary>
/// <returns>The color attribute of the Tile.</returns> /// <returns>The color attribute of the Tile.</returns>
public Color GetColor public Color GetColor => color;
{
get { return color; }
}
/// <summary> /// <summary>
/// This method is used to override the ToString() method. It is simply a tool to facilitate the development. /// This method is used to override the ToString() method. It is simply a tool to facilitate the development.
@ -66,20 +60,66 @@ namespace QwirkleClassLibrary.Tiles
public int CompareTo(object? obj) public int CompareTo(object? obj)
{ {
if (obj == null) return 1; if (obj == null)
{
return 1;
}
var otherTile = obj as Tile; var otherTile = obj as Tile;
if (otherTile != null)
if (color == otherTile!.color)
{ {
if (color == otherTile.color) return shape.CompareTo(otherTile.shape);
{ }
return shape.CompareTo(otherTile.shape);
} return color.CompareTo(otherTile.color);
}
return color.CompareTo(otherTile.color); public override bool Equals(object? obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
} }
throw new ArgumentException("Object is not a Tile"); var otherTile = obj as Tile;
return color == otherTile!.color && shape == otherTile.shape;
}
public override int GetHashCode()
{
return HashCode.Combine(color, shape);
}
public static bool operator ==(Tile tile1, Tile tile2)
{
return EqualityComparer<Tile>.Default.Equals(tile1, tile2);
}
public static bool operator !=(Tile tile1, Tile tile2)
{
return !(tile1 == tile2);
}
public static bool operator <(Tile tile1, Tile tile2)
{
return tile1.CompareTo(tile2) < 0;
}
public static bool operator >(Tile tile1, Tile tile2)
{
return tile1.CompareTo(tile2) > 0;
}
public static bool operator <=(Tile tile1, Tile tile2)
{
return tile1.CompareTo(tile2) <= 0;
}
public static bool operator >=(Tile tile1, Tile tile2)
{
return tile1.CompareTo(tile2) >= 0;
} }
} }
} }

@ -74,7 +74,7 @@
ToolTipProperties.Text="Click here to exit ;)" ToolTipProperties.Text="Click here to exit ;)"
Style="{StaticResource GameButton}" /> Style="{StaticResource GameButton}" />
<Label HorizontalOptions="Center" Grid.Row="0" Grid.Column="1" Text="{Binding PlayerList[0].NameTag}"></Label> <Label HorizontalOptions="Center" Grid.Row="0" Grid.Column="1" FontSize="Medium" Text="{Binding PlayerList[0].NameTag}"></Label>
<CollectionView Grid.Row="0" Grid.Column="1" ItemsSource="{Binding PlayerList[0].Tiles}" <CollectionView Grid.Row="0" Grid.Column="1" ItemsSource="{Binding PlayerList[0].Tiles}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center"> VerticalOptions="Center">
@ -98,7 +98,7 @@
</CollectionView> </CollectionView>
<Label HorizontalOptions="Center" Grid.Row="1" Grid.Column="0" Text="{Binding PlayerList[2].NameTag}"></Label> <Label HorizontalOptions="Center" Grid.Row="1" Grid.Column="0" FontSize="Medium" Text="{Binding PlayerList[2].NameTag}"></Label>
<CollectionView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding PlayerList[2].Tiles}" <CollectionView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding PlayerList[2].Tiles}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center"> VerticalOptions="Center">
@ -119,7 +119,7 @@
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<Label HorizontalOptions="Center" Grid.Row="1" Grid.Column="2" Text="{Binding PlayerList[3].NameTag}"></Label> <Label HorizontalOptions="Center" Grid.Row="1" Grid.Column="2" FontSize="Medium" Text="{Binding PlayerList[3].NameTag}"></Label>
<CollectionView Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PlayerList[3].Tiles}" <CollectionView Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PlayerList[3].Tiles}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center"> VerticalOptions="Center">
@ -140,7 +140,7 @@
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<Label HorizontalOptions="Center" VerticalOptions="End" Grid.Row="2" Grid.Column="1" Text="{Binding PlayerList[1].NameTag}"></Label> <Label HorizontalOptions="Center" VerticalOptions="End" Grid.Row="2" Grid.Column="1" FontSize="Medium" Text="{Binding PlayerList[1].NameTag}"></Label>
<CollectionView Grid.Row="2" Grid.Column="1" ItemsSource="{Binding PlayerList[1].Tiles}" <CollectionView Grid.Row="2" Grid.Column="1" ItemsSource="{Binding PlayerList[1].Tiles}"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Start"> VerticalOptions="Start">

@ -54,7 +54,7 @@ public partial class SetPlayers : ContentPage
game.GiveTilesToPlayers(); game.GiveTilesToPlayers();
game.SetNextPlayer(); game.SetNextPlayer();
Shell.Current.GoToAsync("Gameboard"); Shell.Current.GoToAsync("Gameboard");
//Navigation.PushAsync(new Gameboard());
} }

@ -1,4 +1,5 @@
using CommunityToolkit.Maui.Views; using CommunityToolkit.Maui.Views;
using Microsoft.Maui.Controls;
using QwirkleClassLibrary.Games; using QwirkleClassLibrary.Games;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -32,7 +33,8 @@ public partial class PopUpEndGame : Popup
public async void OnButtonNextClick(object sender, EventArgs e) public async void OnButtonNextClick(object sender, EventArgs e)
{ {
await CloseAsync(); Close();
await Shell.Current.GoToAsync("MainPage");
} }
} }

@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks> <TargetFrameworks>net8.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET --> <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> --> <!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
@ -61,15 +60,15 @@
<None Remove="Resources\Fonts\DiloWorld.ttf" /> <None Remove="Resources\Fonts\DiloWorld.ttf" />
<None Remove="Resources\Fonts\Lexend-Medium.ttf" /> <None Remove="Resources\Fonts\Lexend-Medium.ttf" />
<None Remove="Resources\Images\qwirklelogo.png" /> <None Remove="Resources\Images\qwirklelogo.png" />
<None Remove="Resources\Images\uca.png" /> <None Remove="Resources\Images\uca.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" /> <PackageReference Include="CommunityToolkit.Maui" Version="9.0.1" />
<PackageReference Include="CommunityToolkit.Maui.MediaElement" Version="3.1.1" /> <PackageReference Include="CommunityToolkit.Maui.MediaElement" Version="3.1.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.40" /> <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.40" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.40" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.40" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0-preview.4.24266.19" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -287,25 +287,6 @@ public class TestGame
Assert.False(game.PlaceTile(game.GetPlayingPlayer(), game.PlayerList[game.GetPlayingPlayerPosition()].Tiles[0], -5, 1)); Assert.False(game.PlaceTile(game.GetPlayingPlayer(), game.PlayerList[game.GetPlayingPlayerPosition()].Tiles[0], -5, 1));
} }
// [Fact]
// public void Test_DrawTile()
// {
// Game game = new Game();
// game.AddPlayerInGame("Test1");
// game.AddPlayerInGame(playerstest);
//
// game.StartGame();
// game.SetNextPlayer();
//
// Assert.True(game.DrawTiles(game.GetPlayingPlayer()));
//
// /*test*/
// TileBag bag = new TileBag(0);
// Assert.False(game.DrawTiles(game.GetPlayingPlayer()));
// return;
//
// }
[Theory] [Theory]
[InlineData(true)] [InlineData(true)]
[InlineData(false)] [InlineData(false)]
@ -342,6 +323,48 @@ public class TestGame
Assert.Equal(p, events.Player); Assert.Equal(p, events.Player);
} }
[Fact]
public void Test_IsTilePlacementCorrect()
{
var game = new Game();
var board = new Board(17, 14);
var tile = new Tile(Shape.Club, Color.Red);
board.AddTileInCell(0, 1, new Tile(Shape.Club, Color.Blue));
var x = 1;
var y = 1;
var surroundingCells = new List<Cell?>
{
board.GetCell(x + 1, y),
board.GetCell(x - 1, y),
board.GetCell(x, y + 1),
board.GetCell(x, y - 1)
};
bool result = game.IsTilePlacementCorrect(tile, x, y, board, surroundingCells);
Assert.True(result);
}
[Fact]
public void Test_IsMoveCorrect()
{
var game = new Game();
var board = new Board(17, 14);
var tile = new Tile(Shape.Club, Color.Red);
board.AddTileInCell(0, 1, new Tile(Shape.Club, Color.Blue));
var x = 2;
var y = 1;
bool result = game.IsMoveCorrect(tile, x, y, board);
Assert.False(result);
}
[Fact] [Fact]
public void Test_IsMoveCorrectSixLine() public void Test_IsMoveCorrectSixLine()
{ {
@ -381,6 +404,41 @@ public class TestGame
} }
[Fact]
public void Test_CheckTileInCompletedLines()
{
int nbTiles = 0;
var checkdoubles = new List<Tile>()
{
new(Shape.Club, Color.Blue),
new(Shape.Club, Color.Red),
new(Shape.Club, Color.Green),
};
var t1 = new Tile(Shape.Club, Color.Green);
Assert.False(Game.CheckTileInCompletedLines(t1, ref nbTiles, ref checkdoubles));
}
[Fact]
public void Test_CheckWrongCompletedLines()
{
var board = new Board(17, 14);
var checkDoubles = new List<Tile>();
int x = 4, y = 1, dx = 1, dy = 0;
board.AddTileInCell(1, 1, new Tile(Shape.Club, Color.Red));
board.AddTileInCell(2, 1, new Tile(Shape.Square, Color.Red));
board.AddTileInCell(3, 1, new Tile(Shape.Star, Color.Red));
board.AddTileInCell(5, 1, new Tile(Shape.Round, Color.Red));
board.AddTileInCell(6, 1, new Tile(Shape.Shuriken, Color.Red));
board.AddTileInCell(7, 1, new Tile(Shape.Rhombus, Color.Red));
bool result = Game.CheckWrongCompletedLines(x, y, dx, dy, board, ref checkDoubles);
Assert.False(result);
}
[Theory] [Theory]
[InlineData(3, 1, 4, 1, 5, 1, 5)] [InlineData(3, 1, 4, 1, 5, 1, 5)]
[InlineData(2, 2, 3, 2, 4, 2, 5)] [InlineData(2, 2, 3, 2, 4, 2, 5)]
@ -389,7 +447,7 @@ public class TestGame
{ {
var game = new Game(); var game = new Game();
var player = new Player("TestPlayer"); var player = new Player("TestPlayer");
var board = new Board(8, 8); var board = game.GetBoard();
board.AddTileInCell(1, 1, new Tile(Shape.Club, Color.Red)); board.AddTileInCell(1, 1, new Tile(Shape.Club, Color.Red));
board.AddTileInCell(2, 1, new Tile(Shape.Square, Color.Red)); board.AddTileInCell(2, 1, new Tile(Shape.Square, Color.Red));
@ -413,6 +471,14 @@ public class TestGame
Assert.Equal(expectedScore, score); Assert.Equal(expectedScore, score);
} }
[Theory]
[InlineData(0, -1, -1, 6)]
[InlineData(1, 0, 4, -1)]
public void Test_ShouldIncreaseScore(int dx, int dy, int cellsX, int cellsY)
{
Assert.True(Game.ShouldIncreaseScore(new Tuple<int, int>(dx, dy), new Tuple<int, int>(cellsX, cellsY)));
}
[Fact] [Fact]
public void Test_EndOfGame() public void Test_EndOfGame()

Loading…
Cancel
Save