Exemplo n.º 1
0
    /// <summary>
    /// Possibly adds an animal at a grid position, by reading a given symbol.
    /// If the symbol does not represent an animal, then nothnig happens.
    /// </summary>
    /// <param name="x">The x-coordinate of the tile.</param>
    /// <param name="y">The y-coordinate of the tile.</param>
    /// <param name="symbol">The symbol to read.</param>
    void AddAnimal(int x, int y, char symbol)
    {
        Animal result = null;

        // a shark?
        if (symbol == '@')
        {
            result = new Shark(this, new Point(x, y));
        }

        // a penguin or seal, possibly inside a hole?
        if (result == null)
        {
            int animalIndex = GetAnimalIndex(symbol);
            if (animalIndex < 0)
            {
                animalIndex = GetAnimalInHoleIndex(symbol);
            }

            if (animalIndex >= 0)
            {
                result = new MovableAnimal(this, new Point(x, y), animalIndex);
            }
        }
    }
Exemplo n.º 2
0
    protected override void ApplyCurrentPosition()
    {
        // set the position in the game world
        LocalPosition = level.GetCellPosition(currentGridPosition.X, currentGridPosition.Y);

        // stop moving
        velocity = Vector2.Zero;

        // If the current tile already contains another animal, then both animals should disappear!
        Animal otherAnimal = level.GetAnimal(currentGridPosition);

        if (otherAnimal != null)
        {
            level.RemoveAnimalFromGrid(currentGridPosition);
            Visible             = false;
            otherAnimal.Visible = false;

            // if the other animal matches, notify the game that we've made a pair
            if (otherAnimal is MovableAnimal)
            {
                MovableAnimal other = (MovableAnimal)otherAnimal;
                level.PairFound(this, other);
            }
            // otherwise, the animal is touching a shark: play a sound
            else
            {
                ExtendedGame.AssetManager.PlaySoundEffect("Sounds/snd_eat");
            }

            return;
        }

        // if the current tile has the "empty" type, let the animal die
        Tile.Type tileType = level.GetTileType(currentGridPosition);
        if (tileType == Tile.Type.Empty)
        {
            // the animal has fallen into the water: play a sound
            ExtendedGame.AssetManager.PlaySoundEffect("Sounds/snd_eat");

            Visible = false;
            return;
        }

        // In all other cases, the animal shouldn't disappear yet, so it's still part of the level.
        // Add the animal to the level's grid.
        level.AddAnimalToGrid(this, currentGridPosition);

        // if the current tile is a hole, mark this animal as "inside a hole"
        if (tileType == Tile.Type.Hole)
        {
            IsInHole = true;
        }
    }
Exemplo n.º 3
0
    bool IsPairWith(MovableAnimal other)
    {
        // if one animal is a seal, then there's no match
        if (IsSeal || other.IsSeal)
        {
            return(false);
        }

        // if one animal is a multi-colored penguin, then there's always a match
        if (IsMultiColoredPenguin || other.IsMultiColoredPenguin)
        {
            return(true);
        }

        // otherwise, there's a match if both animals are the same type of penguin
        return(AnimalIndex == other.AnimalIndex);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Updates the game's status after a pair of matching penguins has been created.
    /// </summary>
    /// <param name="penguin1">The first penguin.</param>
    /// <param name="penguin2">The second penguin.</param>
    public void PairFound(MovableAnimal penguin1, MovableAnimal penguin2)
    {
        int penguinType = MathHelper.Max(penguin1.AnimalIndex, penguin2.AnimalIndex);

        pairList.AddPair(penguinType);

        // if the level has been completed, notify the playing state
        if (pairList.Completed)
        {
            PlayingState playingState = (PlayingState)ExtendedGame
                                        .GameStateManager.GetGameState(PenguinPairs.StateName_Playing);
            playingState.LevelCompleted(LevelIndex);
        }
        else
        {
            ExtendedGame.AssetManager.PlaySoundEffect("Sounds/snd_pair");
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Possibly adds an animal at a grid position, by reading a given symbol.
    /// If the symbol does not represent an animal, then nothnig happens.
    /// </summary>
    /// <param name="x">The x-coordinate of the tile.</param>
    /// <param name="y">The y-coordinate of the tile.</param>
    /// <param name="symbol">The symbol to read.</param>
    void AddAnimal(int x, int y, char symbol)
    {
        Animal result = null;

        // a shark?
        if (symbol == '@')
        {
            result = new Shark(this);
        }

        // a penguin or seal that is not in a hole?
        if (result == null)
        {
            int animalIndex = GetAnimalIndex(symbol);
            if (animalIndex >= 0)
            {
                result = new MovableAnimal(this, animalIndex, false);
            }
        }

        // a penguin or seal that *is* in a hole?
        if (result == null)
        {
            int animalIndex = GetAnimalInHoleIndex(symbol);
            if (animalIndex >= 0)
            {
                result = new MovableAnimal(this, animalIndex, true);
            }
        }

        // if we've loaded an animal now, add it to the grid
        if (result != null)
        {
            result.LocalPosition = GetCellPosition(x, y);
            animalsOnTiles[x, y] = result;
        }
    }
 public override void Reset()
 {
     base.Reset();
     SelectedAnimal = null;
 }
Exemplo n.º 7
0
    /// <summary>
    /// Updates the game's status after a pair of matching penguins has been created.
    /// </summary>
    /// <param name="penguin1">The first penguin.</param>
    /// <param name="penguin2">The second penguin.</param>
    public void PairFound(MovableAnimal penguin1, MovableAnimal penguin2)
    {
        int penguinType = MathHelper.Max(penguin1.AnimalIndex, penguin2.AnimalIndex);

        pairList.AddPair(penguinType);
    }
Exemplo n.º 8
0
 /// <summary>
 /// Marks the given animal as the selected one.
 /// </summary>
 /// <param name="animal">The animal to select.</param>
 public void SelectAnimal(MovableAnimal animal)
 {
     selector.SelectedAnimal = animal;
 }