Merge PageBoard into dev (#123)
continuous-integration/drone/push Build is failing Details

pull/99/head
Rémi LAVERGNE 1 year ago
commit 6aa9e768e9

@ -69,7 +69,7 @@ class Program
static void OnBoardUpdated(object sender, EventArgs e)
{
DisplayBoard(((Game)sender).UsedMap);
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid);
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList());
}
/// <summary>
@ -92,7 +92,7 @@ class Program
static void OnOperationChosen(object sender, OperationChosenEventArgs e)
{
Console.WriteLine($"Operation: {e.Operation}, Result: {e.Result}");
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid);
DisplayOperationTable(((Game)sender).UsedMap.OperationGrid.ToList());
Cell playerChoice = GetPlayerChoice();
bool test = ((Game)sender).HandlePlayerChoice(playerChoice, e.Result);
if(!test)

@ -24,7 +24,10 @@
/// <summary>
/// The fact that the cell is dangerous or not.
/// </summary>
private bool IsDangerous { get; set; }
public bool IsDangerous { get; set; }
public bool Valid { get; set; }
/// <summary>
/// Atribute to know if the cell is a penalty cell.
@ -41,6 +44,7 @@
{
IsDangerous = isDangerous;
Penalty = false;
Valid = false;
}
/// <summary>

@ -176,7 +176,7 @@ namespace Models.Game
/// <param name="result">The result of the dice operation to be placed in the cell.</param>
private bool PlaceResult(Cell playerChoice, int result)
{
if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards))
if (Turn == 1 || GameRules.NearCellIsValid(playerChoice, UsedMap.Boards.ToList()))
{
for (int i = 0; i < UsedMap.Boards.Count; i++)
{
@ -323,7 +323,7 @@ namespace Models.Game
//throw new InvalidCellCoordinatesException("Invalid cell coordinates. Please choose again.");
}
if (!GameRules.IsCellValid(cell, UsedMap.Boards))
if (!GameRules.IsCellValid(cell, UsedMap.Boards.ToList()))
{
return false;
//throw new InvalidCellException("Cell is not valid. Please choose again.");
@ -336,7 +336,7 @@ namespace Models.Game
//throw new InvalidPlaceResultException("Cell is not valid for place result. Please choose again.");
}
GameRules.IsZoneValidAndAddToZones(cell, UsedMap);
AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards));
AddToRopePath(cell, GameRules.EveryAdjacentCells(cell, UsedMap.Boards.ToList()));
CellChosen?.Invoke(this, new CellChosenEventArgs(cell, result));
return true;
//BoardUpdated?.Invoke(this, EventArgs.Empty);

@ -1,4 +1,6 @@
namespace Models.Game
using System.Collections.ObjectModel;
namespace Models.Game
{
/// <summary>
@ -9,7 +11,8 @@
/// <summary>
/// It is the list of cells on the map.
/// </summary>
public List<Cell> Boards { get; private set; }
public ReadOnlyObservableCollection<Cell> Boards { get; private set; }
ObservableCollection<Cell> board = new ObservableCollection<Cell>();
/// <summary>
/// It is the backgrond image of the map
@ -19,7 +22,8 @@
/// <summary>
/// It is the grid of the possible operation in the game
/// </summary>
public List<OperationCell> OperationGrid { get; private set; }
public ReadOnlyObservableCollection<OperationCell> OperationGrid { get; private set; }
ObservableCollection<OperationCell> operationGrid = new ObservableCollection<OperationCell>();
/// <summary>
/// It is a list of a list containing user's rope paths in the current game
@ -37,9 +41,11 @@
/// <param name="background">The background of the map.</param>
public Map(string background)
{
Boards = InitializeBoards();
Boards = new ReadOnlyObservableCollection<Cell>(board);
InitializeBoards(board);
Background = background;
OperationGrid = InitializeOperationGrid();
OperationGrid = new ReadOnlyObservableCollection<OperationCell>(operationGrid);
InitializeOperationGrid(operationGrid);
RopePaths = new List<List<Cell>>();
Zones = new List<List<Cell>>();
}
@ -48,23 +54,43 @@
/// Initializes the boards of the map.
/// </summary>
/// <returns>Return the boards</returns>
private List<Cell> InitializeBoards()
private void InitializeBoards(ObservableCollection<Cell> board)
{
var boards = new List<Cell>();
for (int i = 0; i < 36; i++) // 6x6 board
for (int i = 0; i < 49; i++) // 6x6 board
{
boards.Add(new Cell(i / 6, i % 6));
board.Add(new Cell(i / 7, i % 7));
}
return boards;
board[1].Valid = true;
board[3].Valid = true;
board[4].Valid = true;
board[5].Valid = true;
board[9].Valid = true;
board[12].Valid = true;
board[15].Valid = true;
board[16].Valid = true;
board[17].Valid = true;
board[21].Valid = true;
board[24].Valid = true;
board[25].Valid = true;
board[28].Valid = true;
board[30].Valid = true;
board[31].Valid = true;
board[32].Valid = true;
board[40].Valid = true;
board[41].Valid = true;
board[48].Valid = true;
board[3].IsDangerous = true;
board[15].IsDangerous = true;
board[16].IsDangerous = true;
}
/// <summary>
/// Initializes the operation grid of the map.
/// </summary>
/// <returns>Return the operation grid</returns>
private List<OperationCell> InitializeOperationGrid()
private void InitializeOperationGrid(ObservableCollection<OperationCell>operationGrid)
{
var operationGrid = new List<OperationCell>();
for (int i = 0; i < 5; i++) // 5 operations
{
for (int j = 0; j < 4; j++) // 4 cells per operation
@ -72,7 +98,6 @@
operationGrid.Add(new OperationCell(i, j));
}
}
return operationGrid;
}
public bool CheckOperationPossible(int x)

