public static string ExportChooseHeroStatistics(DemolitionFalconsDbContext context) { var map = new DemoMap("map1"); var characters = context.GameCharacters .Select(c => new { map = map.Name, name = c.Game.Name, numberOfPlayers = c.Game.Characters.Count(), players = c.Game.Characters.Select(st => new CharacterDto { Type = st.Type, Nickname = context.Players.FirstOrDefault(p => p.Id == st.PlayerId).Username, Name = st.Character.Name }) }) .FirstOrDefault(); var json = JsonConvert.SerializeObject(characters, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore } ); return(json); }
public AttackACharacter(DemolitionFalconsDbContext context, MapSection[][] map, int roomId, int characterId) { this.context = context; this.map = map; this.roomId = roomId; this.characterId = characterId; }
public SinglePlayer(DemolitionFalconsDbContext context, IInputReader reader, IOutputWriter writer, NumberGenerator numberGenerator) { this.context = context; this.reader = reader; this.writer = writer; this.numberGenerator = numberGenerator; }
public static void CreateDataBase(DemolitionFalconsDbContext context) { //context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Seed(context); }
public PlayGame(DemolitionFalconsDbContext context, NumberGenerator numberGenerator) { this.context = context; this.numberGenerator = numberGenerator; this.keyboardInput = new KeyboardInput(); //this.timer = new Timer(1000); }
public static string ExportCharacterStatistics(DemolitionFalconsDbContext context) { var map = new DemoMap("map1"); var characters = context.Characters .Select(c => new { Id = c.Id, name = c.Name, c.Label, c.Description, c.Hp, c.Armour }) .ToArray(); var json = JsonConvert.SerializeObject(characters, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore } ); return(json); }
public GameManager(DemolitionFalconsDbContext context, IOutputWriter writer, IInputReader reader) { this.context = context; this.Players = this.context.Players.ToList(); this.writer = writer; this.reader = reader; this.numberGenerator = new NumberGenerator(); }
public Engine(DemolitionFalconsDbContext context) { this.context = context; this.commandEngine = new CommandEngine <ICommand>(); this.reader = new InputReader(); this.writer = new OutputWriter(); this.gameManager = new GameManager(context, writer, reader);; }
public static DemolitionFalconsDbContext ResetDB(DemolitionFalconsDbContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); //context.Database.Migrate(); context = new DemolitionFalconsDbContext(); Seed(context); return(context); }
public static void Main() { DemolitionFalconsDbContext context = new DemolitionFalconsDbContext(); SetUpDatabase.CreateDataBase(context); Engine engine = new Engine(context); JsonExport jsonExporter = new JsonExport(); jsonExporter.Export(context); engine.Run(); }
public void Export(DemolitionFalconsDbContext context) { //const string exportDir = "./ImportResults/"; var jsonMapAndGameStatsOutput = Serializer.ExportGameAndMapStatistics(context); Console.WriteLine(jsonMapAndGameStatsOutput); var jsonCharStatsOutput = Serializer.ExportCharacterStatistics(context); Console.WriteLine(jsonCharStatsOutput); //File.WriteAllText(exportDir + "DelayedTrains.json", jsonOutput); var jsonChooseHeroOutput = Serializer.ExportChooseHeroStatistics(context); Console.WriteLine(jsonChooseHeroOutput); }
public Weapon GetMostPowerfulWeapon(DemolitionFalconsDbContext context, int playerId) { var weapons = context.Weapons.OrderByDescending(w => w.Damage); var playerWeapons = context.PlayerWeapons.Where(pw => pw.PlayerId == playerId).ToList(); var currentPlayerWeapons = new List <Weapon>(); foreach (var weapon in weapons) { if (playerWeapons.Any(pw => pw.WeaponId == weapon.Id)) { currentPlayerWeapons.Add(weapon); } } var mostPowerfulWeapon = currentPlayerWeapons.OrderByDescending(cpw => cpw.Damage).FirstOrDefault(); return(mostPowerfulWeapon); }
public string ResetDatabase() { StringBuilder sb = new StringBuilder(); try { SetUpDatabase.ResetDB(context); this.context = SetUpDatabase.ResetDB(context); sb.AppendLine("Reset Database - successful"); } catch (Exception ex) { return(ex.Message); } return(sb.ToString().TrimEnd()); }
public static string ExportGameAndMapStatistics(DemolitionFalconsDbContext context) { var map = new DemoMap("map1"); var characters = context.GameCharacters .Select(c => new { name = c.Game.Name, map = map.Name, numberOfOpponents = c.Game.Characters.Count() }) .FirstOrDefault(); var json = JsonConvert.SerializeObject(characters, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore } ); return(json); }
private static void Seed(DemolitionFalconsDbContext context) { //Add just 2 basic weapons with same stats in order to test //If you want you're free to add more if (!context.Weapons.Any()) { var weapons = new List <Weapon>(); var hollyWoodWand = new Weapon { Name = "Holly Wood Wand ", Core = "Phoenix feather", Damage = 25 }; weapons.Add(hollyWoodWand); var vineWand = new Weapon { Name = "Vine Wand", Core = "Dragon scale", Damage = 25 }; weapons.Add(vineWand); var metalWand = new Weapon { Name = "Metal Wand", Core = "Mystic tear", Damage = 10 }; weapons.Add(metalWand); context.Weapons.AddRange(weapons); context.SaveChanges(); } //Add a bot player in order to test if all is correct //Add weapons to him //Add a playerWeapon connection if (!context.Players.Any() || context.Players.Count() < 5) { var players = new List <Player>(); var bot = new Player { Username = "******", Password = "******", GamesPlayed = 0, Wins = 0 }; players.Add(bot); var kellyane = new Player { Username = "******", Password = "******", GamesPlayed = 0, Wins = 0 }; players.Add(kellyane); var ricardo = new Player { Username = "******", Password = "******", GamesPlayed = 0, Wins = 0 }; players.Add(ricardo); var claire = new Player { Username = "******", Password = "******", GamesPlayed = 0, Wins = 0 }; players.Add(claire); var rango = new Player { Username = "******", Password = "******", GamesPlayed = 0, Wins = 0 }; players.Add(rango); var yoner = new Player { Username = "******", Password = "******", GamesPlayed = 0, Wins = 0 }; players.Add(yoner); context.Players.AddRange(players); context.SaveChanges(); var weapons = new List <Weapon> { context.Weapons.Where(w => w.Name == "Holly Wood Wand").FirstOrDefault(), context.Weapons.Where(w => w.Name == "Vine Wand").FirstOrDefault() }; foreach (var weapon in weapons) { var playerWeapon = new PlayerWeapon { Player = bot, PlayerId = bot.Id, Weapon = weapon, WeaponId = weapon.Id }; context.PlayerWeapons.Add(playerWeapon); context.SaveChanges(); } var vineWand = weapons.FirstOrDefault(w => w.Id == 2); var playersWeapons = new List <PlayerWeapon>(); var playerWeaponSecond = new PlayerWeapon { Player = yoner, PlayerId = yoner.Id, Weapon = vineWand, WeaponId = vineWand.Id }; playersWeapons.Add(playerWeaponSecond); var playerWeaponThird = new PlayerWeapon { Player = rango, PlayerId = rango.Id, Weapon = vineWand, WeaponId = vineWand.Id }; playersWeapons.Add(playerWeaponThird); var playerWeaponFourth = new PlayerWeapon { Player = claire, PlayerId = claire.Id, Weapon = vineWand, WeaponId = vineWand.Id }; playersWeapons.Add(playerWeaponFourth); var playerWeaponFifth = new PlayerWeapon { Player = ricardo, PlayerId = ricardo.Id, Weapon = vineWand, WeaponId = vineWand.Id }; playersWeapons.Add(playerWeaponFifth); var playerWeaponSixth = new PlayerWeapon { Player = kellyane, PlayerId = kellyane.Id, Weapon = vineWand, WeaponId = vineWand.Id }; playersWeapons.Add(playerWeaponSixth); context.PlayerWeapons.AddRange(playersWeapons); context.SaveChanges(); } if (!context.Games.Any()) { var currentGame = new Game() { Name = "FirstGameEver", Xp = 50, Money = 250, Capacity = 6, Map = "FirstMapFrontEnd" }; context.Games.Add(currentGame); context.SaveChanges(); } var currentCharacters = new List <Character>(); if (!context.Characters.Any()) { var eagle = new Character { Name = "Eagle", Label = "The Flying Demon", Description = "It comes from a distant unknown land. It has a weak defence but is very fast and subtle.", Hp = 100, Armour = 20, }; var cloudy = new Character { Name = "Cloudy", Label = "The Cloud Potato", Description = "It comes from a Cloudysland, drives a skateboard and has a strange hairstyle.", Hp = 70, Armour = 65, }; var edward = new Character { Name = "Edward", Label = "The Raccoon's Special Troop", Description = "Has developed great military skills over time. Has very strong defence but is usually unfortunate.", Hp = 70, Armour = 100, }; var stephano = new Character { Name = "Stephano", Label = "The Mad Scientist", Description = "Has worked for different non-governmental projects with an unknown role. Notably known for his bloody scientific experiments on people.", Hp = 50, Armour = 90, }; var leonardo = new Character { Name = "Leonardo", Label = "The King Of The Jungle", Description = "Has ruled over many kingdoms in all over the world and has now come to prove his strength and sageness.", Hp = 90, Armour = 90, }; var darcus = new Character { Name = "Darcus", Label = "The Ancient Firebreather", Description = "Uses his instincts and abilities to burn his enemies.", Hp = 100, Armour = 90, }; currentCharacters.Add(eagle); currentCharacters.Add(cloudy); currentCharacters.Add(edward); currentCharacters.Add(stephano); currentCharacters.Add(leonardo); currentCharacters.Add(darcus); context.AddRange(currentCharacters); context.SaveChanges(); } var game = context.Games.FirstOrDefault(x => x.Name == "FirstGameEver"); if (game.Characters.Count == 0) { var currentChars = context.Characters.ToList(); var currentGameChars = context.GameCharacters.ToList(); var gameChars = new List <GameCharacter>(); if (context.GameCharacters.ToList().Count != 0) { for (int i = 0; i < 6; i++) { currentGameChars[i].Game = game; currentGameChars[i].GameId = game.Id; } context.SaveChanges(); } else { var weaponTaker = new TakeMostPowerfulWeapon(); var gameCharacterOne = new GameCharacter { Character = currentChars[0], CharacterId = currentChars[0].Id, Game = game, GameId = game.Id, PlayerId = 1, Type = "computer", Health = currentChars[0].Hp, Armour = currentChars[0].Armour, WeaponId = weaponTaker.GetMostPowerfulWeapon(context, 1).Id }; gameChars.Add(gameCharacterOne); var gameCharacterTwo = new GameCharacter { Character = currentChars[1], CharacterId = currentChars[1].Id, Game = game, GameId = game.Id, PlayerId = 2, Type = "computer", Health = currentChars[1].Hp, Armour = currentChars[1].Armour, WeaponId = weaponTaker.GetMostPowerfulWeapon(context, 2).Id }; gameChars.Add(gameCharacterTwo); var gameCharacterThree = new GameCharacter { Character = currentChars[2], CharacterId = currentChars[2].Id, Game = game, GameId = game.Id, PlayerId = 3, Type = "computer", Health = currentChars[2].Hp, Armour = currentChars[2].Armour, WeaponId = weaponTaker.GetMostPowerfulWeapon(context, 3).Id }; gameChars.Add(gameCharacterThree); var gameCharacterFour = new GameCharacter { Character = currentChars[3], CharacterId = currentChars[3].Id, Game = game, GameId = game.Id, PlayerId = 4, Type = "computer", Health = currentChars[3].Hp, Armour = currentChars[3].Armour, WeaponId = weaponTaker.GetMostPowerfulWeapon(context, 4).Id }; gameChars.Add(gameCharacterFour); var gameCharacterFive = new GameCharacter { Character = currentChars[4], CharacterId = currentChars[4].Id, Game = game, GameId = game.Id, PlayerId = 5, Type = "computer", Health = currentChars[4].Hp, Armour = currentChars[4].Armour, WeaponId = weaponTaker.GetMostPowerfulWeapon(context, 5).Id }; gameChars.Add(gameCharacterFive); var gameCharacterSix = new GameCharacter { Character = currentChars[5], CharacterId = currentChars[5].Id, Game = game, GameId = game.Id, PlayerId = 6, Type = "computer", Health = currentChars[5].Hp, Armour = currentChars[5].Armour, WeaponId = weaponTaker.GetMostPowerfulWeapon(context, 6).Id }; gameChars.Add(gameCharacterSix); context.GameCharacters.AddRange(gameChars); context.SaveChanges(); } } if (!context.Spells.Any()) { var spells = new List <Spell>(); var fireball = new Spell("Fireball", 50, 15); fireball.Description = "A ball of fire flying towards any enemy and dealing huge damage"; var crucio = new Spell("Crucio", 150, 12); crucio.Description = "A spells seen in the Harry Potter series for first time. One of the three Unforgivable Curses" + " the Cruciatus curse causes agonising pain"; var avadaKedavra = new Spell("Avada Kedavra", 300, 6); avadaKedavra.Description = "Powerful curse which instantly kills the victim"; var expectoPatronum = new Spell("Expecto Patronum", 100, 10); expectoPatronum.Description = "A mytic spell that is useful against demolitional monsters"; spells.Add(fireball); spells.Add(crucio); spells.Add(avadaKedavra); spells.Add(expectoPatronum); context.Spells.AddRange(spells); context.SaveChanges(); } }
public BaseApiController() { dbContext = new DemolitionFalconsDbContext(); }
public BonusSquareAction(DemolitionFalconsDbContext context, int roomId, Character character) { this.context = context; this.roomId = roomId; this.character = character; }
public void StartDoubleChance(DemolitionFalconsDbContext context, int roomId, Character character, int positionNumber, MapSection[][] map, int i, int j, bool isSingle) { var demoMatrixRows = 3; var demoMatrixCols = 3; var firstNumTyped = 0; char[][] demoMatrix = new char[3][]; var isSecondChance = false; int num; var playGame = new PlayGame(context, numberGenerator); var counter = 1; for (int row = 0; row < demoMatrixRows; row++) { demoMatrix[row] = new char[demoMatrixCols]; for (int col = 0; col < demoMatrixCols; col++) { demoMatrix[row][col] = counter.ToString()[0]; counter++; } } //play double chance Console.WriteLine("Welcome to the Double Chance game! You have 9 hidden sayings. Choose one!"); var doubleChanceGame = new DoubleChance(); var matrix = doubleChanceGame.LoadDoubleChance(); Start: int numTyped; if (isSingle) { numTyped = numberGenerator.GenerateNumber(1, 10); while (numTyped == firstNumTyped) { numTyped = numberGenerator.GenerateNumber(1, 10); } goto SinglePlayer; } var isNumeric = int.TryParse(Console.ReadLine(), out numTyped); while (numTyped < 1 || numTyped > 9 || numTyped == firstNumTyped || !isNumeric) { if (firstNumTyped != 0) { Console.WriteLine($"Type a number from 1 to 9 which is different from {firstNumTyped}."); } Console.WriteLine("Type a number from 1 to 9"); isNumeric = int.TryParse(Console.ReadLine(), out numTyped); } SinglePlayer: char letter; if (numTyped >= 1 && numTyped <= 3) { letter = matrix[0][numTyped - 1]; demoMatrix[0][numTyped - 1] = letter; } else if (numTyped <= 6) { letter = matrix[1][numTyped - 4]; demoMatrix[1][numTyped - 4] = letter; } else { letter = matrix[2][numTyped - 7]; demoMatrix[2][numTyped - 7] = letter; } foreach (var row in demoMatrix) { Console.WriteLine(string.Join("{0}", $"[{string.Join(" | ", row)}]")); } if (letter == 'S') { if (!isSecondChance) { firstNumTyped = numTyped; BonusSquareAction bsa = new BonusSquareAction(context, roomId, character); //Gets a random spell drawn with a special algorythm that allow the character to atack another character var spell = bsa.RandomSpell(); Console.WriteLine($"Congrats you have received a new spell -> {spell.Name}. If you want to keep it type 'Y' and if you want a second chance type 'N'"); string response; if (isSingle) { response = TakeOrNot(); } else { response = Console.ReadLine(); while (response != "Y" && response != "N") { Console.WriteLine("Type 'Y' or 'N'"); response = Console.ReadLine(); } } if (response == "N") { isSecondChance = true; foreach (var row in demoMatrix) { Console.WriteLine(string.Join("{0}", $"[{string.Join(" | ", row)}]")); } goto Start; } else { bsa.GetSpell(spell.Name); } } else { Console.WriteLine("This was your second shot! Congrats you win a spell!"); BonusSquareAction bsa = new BonusSquareAction(context, roomId, character); bsa.GetSpell(""); } } else if (letter == 'F') { if (!isSecondChance) { num = numberGenerator.GenerateNumber(2, 6); var toMoveForwardWith = num; Console.WriteLine($"Congrats you can move {toMoveForwardWith} spaces forward if you wish. If so type 'Y' and if you want a second chance type 'N'"); string response; if (isSingle) { response = TakeOrNot(); } else { response = Console.ReadLine(); while (response != "Y" && response != "N") { Console.WriteLine("Type 'Y' or 'N'"); response = Console.ReadLine(); } } if (response == "N") { isSecondChance = true; foreach (var row in demoMatrix) { Console.WriteLine(string.Join("{0}", $"[{string.Join(" | ", row)}]")); } goto Start; } else { playGame.MoveForwardWith(toMoveForwardWith, positionNumber, map, i, j, roomId, character); } } else// is secondChance { num = numberGenerator.GenerateNumber(2, 6); var toMoveForwardWith = num; Console.WriteLine($"Congrats, this was your second shot. You can now move forward with {toMoveForwardWith} places if possible"); playGame.MoveForwardWith(toMoveForwardWith, positionNumber, map, i, j, roomId, character); } } else if (letter == 'B') { var toGoBackWith = numberGenerator.GenerateNumber(3, 8); if (!isSecondChance) { Console.WriteLine($"Sadly you have to move {toGoBackWith} places backwards if possible. You still have a second chance. If you want to go back type 'Y' or type 'N' for a second shot."); string response; if (isSingle) { response = TakeOrNot(); } else { response = Console.ReadLine(); while (response != "Y" && response != "N") { Console.WriteLine("Type 'Y' if you want to go back and 'N' for a second try."); response = Console.ReadLine(); } } if (response == "Y") { playGame.GoBackWith(toGoBackWith, positionNumber, map, i, j, roomId, character); } else { isSecondChance = true; foreach (var row in demoMatrix) { Console.WriteLine(string.Join("{0}", $"[{string.Join(" | ", row)}]")); } goto Start; } } else { num = numberGenerator.GenerateNumber(2, 6); var toMoveBackWith = num; Console.WriteLine($"Sorry this was your second shot. You will move with {toMoveBackWith} places backwards if possible."); playGame.GoBackWith(toMoveBackWith, positionNumber, map, i, j, roomId, character); } } }