From 5c4503268f62c30d814db74dde56bfdbf5aa9293 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 17 Sep 2025 06:38:37 +0200 Subject: [PATCH] feat: add game/shape_queue.go --- game/shape_queue.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 game/shape_queue.go diff --git a/game/shape_queue.go b/game/shape_queue.go new file mode 100644 index 0000000..7d53d8f --- /dev/null +++ b/game/shape_queue.go @@ -0,0 +1,43 @@ +package game + +import ( + "math/rand" +) + +type ShapeQueue struct { + shapes []ShapeType +} + +func NewShapeQueue() *ShapeQueue { + sq := &ShapeQueue{ + shapes: []ShapeType{}, + } + sq.Generate() + return sq +} + +func (sq *ShapeQueue) Generate() { + types := []ShapeType{ + SHAPE_I, + SHAPE_J, + SHAPE_L, + SHAPE_O, + SHAPE_S, + SHAPE_T, + SHAPE_Z, + } + rand.Shuffle(len(types), func(i int, j int) { + types[i], types[j] = types[j], types[i] + }) + + sq.shapes = append(sq.shapes, types...) +} + +func (sq *ShapeQueue) Next() Shape { + if len(sq.shapes) < 1 { + sq.Generate() + } + t := sq.shapes[0] + sq.shapes = sq.shapes[1:] + return NewShape(t) +}