Пример #1
0
 private void CastSpellOnOpponentsCreature(IPlayer player, IPlayer opponent, ISpell spell)
 {
     if (opponent.BattleField.Count > 0)
     {
         Console.WriteLine(constants.EnterCreatureName);
         Console.WriteLine(string.Join("\n", opponent.BattleField));
         IDamageable target = opponent.SelectACreature(Console.ReadLine());
         spell.CastSpell(target);
         if (target.HealthPoints < 1)
         {
             opponent.BattleField.Remove((ICreature)target);
         }
     }
     else
     {
         Console.WriteLine(constants.EnemyDoesntHaveACreature);
         PlayTurn(player, opponent);
     }
 }
Пример #2
0
        public void TakeTurn(ICreature creature, World world)
        {
            _countdownToNextTurn -= 1;
            if (_countdownToNextTurn <= 0)
            {
                _countdownToNextTurn = _speed;
                bool turnOver = false;

                if (world.CanPlayerSeeWorldIndex(creature.WorldIndex) && RandomNumberProvider.CheckIfChanceOccurs(25) && world.GetStraightLineDistance(creature.WorldIndex, world.Player.WorldIndex) <= 5)
                {
                    _spell.CastSpell(creature, world.Player.WorldIndex);
                }
                else
                {
                    while (turnOver != true)
                    {
                        int roll = RandomNumberProvider.GetRandomNumber(1, 4);
                        if (roll == 1)
                        {
                            turnOver = world.MoveCreatureInDirectionSuccessful(Direction.North, creature);
                        }
                        else if (roll == 2)
                        {
                            turnOver = world.MoveCreatureInDirectionSuccessful(Direction.South, creature);
                        }
                        else if (roll == 3)
                        {
                            turnOver = world.MoveCreatureInDirectionSuccessful(Direction.East, creature);
                        }
                        else if (roll == 4)
                        {
                            turnOver = world.MoveCreatureInDirectionSuccessful(Direction.West, creature);
                        }
                    }
                }
            }
        }
Пример #3
0
        private void TouchOrMouse(Vector2 pos)
        {
            if (_messageBox.IntersectsWith(new Vector2(pos.X, pos.Y)))
            {
                Announcer.Instance.Announce("Clicked message box.", MessageTypes.Other);
            }
            else if (_sideBar.IntersectsWith(new Vector2(pos.X, pos.Y)))
            {
                Announcer.Instance.Announce("Clicked side bar.", MessageTypes.Other);
            }
            else if (_inventory.IntersectsWith(new Vector2(pos.X, pos.Y)))
            {
                Announcer.Instance.Announce("Clicked inventory.", MessageTypes.Other);
            }
            else if (_spells.IntersectsWith(new Vector2(pos.X, pos.Y)))
            {
                //Announcer.Instance.Announce("Clicked spells.", MessageTypes.Other);
                int spellOffset = _spells.GetSpellAt(new Vector2(pos.X, pos.Y));
                if (spellOffset > -1)
                {
                    Announcer.Instance.Announce("Clicked spells: " + spellOffset, MessageTypes.Other);
                    AttemptToUseSpell(spellOffset);
                }
            }
            else
            {
                // clicked the map
                Vector2 clickedWorldIndex = _world.ConvertScreenPositionToTileIndex(pos.X, pos.Y);

                if (_state == GameState.PlayerTurn)
                {
                    ICreature target = _world.GetCreatureAtIndex(clickedWorldIndex);
                    if (target != null)
                    {
                        _world.Player.AttackCreature(ref target);
                        _state = GameState.ComputerTurn;
                    }
                    else
                    {
                        if (_world.PlayerCanSeeWorldIndex(clickedWorldIndex))
                        {
                            // a cheese hack toward getting touch sort of working
                            Vector2 delta = clickedWorldIndex - _world.Player.WorldIndex;
                            if (delta.X < 0)
                            {
                                if (_world.MovePlayerInDirectionSuccessful(Direction.West))
                                {
                                    _state = GameState.ComputerTurn;
                                }
                            }
                            if (delta.X > 0)
                            {
                                if (_world.MovePlayerInDirectionSuccessful(Direction.East))
                                {
                                    _state = GameState.ComputerTurn;
                                }
                            }
                            if (delta.Y < 0)
                            {
                                if (_world.MovePlayerInDirectionSuccessful(Direction.North))
                                {
                                    _state = GameState.ComputerTurn;
                                }
                            }
                            if (delta.Y > 0)
                            {
                                if (_world.MovePlayerInDirectionSuccessful(Direction.South))
                                {
                                    _state = GameState.ComputerTurn;
                                }
                            }
                            _world.CenterCameraOnPlayer();
                        }
                    }
                }
                else if (_state == GameState.PlayerTurnSelectingDoorToClose)
                {
                    if (_world.CloseDoorAtPositionSuccessful(clickedWorldIndex, _world.Player.WorldIndex))
                    {
                        _state = GameState.ComputerTurn;
                    }
                    else
                    {
                        Announcer.Instance.Announce("Door at location does not exist or can't be closed.", MessageTypes.Other);
                        _state = GameState.PlayerTurn;
                    }
                }
                else if (_state == GameState.PlayerTurnSelectingTargetForSpell)
                {
                    Vector2 targetIndex = clickedWorldIndex;
                    if (_selectedSpell.TargetCanMove == false)
                    {
                        targetIndex = _world.Player.WorldIndex;
                    }
                    if (_selectedSpell.CastSpell(_world.Player, targetIndex) == true)
                    {
                        _state = GameState.ComputerTurn;
                    }
                    else
                    {
                        _state = GameState.PlayerTurn;
                    }
                }

                Announcer.Instance.Announce(clickedWorldIndex.X + ", " + clickedWorldIndex.Y, MessageTypes.Other);
            }
        }
