Merge pull request '⚗️ Add content to the stub to explore the logic of the app' (#58) from develop-stub into main
continuous-integration/drone/push Build is passing Details

Reviewed-on: #58
pull/61/head
Alexis Drai 2 years ago
commit c97c8d6ee1

@ -14,18 +14,49 @@ namespace Data
public GameRunner LoadApp()
{
// this doesn't do much for now, because the classes aren't coded
List<Game> games = new();
string g1 = "game1", g2 = "game2", g3 = "game3";
PlayerManager gpm = new();
gpm.Add(new Player("Alice"));
gpm.Add(new Player("Bob"));
gpm.Add(new Player("Clyde"));
Player player1 = new("Alice"), player2 = new("Bob"), player3 = new("Clyde");
FavGroupManager fgm = new(new DieManager());
// create some fav groups of die in there, thanks to fgm's methods
FavGroupManager favGroupManager = new(new DieManager());
return new GameRunner(gpm, fgm, games);
// create at least one fav group in there
// ...
Game game1 = new(name: g1, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().First());
Game game2 = new(name: g2, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().Last());
Game game3 = new(name: g3, playerManager: new PlayerManager(), favGroup: favGroupManager.GetAll().First());
List<Game> games = new() { game1, game2, game3 };
PlayerManager globalPlayerManager = new();
globalPlayerManager.Add(player1);
globalPlayerManager.Add(player2);
globalPlayerManager.Add(player3);
GameRunner gameRunner = new(globalPlayerManager, favGroupManager, games);
game1.AddPlayerToGame(player1);
game1.AddPlayerToGame(player2);
game2.AddPlayerToGame(player1);
game2.AddPlayerToGame(player2);
game2.AddPlayerToGame(player3);
game3.AddPlayerToGame(player1);
game3.AddPlayerToGame(player3);
foreach (Game game in games)
{
for (int i = 0; i < 10; i++)
{
Player currentPlayer = game.GetWhoPlaysNow();
game.PerformTurn(currentPlayer);
game.PrepareNextPlayer(currentPlayer);
}
}
return gameRunner;
}
public static List<Player> LoadPlayers()

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

@ -12,13 +12,32 @@ namespace Model.Games
{
private readonly PlayerManager globalPlayerManager;
private readonly FavGroupManager favGroupManager;
private readonly IEnumerable<Game> games;
private readonly List<Game> games;
public GameRunner(PlayerManager globalPlayerManager, FavGroupManager favGroupManager, IEnumerable<Game> games)
public GameRunner(PlayerManager globalPlayerManager, FavGroupManager favGroupManager, List<Game> games)
{
this.globalPlayerManager = globalPlayerManager;
this.favGroupManager = favGroupManager;
this.games = games;
this.games = games ?? new();
}
public IEnumerable<Game> GetAll() => games.AsEnumerable();
/// <summary>
/// finds the game with that name and returns it
/// <br/>
/// that copy does not belong to this gamerunner's games, so it should not be modified
/// </summary>
/// <param name="name">a games's name</param>
/// <returns>game with said name, <em>or null</em> if no such game was found</returns>
public Game GetOneGameByName(string name)
{
if (!string.IsNullOrWhiteSpace(name))
{
Game result = games.FirstOrDefault(g => g.Name == name);
return result; // may return null
}
throw new ArgumentException("param should not be null or blank", nameof(name));
}
}
}

Loading…
Cancel
Save