Snake game on nokia N5110 LCD

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Snakelib.h"
00003 #include "Helper.h"
00004 Serial PC (USBTX, USBRX);
00005 Ticker T;
00006 
00007 //Very important to connect! Snakelib class parametters from N5110 lcd (VCC,SCE, RST,D/C, MOSI,SCLK,LED) and the last 3 from joystick
00008 
00009 Snakelib Snake (PTB2, PTD0, PTB9, PTB3, PTD2, PTD1, PTD0, PTB11, PTC11, PTC10);
00010 void Start()
00011     {
00012         if (!PC.readable()) return;
00013                 char C = PC.getc();
00014         while (!IsOurChar (C)) C = PC.getc();
00015         C = ToUpper (C);
00016         static char Buff[4] = "000"; 
00017         if (C == 'B' || C == 'Z' || C == 'H') 
00018             {
00019                 int N = -7;
00020                 if (C == 'B') //B01 - B10
00021                     {
00022                         Buff[0] = PC.getc();
00023                         Buff[1] = PC.getc();
00024                         N = ToInt (Buff);
00025                         if (N == -7) return;
00026                         Snake.SetSnakeSpeed (N);
00027                         PC.printf ("\nSnake speed changed to %d\n", N);
00028                         return;
00029                     }
00030                 Buff[0] = PC.getc();
00031                 Buff[1] = 0;
00032                 if ((N = ToInt (Buff)) == -7) return;
00033                 if (C == 'Z') {Snake.SetSnakeType (N); PC.printf ("\nSnake type changed to %d\n", N);}
00034                 else {Snake.SetFoodType (N); PC.printf ("\nSnake food changed to %d\n", N);}
00035             }
00036         else if (C == 'P') 
00037             {
00038                 if (Snake.Paused()) Snake.ResumeGame(), PC.printf ("\nContinuing...\n");
00039                 else Snake.PauseGame(), PC.printf ("\nPause...\n");
00040             }
00041         else if (C == 'R') Snake.Restart(), PC.printf ("\nRestarted!\n");
00042     }
00043 int main ()
00044     {
00045         
00046         PC.printf ("\nManual:\n\n-P -> Pause/Continue\n-Z# -> Change snake type. Allowed values Z1-Z6\n");
00047         PC.printf ("-H# -> Change snake food. Allowed values H1-H5\n-R -> Restart game\n");
00048         PC.printf ("-B# -> Change snake speed. Allowed B01-B10\n");
00049         PC.printf ("\nTemp settings: B6, Z1, H1\nTo start playing, use joystick.\n\n \n\n");
00050         T.attach (&Start, 0.01);
00051         Snake.START();
00052         while (7);
00053     }