int annaseed() { lcd_write_ctrl(LCD_CLEAR); lcd_write_str("***Battleship***", 0); lcd_write_str("****************",1); int nappiylos = 0; int nappipohjassa = 0; int seed = 0; while(!(nappipohjassa && nappiylos)) { if(ButtonCenter){ nappipohjassa = 1; seed = seed +6; } else { if(nappipohjassa == 1){ nappiylos = 1; seed = seed + 4; } } seed++; if (seed > 542) seed = 0; } lcd_write_ctrl(LCD_CLEAR); _delay_ms(250); // Aikaa reagoida pelin alkamiseen return seed; }
void lcd_screen(char* firsth_row_text,char* second_row_text) { cli(); lcd_clear(); lcd_goto_xy(0,0); lcd_write_str(firsth_row_text); lcd_goto_xy(0,1); lcd_write_str(second_row_text); sei(); }
/* * Writes an integer number (positive/negative) to the LCD. * Returning 1 if no errors occurred, otherwise 0. Nothing is actually tested * since lcd_write() is incapable of checking possible error on the LCD shield. * (R/W pin is not connected!) */ int lcd_write_int(int32_t number) { /* converted string to LCD */ char digit_str[20]; /* 20 characters is probably excessive? */ /* convert integer to string */ sprintf(digit_str, "%d", number); /* write string to LCD, return result from execution */ return lcd_write_str(digit_str); }
static void write_to_lcd(void) { static char * lcd_str = "hello"; lcd_goto(0, 0); lcd_write_str(lcd_str); }
int main(void) { /*Valikot*/ init(); int vaikeus = 25; // Oletus = helppo char merkki = 0b00111110; int seed = annaseed(); char y = 0; // valikko muuttujia char z = 0; while (1) { y = 0; z = 0; lcd_write_ctrl(LCD_CLEAR); lcd_write_str(" Pelaa nyt", 0); //Main menu lcd_write_str(" Vaikeustaso", 1); while (1) { lcd_gotoxy(0,y); lcd_write_data(' '); if (ButtonDown && y < 1) y++; if (ButtonUp && y > 0) y--; if (ButtonCenter) { while (ButtonCenter) // ei poistuta funktiosta nappipohjassa _delay_ms(50); break; } lcd_gotoxy(0,y); lcd_write_data(merkki); _delay_ms(50); } while (y == 0) { // Aloita peli switch (pelifunktio(vaikeus, seed)) { case 0: // Voitto lcd_write_ctrl(LCD_CLEAR); lcd_write_str("*****VOITTO*****", 0); while (ButtonCenter) // Odotetaan että nappi päästetään irti _delay_ms(50); nyancat(); break; case 1: // Häviö lcd_write_ctrl(LCD_CLEAR); lcd_write_str("*****HAVIO*****", 0); havio(); _delay_ms(500); while (!(ButtonCenter)) // Voitossa tätä ei tarvita koska nyan huolehtii napin päästön _delay_ms(50); while (ButtonCenter) _delay_ms(50); break; case 2: continue; } lcd_write_ctrl(LCD_CLEAR); lcd_write_str(" Uusi peli", 0); lcd_write_str(" Valikkoon", 1); while (1) { lcd_gotoxy(0, z); lcd_write_data(' '); if (ButtonDown && z < 1) z++; if (ButtonUp && z > 0) z--; if (ButtonCenter) { while (ButtonCenter) _delay_ms(50); break; } lcd_gotoxy(0,z); lcd_write_data(merkki); _delay_ms(50); } if (z == 0) { y = 0; seed++; } else y = 5; //hypätään seuraavien ehtojen yli } if (y == 1) { vaikeus = 0; lcd_write_ctrl(LCD_CLEAR); lcd_write_str(" Helppo (25)", 0); lcd_write_str(" Vaikea (10)", 1); while (1) { lcd_gotoxy(0, vaikeus); lcd_write_data(' '); if (ButtonDown && vaikeus < 1) vaikeus++; if (ButtonUp && vaikeus > 0) vaikeus--; if (ButtonCenter) { while (ButtonCenter) _delay_ms(50); break; } lcd_gotoxy(0,vaikeus); lcd_write_data(merkki); _delay_ms(50); } if (vaikeus == 0) vaikeus = 25; else // Jos lisätään tasoja muuta ifiksi vaikeus = 10; } } }