@ -1,3 +1,5 @@
using System.ComponentModel;
namespace Models.Game
{
/// <summary>
@ -5,10 +7,20 @@ namespace Models.Game
/// </summary>
public class OperationCell : Position
{
private bool isChecked;
/// <summary>
/// It tells if the operation is checked or not in the operation grid of the game.
/// </summary>
public bool IsChecked { get; private set; }
public bool IsChecked
{
get => isChecked;
private set
{
isChecked = value;
OnPropertyChanged(nameof(IsChecked));
}
}
/// <summary>
/// Constructor of the OperationCell class.

@ -1,10 +1,13 @@
namespace Models.Game
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Models.Game
{
/// <summary>
/// The Position (x,y) of a cell in the game.
/// </summary>
public class Position
public class Position : INotifyPropertyChanged
{
/// <summary>
/// The X coordinate.
@ -26,5 +29,19 @@
X = x;
Y = y;
}
/// <summary>
/// Event raised when a property is changed to notify the view.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Trigger the PropertyChanged event for a specific property.
/// </summary>
/// <param name="propertyName">Name of the property that changed.</param>
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -130,7 +131,7 @@ namespace Models.Rules
List<Cell> adjacentCells = new List<Cell>();
adjacentCells = EveryAdjacentCells(chosenCell, map.Boards);
adjacentCells = EveryAdjacentCells(chosenCell, map.Boards.ToList());
foreach(var cells in adjacentCells)
{

@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Data;
using System.Numerics;
using Models.Game;
@ -14,9 +14,9 @@ namespace Stub
public Stub()
{
LoadPlayer();
ListPlayer = new ReadOnlyObservableCollection<Player>(listplayer);
ListMap = new ReadOnlyObservableCollection<Map>(listmap);
LoadPlayer();
LoadMap();
}
@ -27,14 +27,8 @@ namespace Stub
listplayer.Add(new Player("Lucas", "profile.jpg"));
listplayer.Add(new Player("relavergne", "profile.jpg"));
listplayer.Add(new Player("reneveu", "profile.jpg"));
}
public void Add(string pseudo, string profilePicture)
{
listplayer.Add(new Player(pseudo, profilePicture));
}
public void LoadMap()
{
@ -43,14 +37,19 @@ namespace Stub
listmap.Add(new Map("tmp1.jpeg"));
}
public void Add(string pseudo, string profilePicture)
{
listplayer.Add(new Player(pseudo, profilePicture));
}
public void Pop(string pseudo, string profilePicture)
{
listplayer.Remove(new Player(pseudo, profilePicture));
}
public bool Modify(string pseudo, string newpseudo)
{
foreach(var index in listplayer)
foreach (var index in listplayer)
{
if (index.Pseudo == pseudo)
{
@ -58,6 +57,7 @@ namespace Stub
return true;
}
}
return false;
}
}

@ -35,7 +35,7 @@ public class RulesTests
Map map = new Map("background");
Cell selectedCell = map.Boards[0];
selectedCell.Value = 5;
Assert.False(rules.IsCellValid(selectedCell, map.Boards));
Assert.False(rules.IsCellValid(selectedCell, map.Boards.ToList()));
}
[Fact]
@ -44,7 +44,7 @@ public class RulesTests
Rules rules = new Rules();
Map map = new Map("background");
Cell selectedCell = map.Boards[0];
Assert.True(rules.IsCellValid(selectedCell, map.Boards));
Assert.True(rules.IsCellValid(selectedCell, map.Boards.ToList()));
}
[Fact]
@ -211,7 +211,7 @@ public class RulesTests
Cell adjacentCell = new Cell(0, 1);
adjacentCell.Value = 1;
map.Boards.Add(adjacentCell);
map.Boards.ToList().Add(adjacentCell);
map.Zones.Add(new List<Cell> { adjacentCell });
rules.IsZoneValidAndAddToZones(cell, map);
@ -228,7 +228,7 @@ public class RulesTests
Cell adjacentCell = new Cell(0, 1);
adjacentCell.Value = 1;
map.Boards.Add(adjacentCell);
map.Boards.ToList().Add(adjacentCell);
rules.IsZoneValidAndAddToZones(cell, map);
Assert.Contains(cell, map.Zones[0]);
}

