#ifndef TILES_H
#define TILES_H

#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <intraFont.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <pspgum.h>
#include <time.h>
#include <psputils.h>
#include <math.h>
#include <psprtc.h>

extern "C"
{
    #include "graphics.h"
    #include "framebuffer.h"
	//#include "timer.h"
};


class Tiles{
private:
	int int_active_chars[7];	/**/
	int int_char_x[7];			/*x coordinates for tile placement*/
	int int_char_y[2];			/*y coordinates for tile placement*/
	int int_cursor_loc; 		/*location of cursor*/
	int int_tile_ans[7]; 		/*Used to keep track what tiles are at ans position;Uses tileID*/
    int int_tile_last[7];       /*Last word entered*/
	int int_tile_idle[7]; 		/*uses tileID*/
	int int_scrambled[7];		/*for generating random location*/
				
    int intAnsStatus;           /*Status of answer:*/
                                /*0 = incorrect*/
                                /*1 = correct*/
                                /*-1 = answered already*/
    float ansResTimer;          /*How many seconds the message for result stayed displayed*/

               

	typedef struct{
		char charAns[8];
		int intShow;  /*1 to show, 0 not to show*/
		int intX;
		int intY;
		}lstAns;

	lstAns lstAnsAll[500];
	
	typedef struct {
		unsigned char letter;		
		Image* img;
		int dx;	
		int dy;
		int fx;
		int fy;
		float tl;
		
	}tile_struct;
	
	tile_struct tile_info[7];
	void genPuzzle(void);
	int chkRepeat(uint idx7);
	
public:
	int debugvalue;
	int OKNextRound;            /*Flag for ok next round*/
    int intAnsTotal;            /*Total of correct Answers*/
    int int_keyed_in;           /*number of tiles keyed-in*/
    int intCorrectAns;                              
	Tiles(void);
	~Tiles();
	void initTiles(void);
	void scrambleTiles(void);
	void keyInTile(void);
	void backOneTile(void);
	void backAll(void);
	void keyInLast(void);
	void drawTiles(float);
	void moveCursor(int);
	void genRandomOrder(void);
	void drawWordAns(void);
	void genAnsList(void);
	void chkAns(void);
    void RevealAns(void);
	

};






extern Image * img_char[26];       /*pointer to tile images*/
extern Image * img_cursor;         /*pointer to cursor image*/

typedef struct{
    char    strName[11];
    int     intScore;
    int     intRound;
}highscores;

extern highscores  lstHighScores[10];
extern int intHScoreCount;

extern intraFont* ltn[16];
//extern intraFont* jpn0;


//extern unsigned int word7total;

extern unsigned int prevword[200];
extern unsigned int prevwordidx;
extern uint score;
//extern int roundcount;


extern unsigned char words3[] __attribute__((aligned(16)));
extern unsigned char words4[] __attribute__((aligned(16)));
extern unsigned char words5[] __attribute__((aligned(16)));
extern unsigned char words6[] __attribute__((aligned(16)));
extern unsigned char words7[] __attribute__((aligned(16)));
extern unsigned int size_words3;
extern unsigned int size_words4;
extern unsigned int size_words5;
extern unsigned int size_words6;
extern unsigned int size_words7;






enum colors {
	RED         =   0xFF0000FF,
	GREEN       =   0xFF00FF00,	
	BLUE        =	0xFFFF0000,
	YELLOW      =   0xFF00FFFF,
	WHITE       =   0xFFFFFFFF,
	LITEGRAY    =   0xFFBFBFBF,
	GRAY        =	0xFF7F7F7F,
	DARKGRAY    =   0xFF3F3F3F,		
	BLACK       =   0xFF000000,
	LITEBLUE    =   0xFFfac592,
};

//Ending instruction when using intrafont
#define endIntraFont	sceGuTexMode(GU_PSM_8888, 0, 0, 0); \
						sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA); \
						sceGuTexFilter(GU_NEAREST, GU_NEAREST); \
						sceGuFinish(); \
						sceGuSync(0,0);




#endif
