|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Threading.Tasks.Dataflow;
|
|
|
|
@ -16,16 +19,59 @@ 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>
|
|
|
|
|
public class Game
|
|
|
|
|
public class Game : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
/* Persistence */
|
|
|
|
|
public IPersistence PersistenceManager { get; set; }
|
|
|
|
|
|
|
|
|
|
/* List for the game and persistence */
|
|
|
|
|
public List<Player> Players { get; set; }
|
|
|
|
|
public List<Game> Games { get; set; }
|
|
|
|
|
public List<Map> Maps { get; set; }
|
|
|
|
|
public List<BestScore> BestScores { get; set; }
|
|
|
|
|
private ObservableCollection<Player> _players;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<Player> Players
|
|
|
|
|
{
|
|
|
|
|
get => _players;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_players = value;
|
|
|
|
|
OnPropertyChanged(nameof(Players));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<Game> _games;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<Game> Games
|
|
|
|
|
{
|
|
|
|
|
get => _games;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_games = value;
|
|
|
|
|
OnPropertyChanged(nameof(Games));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<Map> _maps;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<Map> Maps
|
|
|
|
|
{
|
|
|
|
|
get => _maps;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_maps = value;
|
|
|
|
|
OnPropertyChanged(nameof(Maps));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<BestScore> _bestScores;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<BestScore> BestScores
|
|
|
|
|
{
|
|
|
|
|
get => _bestScores;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_bestScores = value;
|
|
|
|
|
OnPropertyChanged(nameof(BestScores));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _isRunning;
|
|
|
|
|
public bool IsRunning
|
|
|
|
@ -74,6 +120,17 @@ namespace Models.Game
|
|
|
|
|
BestScores.Add(bestScore);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool RemovePlayer(string playerName)
|
|
|
|
|
{
|
|
|
|
|
Player player = Players.FirstOrDefault(p => p.Pseudo == playerName);
|
|
|
|
|
if (player == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Players.Remove(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadData()
|
|
|
|
|
{
|
|
|
|
|
var data = PersistenceManager.LoadData();
|
|
|
|
@ -101,10 +158,10 @@ namespace Models.Game
|
|
|
|
|
{
|
|
|
|
|
PersistenceManager = persistenceManager;
|
|
|
|
|
|
|
|
|
|
Players = new List<Player>();
|
|
|
|
|
Games = new List<Game>();
|
|
|
|
|
Maps = new List<Map>();
|
|
|
|
|
BestScores = new List<BestScore>();
|
|
|
|
|
Players = new ObservableCollection<Player>();
|
|
|
|
|
Games = new ObservableCollection<Game>();
|
|
|
|
|
Maps = new ObservableCollection<Map>();
|
|
|
|
|
BestScores = new ObservableCollection<BestScore>();
|
|
|
|
|
|
|
|
|
|
GameRules = new Rules.Rules();
|
|
|
|
|
|
|
|
|
@ -113,8 +170,10 @@ namespace Models.Game
|
|
|
|
|
|
|
|
|
|
public Game()
|
|
|
|
|
{
|
|
|
|
|
UsedMap = new Map("Map1");
|
|
|
|
|
BestScores = new List<BestScore>();
|
|
|
|
|
Players = new ObservableCollection<Player>();
|
|
|
|
|
Games = new ObservableCollection<Game>();
|
|
|
|
|
Maps = new ObservableCollection<Map>();
|
|
|
|
|
BestScores = new ObservableCollection<BestScore>();
|
|
|
|
|
|
|
|
|
|
GameRules = new Rules.Rules();
|
|
|
|
|
|
|
|
|
@ -351,5 +410,19 @@ namespace Models.Game
|
|
|
|
|
return true;
|
|
|
|
|
//BoardUpdated?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
public virtual void OnPropertyChanged(string propertyName)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|