@ -34,9 +34,9 @@
ContentTemplate="{DataTemplate views:PageSelectMap}"
Route="PageSelectMap"/>
<!--<ShellContent
Title="Plateau"
ContentTemplate="{DataTemplate views:PagePlateau}"
Route="Plateau"/>-->
<ShellContent
Title="Board"
ContentTemplate="{DataTemplate views:PageBoard}"
Route="Board"/>
</Shell>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 KiB

@ -56,6 +56,11 @@
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<None Remove="Resources\Images\checked.png" />
<None Remove="Resources\Images\maptest.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="7.0.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
@ -84,6 +89,9 @@
<MauiXaml Update="Views\Components\ContentLeaderBoard.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\PageBoard.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\PageLeaderBoard.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Trek_12.Views.PageBoard"
Title="Board"
BackgroundColor="Bisque">
<Grid RowDefinitions="*,auto" ColumnDefinitions="*,auto">
<Image Source="maptest.png" Aspect="AspectFit" Grid.ColumnSpan="2" Grid.RowSpan="3"/>
<CollectionView ItemsSource="{Binding ListMap[0].Boards}"
Grid.Row="1"
Grid.Column="0"
SelectionMode="Single"
WidthRequest="350"
HeightRequest="350"
ItemsLayout="VerticalGrid,7"
BackgroundColor="Aqua">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="50" WidthRequest="50">
<Frame
IsVisible="{Binding Valid}"
BorderColor="DarkGray"
CornerRadius="25"
HeightRequest="50"
WidthRequest="50"
BackgroundColor="White"
Opacity="0.7"
VerticalOptions="Center"
HorizontalOptions="Center"
Padding="0">
<Frame.Triggers>
<DataTrigger TargetType="Frame" Binding="{Binding IsDangerous}" Value="True">
<Setter Property="BorderColor" Value="Black"/>
</DataTrigger>
<DataTrigger TargetType="Frame" Binding="{Binding IsDangerous}" Value="False">
<Setter Property="BorderColor" Value="Transparent"/>
</DataTrigger>
</Frame.Triggers>
</Frame>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<!-- Operation Grid -->
<CollectionView Grid.Row="0" Grid.Column="1"
ItemsSource="{Binding ListMap[0].OperationGrid}"
ItemsLayout="VerticalGrid,4"
WidthRequest="200"
HeightRequest="250"
BackgroundColor="Transparent"
SelectionChanged="OnOperationCellSelected"
Margin="50">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame HasShadow="True"
BorderColor="Black"
BackgroundColor="Transparent"
CornerRadius="0"
HorizontalOptions="Center"
VerticalOptions="Center"
HeightRequest="50"
WidthRequest="50"
Padding="0">
<Image Source="checked.png"
IsVisible="{Binding IsChecked}"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</ContentPage>

@ -0,0 +1,32 @@
using System.Diagnostics;
namespace Trek_12.Views;
using Models.Game;
using Stub;
public partial class PageBoard : ContentPage
{
public Stub MyStub { get; set; } = new Stub();
public PageBoard()
{
InitializeComponent();
BindingContext = MyStub;
}
private void OnOperationCellSelected(object sender, SelectionChangedEventArgs e)
{
Debug.WriteLine("OnOperationCellSelected"); // Debug
if (e.CurrentSelection.Count > 0) // Si un élément est sélectionné
{
var selectedCell = (OperationCell)e.CurrentSelection[0];
if (selectedCell != null && !selectedCell.IsChecked)
{
selectedCell.Check();
Debug.WriteLine("OperationCell at ({0}, {1}) is checked", selectedCell.X, selectedCell.Y); // Debug
}
((CollectionView)sender).SelectedItem = null; // Déselectionne l'élément pour la CollectionView
}
}
}
Loading…
Cancel
Save