#pragma once

#include "cube.object.h"

#include <time.h>
#include <stdlib.h>

// 随机数初始化
void rand_init()
{
	srand((unsigned int)time(NULL));
}
// 本来是想做随机颜色的, 但发现效果不好...
COLORREF random_color()
{
	return RGB(255, 255, 255);
}

enum rect_class
{
	ONE_BLOCK, /*
				 xxx
			     x*x
				 xxx
			   */
	TWO_BLOCK_PORTRAIT, 
	           /*
				 x*x
				 x*x
				 xxx
			   */
	TWO_BLOCK_LANDSCAPE,
			   /*
				 xxx
				 **x
				 xxx
			   */
	THREE_BLOCK_MIDDLE,
				/*
				 x*x
				 ***
				 xxx
	 		    */
	THREE_BLOCK_LEFT,
				/*
				 *xx
				 **x
				 xxx
				*/
};

// 随机产生形状
image_object random_rect()
{
	int block  = rand() % 5;

	image_object object;

	switch (block)
	{
	case ONE_BLOCK: 
	{
		object.height = 60 * 2;
		object.width = 60 * 2;

		object.image = IMAGE(60 * 2, 60 * 2);

		SetWorkingImage(&object.image);

		setfillcolor(random_color());

		fillrectangle(60, 60, 120, 120);

		SetWorkingImage();

		break;
	}
	case TWO_BLOCK_LANDSCAPE:
	{
		object.height = 60 * 2;
		object.width = 60 * 2;

		object.image = IMAGE(60 * 2, 60 * 2);

		SetWorkingImage(&object.image);

		setfillcolor(random_color());

		fillrectangle(0, 60, 120, 120);

		SetWorkingImage();

		break;
	}
	case TWO_BLOCK_PORTRAIT:
	{
		object.height = 60 * 2;
		object.width = 60 * 2;

 		object.image = IMAGE(60 * 2, 60 * 2);

		SetWorkingImage(&object.image);

		setfillcolor(random_color());

		fillrectangle(60, 0, 120, 120);

		SetWorkingImage();

		break;
	}
	case THREE_BLOCK_MIDDLE:
	{
		object.height = 60 * 2;
		object.width = 60 * 3;

		object.image = IMAGE(60 * 3, 60 * 2);

		SetWorkingImage(&object.image);

		setfillcolor(random_color());

		fillrectangle(60, 0, 120, 60);
		fillrectangle(0, 60, 180, 120);

		SetWorkingImage();

		break;
	}
	case THREE_BLOCK_LEFT:
	{
		object.height = 60 * 2;
		object.width = 60 * 3;

		object.image = IMAGE(60 * 3, 60 * 2);

		SetWorkingImage(&object.image);

		setfillcolor(random_color());

		fillrectangle(0, 0, 60, 60);
		fillrectangle(0, 60, 120, 120);

		SetWorkingImage();

		break;
	}
	}

	object.object_type = block;

	render_image_alpha(&object.image);

	return object;
}
