#pragma once
#ifndef TETRIMINO_MANAGER_H
#define TETRIMINO_MANAGER_H

//Includes
#include <list>

//Forward declarations
class SDL_Surface;

using namespace std;


//Different block colors are associated with different piece shapes
typedef enum BlockColor
{
	TET_I,
	TET_J,
	TET_L,
	TET_O,
	TET_S,
	TET_T,
	TET_Z,
	TET_COUNT,
	TET_EMPTY
} BlockColor;

#define BLOCKIMAGE_SIZE 24

//Orly?
#define TETRIMINO_SIZE 4

#define QUEUE_LENGTH 2

//Represents one tetris piece
class Tetrimino
{
public:
	//Constructor
	Tetrimino(BlockColor* shape);

	//Draw this piece to the given surface
	void draw(SDL_Surface* target, int posx, int posy);

	//Rotate this piece
	void rotateCW();

	//Retrieve data on this piece's internal grid
	BlockColor getBlockAt(int x, int y) const;

	int getLeftmost() const;
	int getRightmost() const;

private:
	//Internal storage for this piece's shape
	BlockColor shape[TETRIMINO_SIZE][TETRIMINO_SIZE];
};

//This class manages the images and shapes of the different tetriminos
class TetriminoManager
{
public:
	//Load data for the manager
	static void Init();

	//Unload heap-allocated manager data
	static void Deinit();

	//Retrieve the next piece and queue a new one
	static Tetrimino* nextTetrimino();

	//Draw the upcoming pieces queue
	static void drawQueue(SDL_Surface* surface, int posx, int posy);

	//Get the image associated with the specified index
	static SDL_Surface* getBlockImage(BlockColor block);

private:
	//Put a new random tetrimino in the queue
	static void queueNewTetrimino();

	//Queue storing the upcoming pieces
	static list<Tetrimino*> upcoming;

	//Storage for the different block images
	static SDL_Surface* blockImages[TET_COUNT];

	//Storage for the different tetrimino shapes
	static BlockColor shapes[TET_COUNT][TETRIMINO_SIZE * TETRIMINO_SIZE];
};


#endif