Package com.sirenian.hellbound.engine

Source Code of com.sirenian.hellbound.engine.PseudoRandomGlyphFactory

package com.sirenian.hellbound.engine;

import java.util.Random;

import com.sirenian.hellbound.domain.glyph.GlyphType;
import com.sirenian.hellbound.domain.glyph.Junk;
import com.sirenian.hellbound.domain.glyph.LivingGlyph;
import com.sirenian.hellbound.util.ListenerSet;
import com.sirenian.hellbound.util.Logger;

public class PseudoRandomGlyphFactory implements GlyphFactory {

    private final Random random;
    private final int width;
    private final int height;

    public PseudoRandomGlyphFactory(int width, int height) {
        this(System.currentTimeMillis(), width, height);
    }
   
    public PseudoRandomGlyphFactory(long seed, int width, int height) {
        this.width = width;
        this.height = height;
        random = new Random(seed);
    }

    public LivingGlyph nextGlyph(CollisionDetector detector, ListenerSet glyphListeners) {
        GlyphType glyphType = GlyphType.ALL_LIVING[random.nextInt(GlyphType.ALL_LIVING.length)];
        Logger.debug(this, "Creating next glyph, glyph type is " + glyphType);
        LivingGlyph glyph = new LivingGlyph(glyphType, detector, CenterCalculator.forWidth(width));
        glyph.addListeners(glyphListeners);
    return glyph;
    }

  public Junk createJunk(ListenerSet glyphListeners) {
    Junk junk = new Junk(width, this.height);
        junk.addListeners(glyphListeners);
        return junk;
  }

}
TOP

Related Classes of com.sirenian.hellbound.engine.PseudoRandomGlyphFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.