Ejemplo n.º 1
0
    private StageData GenerateRandomStage(int seed)
    {
        Random.InitState(seed);
        int           stripCount     = Random.Range((this.minStrips - 1) / 2, (this.maxStrips - 1) / 2) * 2 + 1; // Should be odd?
        int           min            = Mathf.Max(this.minLongestStripLength, stripCount / 2 + 1);
        int           maxStripLength = Random.Range(min, this.maxLongestStripLength + 1);
        HoneycombData honey          = HoneycombData.Generate(stripCount, maxStripLength);

        // For each hex, give it random contents.
        foreach (StripData stripData in honey.strips)
        {
            foreach (HexData data in stripData.hexes)
            {
                this.RandomizeHex(data);
            }
        }

        // Pick a random starting location.
        // Do this last so it replaces whatever was at the hex's location.
        int     strip   = Random.Range(0, stripCount);
        int     hex     = Random.Range(0, honey.GetStripLength(strip));
        HexData hexData = honey.strips[strip].hexes[hex];

        hexData.entityType = EntityType.Player;
        hexData.entityData = HexData.PLAYER_DATA_HEAD;

        StageData stageData = new StageData();

        stageData.name             = "Random stage from seed " + seed;
        stageData.growthPerSegment = this.possibleGrowthPerSegment[Random.Range(0, this.possibleGrowthPerSegment.Length)];
        stageData.honeycomb        = honey;
        return(stageData);
    }
Ejemplo n.º 2
0
    // Creates a new honeycomb in the game, initialized with the given data.
    public void InitializeWithData(HoneycombData data)
    {
        // Destroy all old game objects.
        foreach (Strip strip in this.strips)
        {
            GameObject.Destroy(strip);
        }
        this.strips.Clear();

        // Compute the honeycomb properties.
        float stripWidth = Util.edgeLengthToStripWidth(this.edgeLength);

        // Compute the position of the first strip.
        // The center of each strip is the middle of the strip.
        // Each strip runs parallel to the y-axis. Their centers are in a line parallel to the x-axis.
        Vector3 nextPosition = this.transform.position;

        nextPosition.x -= (data.strips.Length - 1f) * 0.5f * stripWidth;
        // Create the strips.
        for (int i = 0; i < data.strips.Length; ++i)
        {
            StripData stripData = data.strips[i];
            Strip     strip     = Instantiate <Strip>(this.stripPrefab, nextPosition, Quaternion.identity);
            strip.stripNumber = i;
            this.strips.Add(strip);
            strip.InitializeWithData(stripData, this.edgeLength);
            // Set the next hex's position.
            nextPosition.x += stripWidth;
        }
    }
Ejemplo n.º 3
0
 public void Undo()
 {
     if (this.undoStack.Count == 0)
     {
         // Do nothing.
         return;
     }
     this.currentData = this.undoStack.Pop().Deserialize();
     this.UpdateGameFromData();
 }
Ejemplo n.º 4
0
 // Sets the honeycomb's current data. Assumes the data has the same honeycomb size as the current honeycomb.
 // To change the size of the honeycomb, use InitializeWithData instead.
 public void SetData(HoneycombData data)
 {
     if (this.strips.Count != data.strips.Length)
     {
         Debug.LogError("Cannot set honeycomb data: data has wrong number of strips.");
         return;
     }
     for (int i = 0; i < this.strips.Count; ++i)
     {
         StripData stripData = data.strips[i];
         this.strips[i].SetData(stripData);
     }
 }
Ejemplo n.º 5
0
    public void InitializeWithData(StageData data)
    {
        this.growthPerSegment = data.growthPerSegment;
        this.currentData      = data.honeycomb;

        this.stageNameText.text         = data.name;
        this.stageInstructionsText.text = data.instructions;

        // Initialize the player's data.
        this.currentData.player.totalGrowth       = 0;
        this.currentData.player.itemsCollected    = 0;
        this.currentData.player.powerupsCollected = 0;
        this.currentData.player.totalMoves        = 0;
        Player.instance.Clear();

        // Initialize the honeycomb.
        Honeycomb.instance.InitializeWithData(this.currentData);
        this.UpdateUI();
    }
Ejemplo n.º 6
0
    // stripCount should be an odd number...?
    public static HoneycombData Generate(int stripCount, int maxLength)
    {
        HoneycombData honey = new HoneycombData();

        honey.strips = new StripData[stripCount];

        for (int s = 0; s < stripCount; ++s)
        {
            int       length = GetStripLength(s, stripCount, maxLength);
            StripData strip  = new StripData();
            strip.hexes     = new HexData[length];
            honey.strips[s] = strip;

            for (int i = 0; i < length; ++i)
            {
                HexData hex = new HexData();
                strip.hexes[i] = hex;
            }
        }

        return(honey);
    }
Ejemplo n.º 7
0
    public int GetStripLength(int stripNumber)
    {
        int middleStrip = this.strips.Length / 2;

        return(HoneycombData.GetStripLength(stripNumber, this.strips.Length, this.strips[middleStrip].hexes.Length));
    }