🏗️ Fix #67
continuous-integration/drone/push Build is passing Details

pull/75/head
Alexis Drai 2 years ago
parent 4fe026a094
commit aaa94de362

@ -2,6 +2,7 @@
using Model.Dice.Faces; using Model.Dice.Faces;
using Model.Games; using Model.Games;
using Model.Players; using Model.Players;
using System.Collections.Generic;
namespace Data namespace Data
{ {
@ -18,14 +19,18 @@ namespace Data
Player player1 = new("Alice"), player2 = new("Bob"), player3 = new("Clyde"); Player player1 = new("Alice"), player2 = new("Bob"), player3 = new("Clyde");
FavGroupManager favGroupManager = new(new DieManager()); DieManager globalDieManager = new DieManager();
// create at least one fav group in there // create at least one fav group in there
// ... // ...
IEnumerable<AbstractDie<AbstractDieFace>> dice1;
(_, dice1) = globalDieManager.GetAll().First();
IEnumerable<AbstractDie<AbstractDieFace>> dice2;
(_, dice2) = globalDieManager.GetAll().Last();
Game game1 = new(name: g1, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().First()); Game game1 = new(name: g1, playerManager: new PlayerManager(), dice: dice1);
Game game2 = new(name: g2, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().Last()); Game game2 = new(name: g2, playerManager: new PlayerManager(), dice: dice2);
Game game3 = new(name: g3, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().First()); Game game3 = new(name: g3, playerManager: new PlayerManager(), dice: dice1);
List<Game> games = new() { game1, game2, game3 }; List<Game> games = new() { game1, game2, game3 };
@ -34,7 +39,7 @@ namespace Data
globalPlayerManager.Add(player2); globalPlayerManager.Add(player2);
globalPlayerManager.Add(player3); globalPlayerManager.Add(player3);
GameRunner gameRunner = new(globalPlayerManager, favGroupManager, games); GameRunner gameRunner = new(globalPlayerManager, globalDieManager, games);
game1.AddPlayerToGame(player1); game1.AddPlayerToGame(player1);
game1.AddPlayerToGame(player2); game1.AddPlayerToGame(player2);

@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using Model.Dice.Faces;
namespace Model.Dice
{
public class Die
{
private static readonly Random random = new Random();
private List<AbstractDieFace> faces;
public AbstractDieFace Throw()
{
// next(x, y) --> [x, y[
return faces[random.Next(0, faces.Count)];
// replace with better algo later
}
}
}

@ -1,9 +1,35 @@
using System.Collections.Generic; using Model.Dice.Faces;
using System.Collections.Generic;
namespace Model.Dice namespace Model.Dice
{ {
public class DieManager public class DieManager : IManager<(string, IEnumerable<AbstractDie<AbstractDieFace>>)>
{ {
private readonly IEnumerable<Die> dice = new List<Die>(); private readonly List<(string name, IEnumerable<AbstractDie<AbstractDieFace>> dice)> diceGroups = new();
public (string, IEnumerable<AbstractDie<AbstractDieFace>>) Add((string, IEnumerable<AbstractDie<AbstractDieFace>>) toAdd)
{
throw new System.NotImplementedException();
}
public IEnumerable<(string, IEnumerable<AbstractDie<AbstractDieFace>>)> GetAll()
{
throw new System.NotImplementedException();
}
public (string, IEnumerable<AbstractDie<AbstractDieFace>>) GetOneById(int id)
{
throw new System.NotImplementedException();
}
public void Remove((string, IEnumerable<AbstractDie<AbstractDieFace>>) toRemove)
{
throw new System.NotImplementedException();
}
public (string, IEnumerable<AbstractDie<AbstractDieFace>>) Update((string, IEnumerable<AbstractDie<AbstractDieFace>>) before, (string, IEnumerable<AbstractDie<AbstractDieFace>>) after)
{
throw new System.NotImplementedException();
}
} }
} }

@ -17,5 +17,10 @@ namespace Model.Dice.Faces
protected abstract int Value { get; } protected abstract int Value { get; }
public abstract object GetPracticalValue(); public abstract object GetPracticalValue();
public override string ToString()
{
return GetPracticalValue().ToString();
}
} }
} }

@ -40,10 +40,5 @@ namespace Model.Dice.Faces
// maybe prepend it with a "#"... // maybe prepend it with a "#"...
return Value.ToString("X6").Insert(0, "#"); return Value.ToString("X6").Insert(0, "#");
} }
public override string ToString()
{
return GetPracticalValue().ToString();
}
} }
} }

