Exemple #1
0
                public static void EasyAI()
                {
                    Random r = new Random();

                    foreach (Creature Creature in Engine.CurrentBattle.Creatures)
                    {
                        if (Creature.InRange(Engine.CurrentBattle.Player, 1))
                        {
                            Debug.WriteLine("Opponent: I will attack");
                            List<XNAObject> Target = new List<XNAObject>();
                            Target.Add(Engine.CurrentBattle.Player);
                            Creature.Actions[0].Resolve(Creature, Target);
                        }

                        Vector2 Direction = new Vector2(r.Next(-1, 2), r.Next(-1, 2));

                        Point Location = new Point(Creature.Bounds.X + (int)(Direction.X * 64), Creature.Bounds.Y + (int)(Direction.Y * 64));

                        MoveCommand move = new MoveCommand(Creature, Location);
                        if (move.CanExecute(Location))
                        {
                            Debug.WriteLine("Opponent: I will move");
                            move.Execute();
                        }
                        else
                        {
                            return;
                        }

                    }
                }
Exemple #2
0
        public void Player_KeyPress(object sender, KeyboardState keyboardState)
        {
            if (Engine.GameState != Engine.State.PlayersTurn)
            {
                return;
            }
            else
            {
                // Using key command for actions

                // Move command
                if (keyboardState.IsKeyDown(Keys.M))
                {
                    MoveCommand move = new MoveCommand(this);

                    Engine.CommandQueue.Add(move);

                    Engine.CurrentCommandInput = move;
                }

                if (keyboardState.IsKeyDown(Keys.C))
                {
                    CastSpellCommand castspell = new CastSpellCommand();
                    castspell.Character = this;
                    castspell.Spell = Templates.Actions.Spells.Spark();

                    Engine.CommandQueue.Add(castspell);

                    Engine.CurrentCommandInput = castspell;
                }

                if (keyboardState.IsKeyDown(Keys.E))
                {
                    // End turn
                    Engine.EndPlayerTurn();
                }

                if (keyboardState.IsKeyDown(Keys.H))
                {
                    CastSpellCommand castspell = new CastSpellCommand();
                    castspell.Character = this;
                    castspell.Spell = Templates.Actions.Spells.Heal();

                    Engine.CommandQueue.Add(castspell);

                    Engine.CurrentCommandInput = castspell;
                }

                if (keyboardState.IsKeyDown(Keys.F))
                {
                    CastSpellCommand castspell = new CastSpellCommand();
                    castspell.Character = this;
                    castspell.Spell = Templates.Actions.Spells.Fireball();

                    Engine.CommandQueue.Add(castspell);

                    Engine.CurrentCommandInput = castspell;
                }

                if (keyboardState.IsKeyDown(Keys.S))
                {
                    MoveCommand move = new MoveCommand(this);
                    move.MapPoint.X = Bounds.X;
                    move.MapPoint.Y = Bounds.Y + 64;
                    if (move.CanExecute(move.MapPoint))
                    {
                        move.Execute();
                    }
                }

                if (keyboardState.IsKeyDown(Keys.W))
                {
                    MoveCommand move = new MoveCommand(this);
                    move.MapPoint.X = Bounds.X;
                    move.MapPoint.Y = Bounds.Y - 64;
                    if (move.CanExecute(move.MapPoint))
                    {
                        move.Execute();
                    }
                }

                if (keyboardState.IsKeyDown(Keys.A))
                {
                    MoveCommand move = new MoveCommand(this);
                    move.MapPoint.X = Bounds.X - 64;
                    move.MapPoint.Y = Bounds.Y;
                    if (move.CanExecute(move.MapPoint))
                    {
                        move.Execute();
                    }
                }

                if (keyboardState.IsKeyDown(Keys.D))
                {

                    MoveCommand move = new MoveCommand(this);
                    move.MapPoint.X = Bounds.X + 64;
                    move.MapPoint.Y = Bounds.Y;
                    if (move.CanExecute(move.MapPoint))
                    {
                        move.Execute();
                    }
                }

            }
        }