
#include "spec.h"


/*tetris ?*/

const char * Tetris[] = {
	"24445  8",
	"22345  9",
	"21335  8",
	"11135 7",
	"6666 777",
	0
};

#define isFirstColumn (col==0)
#define isFirstRow (row==0)
#define dontFirstColumn (col!=0)
#define dontFirstRow (row!=0)
void DrawTetrominos (char**tetris,Let x, Let y){
	for (int row=0;tetris[row]!=0;row++)
	for (int col=0;tetris[row][col]!=0;col++){
		//another algo, corner checker, only 2x2 backward
		Let sym = Rose;
		if(isFirstColumn)
		sym &= ~West;
		if(isFirstRow)
		sym &= ~North;
		if(dontFirstColumn && row!=0 && tetris[row][col-1] == tetris[row-1][col-1] )
		sym &= ~West;
		if(col!=0 && row!=0 && tetris[row-1][col] == tetris[row-1][col-1] )
		sym &= ~North;
		if(row!=0 && tetris[row][col] == tetris[row-1][col])
		sym &= ~East;
		if(col!=0 && tetris[row][col] == tetris[row][col-1])
		sym &= ~South;

		Sym(sym,x+col,y+row,White);
	
		if(tetris[row+1]==0 && tetris[row][col+1]==0){
			Sym(	North+West,
				x+col+1,
				y+row+1,
				White);
		}	
		if(tetris[row+1]==0){
			sym = Rose-South;
			if(col==0)
			sym &= ~West;
			else if(tetris[row][col] == tetris[row][col-1] )
			sym &= ~North;
			Sym(	sym,
				x+col,
				y+row+1,
				White);
		}
		if(tetris[row][col+1] == 0){
			sym = Rose-East;
			if(row==0)
			sym &= ~North;
			else if(tetris[row][col] == tetris[row-1][col])
			sym &= ~West;
			Sym(	sym,
				x+col+1,
				y+row,
				White);
		}
	}
}
#undef firstColumn
#undef firstRow

const char * Tetrominos[] = {
	"@L2-2@Lv3@L<@Lv3@L<L^2@L<L",
	"@L2@Lv2|3@L<L^2|",
	""
};
enum { 
	T,
	I
} Tetromino;
void Tetris_End(Co c){

	DrawTetrominos(Tetris,20,10);

	AnyKey(c,0);
}

void Tetris_Loop(Co c){

	Pth(Tetrominos[1],15,10,White);

	AnyKey(c,Tetris_End);
}

void Tetris_Begin(Co c){
	
	Pth(Tetrominos[0],10,10,White);
	
	AnyKey(c,Tetris_Loop);
}