@ -31,10 +31,5 @@ namespace Model.Dice.Faces
{ {
return string.Format("Assets/images/{0}", Value); return string.Format("Assets/images/{0}", Value);
} }
public override string ToString()
{
return GetPracticalValue().ToString();
}
} }
} }

@ -18,10 +18,5 @@ namespace Model.Dice.Faces
{ {
return Value; return Value;
} }
public override string ToString()
{
return GetPracticalValue().ToString();
}
} }
} }

@ -1,13 +0,0 @@
using Model.Players;
using System.Collections.Generic;
namespace Model.Dice
{
public class FavGroup
{
public IEnumerable<Die> Dice { get; private set; }
public string Name { get; private set; }
}
}

@ -1,21 +0,0 @@
using Model.Players;
using System.Collections.Generic;
using System.Linq;
namespace Model.Dice
{
public class FavGroupManager
{
private readonly List<FavGroup> favGroups = new();
private readonly DieManager dieManager;
public FavGroupManager(DieManager dieManager)
{
this.dieManager = dieManager;
}
public IEnumerable<FavGroup> GetAll() => favGroups.AsEnumerable();
}
}

@ -56,7 +56,7 @@ namespace Model.Games
/// <summary> /// <summary>
/// the group of dice used for this game /// the group of dice used for this game
/// </summary> /// </summary>
private readonly FavGroup favGroup; private readonly IEnumerable<AbstractDie<AbstractDieFace>> dice;
/// <summary> /// <summary>
/// constructs a Game with its own history of Turns. /// constructs a Game with its own history of Turns.
@ -66,12 +66,12 @@ namespace Model.Games
/// <param name="turns">the turns that have been done so far</param> /// <param name="turns">the turns that have been done so far</param>
/// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param> /// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param>
/// <param name="favGroup">the group of dice used for this game</param> /// <param name="favGroup">the group of dice used for this game</param>
public Game(string name, PlayerManager playerManager, FavGroup favGroup, IEnumerable<Turn> turns) public Game(string name, PlayerManager playerManager, IEnumerable<AbstractDie<AbstractDieFace>> dice, IEnumerable<Turn> turns)
{ {
Name = name; Name = name;
this.turns = turns.ToList() ?? new List<Turn>(); this.turns = turns.ToList() ?? new List<Turn>();
this.playerManager = playerManager; this.playerManager = playerManager;
this.favGroup = favGroup; this.dice = dice;
} }
/// <summary> /// <summary>
@ -80,8 +80,8 @@ namespace Model.Games
/// <param name="name">the name of the game 😎</param> /// <param name="name">the name of the game 😎</param>
/// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param> /// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param>
/// <param name="favGroup">the group of dice used for this game</param> /// <param name="favGroup">the group of dice used for this game</param>
public Game(string name, PlayerManager playerManager, FavGroup favGroup) public Game(string name, PlayerManager playerManager, IEnumerable<AbstractDie<AbstractDieFace>> dice)
: this(name, playerManager, favGroup, null) : this(name, playerManager, dice, null)
{ } { }
/// <summary> /// <summary>
@ -114,9 +114,9 @@ namespace Model.Games
private List<AbstractDieFace> ThrowAll() private List<AbstractDieFace> ThrowAll()
{ {
List<AbstractDieFace> faces = new(); List<AbstractDieFace> faces = new();
foreach (Die die in favGroup.Dice) foreach (AbstractDie<AbstractDieFace> die in dice)
{ {
faces.Add(die.Throw()); faces.Add(die.GetRandomFace());
} }
return faces; return faces;
} }

@ -11,13 +11,13 @@ namespace Model.Games
public class GameRunner public class GameRunner
{ {
private readonly PlayerManager globalPlayerManager; private readonly PlayerManager globalPlayerManager;
private readonly FavGroupManager favGroupManager; private readonly DieManager globalDieManager;
private readonly List<Game> games; private readonly List<Game> games;
public GameRunner(PlayerManager globalPlayerManager, FavGroupManager favGroupManager, List<Game> games) public GameRunner(PlayerManager globalPlayerManager, DieManager globalDieManager, List<Game> games)
{ {
this.globalPlayerManager = globalPlayerManager; this.globalPlayerManager = globalPlayerManager;
this.favGroupManager = favGroupManager; this.globalDieManager = globalDieManager;
this.games = games ?? new(); this.games = games ?? new();
} }

Loading…
Cancel
Save