示例#1
0
    private ScaredPlant DeepCopy()
    {
        ScaredPlant other = (ScaredPlant)this.MemberwiseClone();

        other.runningDirection = this.runningDirection;
        other.KeepRunning      = this.KeepRunning;
        other.isRunning        = this.isRunning;
        return(other);
    }
示例#2
0
    // Why does Instantiate(prefab) clear values from the class I'm giving it? Is there a interface I can override or w.e to do this automatically??
    public override void Initialize(CellController parent)
    {
        base.Initialize(parent);
        ScaredPlant scaredParent = parent as ScaredPlant;

        if (scaredParent)
        {
            runningDirection = scaredParent.runningDirection;
        }
    }
示例#3
0
    public override bool Grow()
    {
        bool hasGrown = false;

        if (isRunning && KeepRunning)
        {
            CellController neighbour = this.Grid.GetCellInDirection(this.X, this.Y, runningDirection);

            if (CanClaim(neighbour))
            {
                neighbour.Claim(this);
                hasGrown = true;
            }
        }


        foreach (GridDirection direction in DirectionsToRunFrom)
        {
            CellController neighbour = this.Grid.GetCellInDirection(this.X, this.Y, direction);

            if (NeighbourIsPlant(neighbour))
            {
                CellController oppositeNeighbour = this.Grid.GetCellInDirection(this.X, this.Y, direction.Opposite());

                if (CanClaim(oppositeNeighbour))
                {
                    if (!isRunning)
                    {
                        isRunning        = true;
                        runningDirection = direction.Opposite();
                    }

                    ScaredPlant copy = DeepCopy();
                    copy.runningDirection = direction.Opposite();
                    oppositeNeighbour.Claim(copy);
                    hasGrown = true;
                }
            }
        }
        return(hasGrown);
    }