|
|
|
@ -13,6 +13,7 @@ using System.Threading.Tasks.Dataflow;
|
|
|
|
|
using Models.Events;
|
|
|
|
|
using Models.Interfaces;
|
|
|
|
|
using Models.Rules;
|
|
|
|
|
using SQLite;
|
|
|
|
|
|
|
|
|
|
namespace Models.Game
|
|
|
|
|
{
|
|
|
|
@ -20,16 +21,21 @@ namespace Models.Game
|
|
|
|
|
/// The Game class represents a game session in the application.
|
|
|
|
|
/// It contains all the necessary properties and methods to manage a game, including the game loop, dice rolling, and use of the game rules.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataContract]
|
|
|
|
|
[DataContract, SQLite.Table("Games")]
|
|
|
|
|
public class Game : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
public bool IsPreviousGameNotFinished { get; private set; }
|
|
|
|
|
|
|
|
|
|
[PrimaryKey, AutoIncrement]
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/* Persistence Interface */
|
|
|
|
|
[Ignore]
|
|
|
|
|
public IPersistence PersistenceManager { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* List for the game and persistence */
|
|
|
|
|
private ObservableCollection<Player> _players;
|
|
|
|
|
[Ignore]
|
|
|
|
|
public ObservableCollection<Player> Players
|
|
|
|
|
{
|
|
|
|
|
get => _players;
|
|
|
|
@ -41,6 +47,7 @@ namespace Models.Game
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<Game> _games;
|
|
|
|
|
[Ignore]
|
|
|
|
|
public ObservableCollection<Game> Games
|
|
|
|
|
{
|
|
|
|
|
get => _games;
|
|
|
|
@ -52,6 +59,7 @@ namespace Models.Game
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<Map> _maps;
|
|
|
|
|
[Ignore]
|
|
|
|
|
public ObservableCollection<Map> Maps
|
|
|
|
|
{
|
|
|
|
|
get => _maps;
|
|
|
|
@ -63,6 +71,7 @@ namespace Models.Game
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<BestScore> _bestScores;
|
|
|
|
|
[Ignore]
|
|
|
|
|
public ObservableCollection<BestScore> BestScores
|
|
|
|
|
{
|
|
|
|
|
get => _bestScores;
|
|
|
|
@ -96,16 +105,20 @@ namespace Models.Game
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Ignore]
|
|
|
|
|
public Dice Dice1 { get; private set;}
|
|
|
|
|
|
|
|
|
|
[Ignore]
|
|
|
|
|
public Dice Dice2 { get; private set; }
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
|
public int Turn { get; set; }
|
|
|
|
|
|
|
|
|
|
[Ignore]
|
|
|
|
|
public Operation PlayerOperation { get; set; }
|
|
|
|
|
|
|
|
|
|
private Cell _playerCell;
|
|
|
|
|
[Ignore]
|
|
|
|
|
public Cell PlayerCell {
|
|
|
|
|
get => _playerCell;
|
|
|
|
|
set
|
|
|
|
@ -128,6 +141,7 @@ namespace Models.Game
|
|
|
|
|
public bool DiceRolledFlag { get; private set; }
|
|
|
|
|
public bool OperationChosenFlag { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Ignore]
|
|
|
|
|
public Rules.Rules GameRules { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -424,22 +438,22 @@ namespace Models.Game
|
|
|
|
|
where cell.Value != null && cell.Valid == true && cell != playerChoice
|
|
|
|
|
select cell;
|
|
|
|
|
|
|
|
|
|
foreach (var item in ValidCell)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in ValidCell)
|
|
|
|
|
{
|
|
|
|
|
if (!GameRules.IsCellAdjacent(playerChoice, item))
|
|
|
|
|
continue;
|
|
|
|
|
if (!((playerChoice.Value - item.Value) == 1 || (playerChoice.Value - item.Value) == -1))
|
|
|
|
|
continue;
|
|
|
|
|
continue;
|
|
|
|
|
if (!((playerChoice.Value - item.Value) == 1 || (playerChoice.Value - item.Value) == -1))
|
|
|
|
|
continue;
|
|
|
|
|
if (!GameRules.IsInRopePaths(item,UsedMap.RopePaths,index))
|
|
|
|
|
{
|
|
|
|
|
UsedMap.RopePaths.Add(new List<Cell> { playerChoice, item });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!GameRules.AsValue(playerChoice, UsedMap.RopePaths, index))
|
|
|
|
|
{
|
|
|
|
|
UsedMap.RopePaths[index].Add(playerChoice);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|