Tetris Piece Rotation Algorithm

前端 未结 15 876
傲寒
傲寒 2020-11-30 17:57

What are the best algorithms (and explanations) for representing and rotating the pieces of a tetris game? I always find the piece rotation and representation schemes confu

15条回答
  •  情话喂你
    2020-11-30 18:12

    Personally I've always just represented the rotations by hand - with very few shapes, it's easy to code that way. Basically I had (as pseudo-code)

    class Shape
    {
        Color color;
        ShapeRotation[] rotations;
    }
    
    class ShapeRotation
    {
        Point[4] points;
    }
    
    class Point
    {
        int x, y;
    }
    

    At least conceptually - a multi-dimensional array of points directly in shape would do the trick too :)

提交回复
热议问题