public async Task ExecuteAsync(int number) { var players = playersAccessLayer.GetCollection().ToList(); var menu = new Menu(players.Select(p => new CmdLoadChosenGame(p)).ToArray()); await menu.Activate(); }
// Get a player instance. If none created yet, create one. Else, get the last player data from db, and return it. public static async Task <Player> GetPlayerInstance() { if (_playerInstance == null) { Console.WriteLine("Enter your name!"); Console.WriteLine("\n"); List <Player> players = playersAccessLayer.GetCollection().ToList(); List <string> playersName = new List <string>(); int index = 0; foreach (Player p in players) { playersName.Add(p.Name); index++; } bool alreadyExisting = true; string name = null; while (alreadyExisting) { name = Console.ReadLine(); if (playersName.Contains(name) || name.Length <= 1) { Console.WriteLine("This name already exists or it is too short !"); } else { alreadyExisting = false; } } var player = new Player { Name = name, MaxHp = 100, Hp = 100, Exp = 0 }; await playersAccessLayer.AddAsync(player); var insertedPlayer = playersAccessLayer.GetSingleWithRelations(p => p.Name == player.Name, true); _playerInstance = insertedPlayer; } else { var player = playersAccessLayer.GetSingleWithRelations(p => p.Id == _playerInstance.Id, true); _playerInstance = player; } return(_playerInstance); }