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();
            }
        }
示例#2
0
        public string JoinRoom(IList <string> arguments)
        {
            //gameName
            //string roomName = arguments[0];
            StringBuilder sb = new StringBuilder();

            try
            {
                var rooms = context.Games.ToList();

                Console.WriteLine($"Here is a list of all available rooms:");
                for (int i = 0; i < rooms.Count; i++)
                {
                    var num  = i + 1;
                    var room = rooms[i];
                    Console.WriteLine($"{num}. {room.Name} {room.Characters.Count}");
                }
                Console.WriteLine($"Choose which one you would like to join.(integer)");
                var roomNumber = int.Parse(Console.ReadLine());

                while (rooms[roomNumber - 1].Characters.Count == 6)
                {
                    Console.WriteLine($"{rooms[roomNumber - 1].Name} is full, please choose another room.");
                    roomNumber = int.Parse(Console.ReadLine());
                }

                Console.WriteLine($"Successfully Joined Room {rooms[roomNumber - 1].Name}");
                Console.WriteLine($"Please choose a character from the list below:");

                var characters = context.Characters.ToList();

                for (int i = 0; i < characters.Count; i++)
                {
                    var num       = i + 1;
                    var character = characters[i];
                    Console.WriteLine($"{num}. {character.Name} - {character.Hp}HP and {character.Armour}Armour");
                }

                Console.WriteLine($"Choose which one you would like to use.");
                var characterNumber = int.Parse(Console.ReadLine());
                var gameCharacter   = context.GameCharacters.Where(g => g.GameId == rooms[roomNumber - 1].Id).ToList();
                while (gameCharacter.Where(g => g.GameId == rooms[roomNumber - 1].Id).Any(g => g.CharacterId == characters[characterNumber - 1].Id))
                {
                    Console.WriteLine($"{characters[characterNumber - 1]} is already taken, please choose another one.");
                    Console.WriteLine($"Or if you want to exit JoinRoom, type Exit");
                    characterNumber = int.Parse(Console.ReadLine());
                }
                var player      = context.Players.LastOrDefault();
                var weaponTaker = new TakeMostPowerfulWeapon();

                GameCharacter gc = new GameCharacter
                {
                    Character   = characters[characterNumber - 1],
                    CharacterId = characters[characterNumber - 1].Id,
                    Game        = rooms[roomNumber - 1],
                    GameId      = rooms[roomNumber - 1].Id,
                    PlayerId    = player.Id,
                    Health      = characters[characterNumber - 1].Hp,
                    Armour      = characters[characterNumber - 1].Armour,
                    WeaponId    = weaponTaker.GetMostPowerfulWeapon(context, player.Id).Id
                };
                context.GameCharacters.Add(gc);
                context.SaveChanges();
                sb.AppendLine($"Successfully joined room {rooms[roomNumber - 1].Name}. You will use {characters[characterNumber - 1].Name} as your character for this game!");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return(sb.ToString().TrimEnd());
        }