Пример #1
0
    // Action model - check if action is applicable
    public bool CheckActionApplicable(BlockWorldAction action)
    {
        int i = ActionToI(action);
        int j = ActionToJ(action);

        bool ground           = CheckGroundByIndex(i, j);
        bool immutable        = CheckGroundImmutableByIndex(i, j);
        bool currentSupported = CheckPositionSupported(Player.I, Player.J);

        if (immutable)
        {
            return(false);
        }

        // Only certain times can the player move through ground
        if (ground)
        {
            if (Player.Ammo == 0)
            {
                return(false);
            }

            // Lightning is only way to move upwards through ground
            if (action == BlockWorldAction.Up)
            {
                return(currentSupported && Player.Weapon == WeaponType.Lightning);
            }

            // Rockets go to the sides
            if (action == BlockWorldAction.Left || action == BlockWorldAction.Right)
            {
                return(currentSupported && Player.Weapon == WeaponType.Rockets);
            }

            // Bombs go down
            if (action == BlockWorldAction.Down)
            {
                return(Player.Weapon == WeaponType.Bombs);
            }

            return(false);

            // TODO: Minions cannot be used to determine a definite path. How to handle this?
        }
        else
        {
            // Ground support is the only influence
            if (action != BlockWorldAction.Down && !currentSupported)
            {
                return(false);
            }
            return(true);
        }
    }
Пример #2
0
 public int ActionToJ(BlockWorldAction action)
 {
     if (action == BlockWorldAction.Up)
     {
         return(Player.J - 1);
     }
     else if (action == BlockWorldAction.Down)
     {
         return(Player.J + 1);
     }
     return(Player.J);
 }
Пример #3
0
 // Gets I, J coordinates of new player position for an action
 public int ActionToI(BlockWorldAction action)
 {
     if (action == BlockWorldAction.Left)
     {
         return(Player.I + 1);
     }
     else if (action == BlockWorldAction.Right)
     {
         return(Player.I - 1);
     }
     return(Player.I);
 }
Пример #4
0
    // Advance with a single action
    public void Advance(BlockWorldAction action, bool collectAmmo = true)
    {
        // Checks action applicability
        if (!CheckActionApplicable(action))
        {
            return;
        }

        // Move to new location
        Player.I = ActionToI(action);
        Player.J = ActionToJ(action);

        // Collect ammo
        if (collectAmmo)
        {
            WeaponType weapon = CheckAmmo(Player.I, Player.J);
            if (weapon != WeaponType.None)
            {
                if (Player.Ammo != -1)
                {
                    Player.Ammo = 3;
                }
                Player.Weapon     = weapon;
                justCollectedAmmo = true;
            }
        }

        // Blow out ground if needed and reduce ammo
        if (CheckGroundByIndex(Player.I, Player.J))
        {
            SetGroundByIndex(Player.I, Player.J, false);
            Player.Ammo--;
            if (Player.Ammo == 0)
            {
                Player.Weapon = WeaponType.None;
            }
        }
    }