Exemple #1
0
        public void SetPlayer(int id)
        {
            Dead     = false;
            GameText = new GameText();
            PlayerRepo repo = new PlayerRepo(new PlayerQuery());

            CurrentPlayer              = repo.GetPlayer(id);
            CurrentPlayer.UsedMagic    = repo.EquipedMagic(CurrentPlayer.Id);
            CurrentPlayer.CurrentMagic = repo.PlayerMagic(CurrentPlayer.Id);
            GameText.AddText(CurrentPlayer.Name);
            CurrentEnemy = null;
        }
Exemple #2
0
        public void Attack()
        {
            if (CurrentRoom != null)
            {
                if (CurrentEnemy != null)
                {
                    Random random      = new Random();
                    int    enemyattack =
                        Convert.ToInt32(Math.Round(Convert.ToDouble(CurrentEnemy.Attack - (CurrentPlayer.Defence / 2)),
                                                   0));
                    if (enemyattack < 0)
                    {
                        enemyattack = 0;
                    }

                    CurrentPlayer.Health -= enemyattack;
                    int rand         = random.Next(1, 101);
                    int playerattack = CurrentPlayer.Attack;
                    if (CurrentPlayer.CritChance > rand)
                    {
                        playerattack = (playerattack * 2);
                        GameText.AddText("Critical hit!");
                        GameText.AddText(CurrentPlayer.Name + " Attacked " + CurrentEnemy.Name + " for " + playerattack +
                                         " damage");
                    }
                    else
                    {
                        GameText.AddText(CurrentPlayer.Name + " Attacked " + CurrentEnemy.Name + " for " + playerattack +
                                         " damage");
                    }
                    rand = random.Next(1, 101);
                    if (CurrentPlayer.DodgeChance > rand)
                    {
                        GameText.AddText(CurrentEnemy.Name + " Attacked " + CurrentPlayer.Name + " but missed");
                    }
                    else
                    {
                        CurrentEnemy.Health -= CurrentPlayer.Attack;
                        GameText.AddText(CurrentEnemy.Name + " Attacked " + CurrentPlayer.Name + " for " + enemyattack +
                                         " damage");
                    }
                }
                else
                {
                    GameText.AddText("There is nothing to attack here");
                }
            }
            else
            {
                GameText.AddText("There is nothing to attack here");
            }
            Endturn();
        }
Exemple #3
0
        public void UseMagic()
        {
            if (CurrentPlayer.UsedMagic != 0)
            {
                foreach (Magic magic in CurrentPlayer.CurrentMagic)
                {
                    if (magic.Id == CurrentPlayer.UsedMagic)
                    {
                        if (CurrentPlayer.Mana > magic.Manacost)
                        {
                            if (magic.Damage == 0)
                            {
                                CurrentPlayer.Health += magic.HealthRestore;
                                CurrentPlayer.Mana   -= magic.Manacost;
                                GameText.AddText(CurrentPlayer.Name + " healed for " + magic.HealthRestore + "health");
                            }
                            else if (CurrentEnemy != null)
                            {
                                CurrentPlayer.Health += magic.HealthRestore - CurrentEnemy.Attack;
                                CurrentPlayer.Mana   -= magic.Manacost;
                                CurrentEnemy.Health  -= magic.Damage;
                                if (magic.Damage > 0)
                                {
                                    GameText.AddText(CurrentPlayer.Name + " did " + magic.Damage + " to " +
                                                     CurrentEnemy.Name + "with " + magic.Name);
                                }
                                if (magic.HealthRestore > 0)
                                {
                                    GameText.AddText(CurrentPlayer.Name + " healed for " + magic.HealthRestore +
                                                     " health");
                                }

                                GameText.AddText(CurrentEnemy.Name + " Attacked " + CurrentPlayer.Name + " for " +
                                                 CurrentEnemy.Attack + " damage");
                            }
                            else
                            {
                                GameText.AddText("There is nothing to use " + magic.Name + " on");
                            }
                        }
                        else
                        {
                            GameText.AddText("Not enough mana to use this spell");
                        }
                    }
                }
            }
            else
            {
                GameText.AddText("No magic equipped yet");
            }
            Endturn();
        }
Exemple #4
0
        public void Endturn()
        {
            if (CurrentPlayer.Health <= 0)
            {
                GameText.AddText("You Died");
                Dead = true;
            }
            else
            {
                PlayerRepo repo   = new PlayerRepo(new PlayerQuery());
                GameRepo   g_repo = new GameRepo(new GameQuery());
                CurrentPlayer.Mana   += CurrentPlayer.ManaRegen;
                CurrentPlayer.Health += CurrentPlayer.HealthRegen;
                repo.UpdatePlayer(CurrentPlayer);
                CurrentPlayer              = repo.GetPlayer(CurrentPlayer.Id);
                CurrentPlayer.UsedMagic    = repo.EquipedMagic(CurrentPlayer.Id);
                CurrentPlayer.CurrentMagic = repo.PlayerMagic(CurrentPlayer.Id);
                if (CurrentEnemy != null)
                {
                    if (CurrentEnemy.Health <= 0)
                    {
                        GameText.AddText(CurrentPlayer.Name + " Defeated " + CurrentEnemy.Name + " And gained " +
                                         CurrentEnemy.ExperienceDrop + " experience");

                        List <int> items = new List <int>();
                        Item       item  = g_repo.GetItem(CurrentPlayer.Level);

                        GameText.AddText(CurrentEnemy.Name + " Dropped a " + item.Name);

                        items.Add(item.Id);
                        items.Add(200);
                        g_repo.SetItem(items, CurrentPlayer.Id);

                        int enemyspawn = g_repo.EnemyDefeated(CurrentEnemy.Id, CurrentPlayer.Id);
                        if (enemyspawn != 0 && new Random().Next(1, 100) > 80)
                        {
                            CurrentEnemy = g_repo.EnemybyId(enemyspawn);
                            GameText.AddText("A " + CurrentEnemy.Name + "Jumps at you!");
                        }
                        else
                        {
                            CurrentEnemy = null;
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void Nextroom()
        {
            Trader = false;
            GameRepo repo = new GameRepo(new GameQuery());

            if (CurrentEnemy == null)
            {
                CurrentRoom = null;
                int roomlevel = new Random().Next(1, CurrentPlayer.Level);
                CurrentRoom = repo.Nextroom(roomlevel);

                if (CurrentRoom.Id == 0)
                {
                    while (CurrentRoom.Id == 0)
                    {
                        roomlevel--;
                        CurrentRoom = repo.Nextroom(roomlevel);
                    }
                }
                GameText.AddText(CurrentPlayer.Name + " entered a " + CurrentRoom.Name);
                if (CurrentRoom.Random <= CurrentRoom.EnemyChance && CurrentRoom.Random >= CurrentRoom.TraderChance &&
                    CurrentRoom.Random >= CurrentRoom.EventChance)
                {
                    CurrentEnemy = repo.Enemy(roomlevel);
                    GameText.AddText("a " + CurrentEnemy.Name + " appeared in the " + CurrentRoom.Name);
                }
                if (CurrentRoom.Random >= CurrentRoom.EnemyChance && CurrentRoom.Random <= CurrentRoom.TraderChance &&
                    CurrentRoom.Random >= CurrentRoom.EventChance)
                {
                    GameText.AddText("You meet a trader while traveling");
                    Trader = true;
                }
            }
            else
            {
                GameText.AddText("You cannot leave while a enemy is still alive");
            }
        }