Пример #4
0
        private void PlayTurn(IPlayer player, IPlayer opponent)
        {
            Console.WriteLine(constants.StartOfTurnOptions);

            while (true)
            {
                string input = Console.ReadLine();
                if (input == "8")
                {
                    break;
                }
                switch (input)
                {
                case "1":
                    Console.WriteLine(constants.AskToEnterCreatureName);
                    player.PrintCreaturesInHand();
                    ICreature creature = player.SelectACreature(Console.ReadLine());
                    if (creature.ManaCost > player.ManaCrystals)
                    {
                        Console.WriteLine(constants.NotEnoughManaCrystal);
                        break;
                    }
                    player.PlayCreature(creature);
                    break;

                case "2":
                    Console.WriteLine(constants.AskToEnterSpellName);
                    player.PrintSpellsInHand();
                    ISpell spell = player.SelectASpell(Console.ReadLine());
                    if (spell.ManaCost > player.ManaCrystals)
                    {
                        Console.WriteLine(constants.NotEnoughManaCrystal);
                        break;
                    }
                    player.ManaCrystals -= spell.ManaCost;
                    player.PlayerHand.Remove(spell);
                    Console.WriteLine(constants.MenuWhenCastingSpell);
                    switch (Console.ReadLine())
                    {
                    case "1":
                        spell.CastSpell(opponent);
                        break;

                    case "2":
                        CastSpellOnOpponentsCreature(player, opponent, spell);
                        break;
                    }
                    break;

                case "3":
                    if (opponent.BattleField.Count == 0)
                    {
                        Console.WriteLine(constants.EnemyDoesntHaveACreature);
                        PlayTurn(player, opponent);
                    }
                    else
                    {
                        Console.WriteLine(constants.AskToEnterCreatureName);
                        player.PrintCreaturesOnBattleField();
                        string    attackingCreature = Console.ReadLine().ToLower();
                        ICreature myCreature        = (ICreature)player.BattleField.FirstOrDefault(x => x.Name.ToLower() == attackingCreature);

                        Console.WriteLine(constants.EnterCreatureNameToBeAttacked);
                        opponent.PrintCreaturesOnBattleField();
                        string    defendingCreature = Console.ReadLine().ToLower();
                        ICreature oppoCreature      = (ICreature)opponent.BattleField.FirstOrDefault(x => x.Name.ToLower() == defendingCreature);
                        myCreature.Attack(oppoCreature);
                        if (oppoCreature.IsDead)
                        {
                            opponent.BattleField.Remove(oppoCreature);
                        }
                    }
                    break;

                case "4":
                    Console.WriteLine(constants.EnterCreatureName);
                    player.PrintCreaturesOnBattleField();
                    ICreature myCreature2 = (ICreature)player.BattleField.FirstOrDefault(x => x.Name.ToLower() == Console.ReadLine().ToLower());
                    myCreature2.Attack(opponent);
                    break;
                }
            }
        }
Пример #5
0
        public void performAttackPhase()
        {
            int playerAttack;
            int enemyAttack;

            if (_player.CalcTotalAttackValue() <= _enemy.CalcTotalDefenseValue() && _enemy.CalcTotalAttackValue() <= _player.CalcTotalDefenseValue())
            {
                playerAttack = (_player.CalcTotalAttackValue() + 5) - _enemy.CalcTotalDefenseValue();
                enemyAttack  = _enemy.CalcTotalAttackValue() - _player.CalcTotalDefenseValue();
            }
            else
            {
                playerAttack = _player.CalcTotalAttackValue() - _enemy.CalcTotalDefenseValue();
                enemyAttack  = _enemy.CalcTotalAttackValue() - _player.CalcTotalDefenseValue();
            }

            if (playerAttack <= 0)
            {
                playerAttack = 1;
            }
            if (enemyAttack < 0)
            {
                enemyAttack = 0;
            }

            _enemy.TakeDamage(playerAttack);

            // FIXME: See below
            ISpell enemySpell = _enemy.Equipped.GetItem(InventorySlotId.WEAPON) as ISpell;

            if (enemySpell != null)
            {
                int spellDamage = enemySpell.CastSpell();
                spellDamage -= _player.CalcTotalDefenseValue();
                if (spellDamage > 0)
                {
                    _player.TakeDamage(spellDamage);
                }
            }
            else if (!_enemy.IsDead)
            {
                _player.TakeDamage(enemyAttack);
            }


            if (_enemy.Name == "The End" && _enemy.IsDead)
            {
                _gameWon = true;
            }
            if (_enemy.IsDead)
            {
                _depth++;
            }
            if (_player.IsDead)
            {
                System.IO.Stream         str = Properties.Resources.death_sound;
                System.Media.SoundPlayer snd = new System.Media.SoundPlayer(str);
                snd.Play();
                _gameOver = true;
            }
        }