Beispiel #1
0
/**
 * 文字列表示
 */
void glcd_puts(const char *s)
{
    switch(font_type) {
    case ASCII7_8x16:
	/* 常に1バイト=1文字と想定し、文字出力する */
	while(s[0]) {
	    glcd_putchar(s[0]);
	    s += 1;
	}
	break;

    case EUCJP_8x16:
	/* 第1バイトの第7ビットが0の場合はASCII, 
	 * 第1バイトがSS2の場合はJIS X0201(半角カナ)、
	 * それ以外はJIS X0208と決め打ちする。
	 * 不正コード、補助漢字は扱わない */
	while(s[0]) {
	    if(s[0] & 0x80 == 0) {
		glcd_putchar(s[0]);
		s += 1;
	    } else {
		glcd_putchar((s[0] << 8) | s[1]);
		s += 2;
	    }
	}
	break;

    case UTF8_8x16:
	/* UTF-8符号化に従ってデコードする。
	 * 第1バイトだけでバイト数を決め打ちし、
	 * 不正コードは特にチェックしない。
	 * UCS-2に収まらないコードポイントは単に読み捨てる。
	 * デコードされたコードポイントがすべて表示できるわけではない。*/
	while(s[0]) {
	    if(s[0] <= 0x7f) {
		/* 0xxxxxxx */
		glcd_putchar(s[0]);
		s += 1;
	    } else if(s[0] <= 0xdf) {
		/* 110yyyyx 10xxxxxx */
		glcd_putchar((s[0] & 0x1f) << 6 | (s[1] & 0x3f));
		s += 2;
	    } else if(s[0] <= 0xef) {
		/* 1110yyyy 10yxxxxx 10xxxxxx  */
		glcd_putchar((s[0] & 0x0f) << 12
			     | (s[1] & 0x3f) << 6 | (s[2] & 0x3f));
		s += 3;
	    } else if(s[0] <= 0xf7) {
		/* 11110yyy 10yyxxxx 10xxxxxx 10xxxxxx */
		s += 4;
	    } else if(s[0] <= 0xfb) {
		/* 111110yy 10yyyxxx 10xxxxxx 10xxxxxx 10xxxxxx */
		s += 5;
	    } else if(s[0] <= 0xfd) {
		/* 1111110y 10yyyyxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */
		s += 6;
	    } else {
		s += 1;
	    }
	}
	break;
    }
}
int main(void)
{
	
	/*Se inicializan los puertos.	*/
	DDRB=0x00;
	DDRA= 0xFF;
	DDRC=0xff;
	
	/*Se inicializan los puertos que generan las interupciones externas */
	DDRD= 0x00;
	DDRE=0x00;
	
	DATADDR = 0xff;	
	//Se inicializan las interrupciones
	
	EICRA= 0xFF;
	EICRB= 0xFF;
	
	/**Se habilitan las interrupciones */	
	sei();	
	
	//*puntresetPushed=&variablesJuego.resetPushed;
	//Se inicializan las variables necesarias para jugar
	ReiniciarJuego(&variablesJuego);
	
	//Inicializar GLCD
	glcd_on();	
	glcd_clear();	
	loadingBar();	
			
    while(1)
    {	sei();
		//Se habilita que solo se puedan usar los botones de arriba, abajo y seleccionar
	    EIMSK= 0x07;
		
		//Despliega el menu de seleccion de los niveles
	    menu(&variablesJuego.posCursor,&variablesJuego.seleccionScreen);				
		//Se habilita que se puedan usar todos los botones		
		EIMSK= 0xFF;		
		
		rellenarCasillas(variablesJuego.tablero1,variablesJuego.posCursor,&variablesJuego);
		
		variablesJuego.inGame=True;
		DrawScore();
					
		while (endGame(variablesJuego.tablero1)==1 && variablesJuego.puntuacion>0 && variablesJuego.resetPushed==False)
		{
			glcd_putchar(42,variablesJuego.cursorPantalla.y,variablesJuego.cursorPantalla.x,0,2);
			_delay_ms(500);		
			glcd_putchar(variablesJuego.valorCasilla,variablesJuego.cursorPantalla.y,variablesJuego.cursorPantalla.x,0,2);		
			_delay_ms(500);
		}		
		cli ();
		
		if (variablesJuego.puntuacion==0 && endGame(variablesJuego.tablero1)==1) 
		{
			glcd_clear();
			_delay_ms(500);
			glcd_puts("You Have Lost",5,3,0,1,0);
			_delay_ms(500);
			glcd_puts("Puntuacion 0",5,5,0,1,0);
			_delay_ms(500);
		}	
		if 	(endGame(variablesJuego.tablero1)==0 ||(endGame(variablesJuego.tablero1)==0 && variablesJuego.puntuacion==0))
		{
			glcd_clear();
			_delay_ms(500);
			glcd_puts("You have Won",5,3,0,1,0);
			_delay_ms(500);
			glcd_puts("Puntuacion",5,5,0,1,0);
			_delay_ms(500);
			glcd_puts(itoa (variablesJuego.puntuacion,variablesJuego.puntuacion_pantalla,10),25,6,0,1,0);
			_delay_ms(700);
		}
		if(variablesJuego.resetPushed==True)
		{
			glcd_clear();
			_delay_ms(500);
			glcd_puts("You have Won",5,3,0,1,0);
			_delay_ms(500);
			glcd_puts("Puntuacion",5,5,0,1,0);
			_delay_ms(500);
			glcd_puts(itoa (variablesJuego.puntuacion,variablesJuego.puntuacion_pantalla,10),25,6,0,1,0);
			_delay_ms(1000);			
			
		}
						
		//Se reinicializan las variables
		ReiniciarJuego(&variablesJuego);
        //TODO:: Please write your application code 
		}    
}