|
|
|
@ -31,6 +31,8 @@ namespace App
|
|
|
|
|
gameRunner = new(new PlayerManager(), new DieManager(), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// DB stuff when the app opens
|
|
|
|
|
using (DiceAppDbContext db = new())
|
|
|
|
|
{
|
|
|
|
@ -39,15 +41,16 @@ namespace App
|
|
|
|
|
// get all the players from the DB
|
|
|
|
|
IEnumerable<PlayerEntity> entities = db.Players;
|
|
|
|
|
|
|
|
|
|
Debug.WriteLine("Loading players");
|
|
|
|
|
|
|
|
|
|
foreach (PlayerEntity entity in entities)
|
|
|
|
|
{
|
|
|
|
|
try // to persist them
|
|
|
|
|
{ // as models !
|
|
|
|
|
// persist them as models !
|
|
|
|
|
gameRunner.GlobalPlayerManager.Add(entity.ToModel());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Debug.WriteLine($"{ex.Message}\n... Did you make sure that the DATABASE exists?"); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Debug.WriteLine($"{ex.Message}\n... Couldn't use the database"); }
|
|
|
|
|
|
|
|
|
|
string menuChoice = "nothing";
|
|
|
|
|
|
|
|
|
@ -146,6 +149,8 @@ namespace App
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// DB stuff when the app closes
|
|
|
|
|
using (DiceAppDbContext db = new())
|
|
|
|
|
{
|
|
|
|
@ -155,6 +160,8 @@ namespace App
|
|
|
|
|
// create a PlayerDbManager (and inject it with the DB)
|
|
|
|
|
PlayerDbManager playerDbManager = new(db);
|
|
|
|
|
|
|
|
|
|
Debug.WriteLine("Saving players");
|
|
|
|
|
|
|
|
|
|
foreach (Player model in models)
|
|
|
|
|
{
|
|
|
|
|
try // to persist them
|
|
|
|
@ -163,9 +170,9 @@ namespace App
|
|
|
|
|
}
|
|
|
|
|
// what if there's already a player with that name? Exception (see PlayerEntity's annotations)
|
|
|
|
|
catch (ArgumentException ex) { Debug.WriteLine($"{ex.Message}\n... Never mind"); }
|
|
|
|
|
catch (Exception ex) { Debug.WriteLine($"{ex.Message}\n... Did you make sure that the DATABASE exists?"); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) { Debug.WriteLine($"{ex.Message}\n... Couldn't use the database"); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Play(GameRunner gameRunner, string name)
|
|
|
|
|