Completed Snake Program

Dependencies:   N5110 PinDetect PowerControl mbed

Fork of DocTest by Craig Evans

Files at this revision

API Documentation at this revision

Comitter:
MBirney
Date:
Wed Apr 08 20:00:37 2015 +0000
Parent:
1:6fc14cd8ccf1
Child:
3:478b090b7e1b
Commit message:
Splash screen and working on switch statement for difficulty menu

Changed in this revision

N5110.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/N5110.lib	Wed Apr 08 20:00:37 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/eencae/code/N5110/#780a542d5f8b
--- a/main.cpp	Wed Mar 11 16:03:08 2015 +0000
+++ b/main.cpp	Wed Apr 08 20:00:37 2015 +0000
@@ -1,25 +1,156 @@
-/**
-@file main.cpp
+#include "mbed.h"
+#include "N5110.h"
+
+//    VCC,SCE,RST,D/C,MOSI,SCLK,LED
+N5110 lcd(p7,p8,p9,p10,p11,p13,p21);
+//d
 
-@brief Program implementation
+// Can also power (VCC) directly from VOUT (3.3 V) -
+// Can give better performance due to current limitation from GPIO pin
+enum Difficulty {
+    EASY,
+    MEDIUM,
+    HARD,
+};
+int gameSpeed;//change depending on difficulty selected
 
-*/
-#include "main.h"
+Difficulty currentDifficulty =EASY;
 
-int main() {
-    
-    /// flash LED in infinite loop
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
-    }
+void displaySplash()
+{
+    // these are default settings so not strictly needed
+    lcd.inverseMode();      // normal colour mode
+    lcd.setBrightness(0.5); // put LED backlight on 50%
+
+    //Draw S
+    lcd.drawRect(28,10,2,5,1);
+    lcd.drawRect(15,10,15,2,1);
+    lcd.drawRect(15,10,2,10,1);
+    lcd.drawRect(15,20,15,2,1);
+    lcd.drawRect(28,20,2,10,1);
+    lcd.drawRect(15,28,15,2,1);
+    lcd.drawRect(15,25,2,3,1);
+
+    lcd.printString("NAKE ",34,3);
+    lcd.printString("By M.Birney",10,5);
+    lcd.drawRect(10,5,65,30,0);
+
+    // need to refresh display after setting pixels
+
+    lcd.refresh();
 }
 
 
-int sum(int a, int b) {
-    
-    /// calculate the sum of the two arguments and return
-    return a + b;
+
+void easySelected() // display when easy is selected
+{
+    lcd.clear();
+    lcd.printString("Please Select",2,0);
+    lcd.printString("Difficulty:",2,1);
+    lcd.printString("Easy",20,3);
+    lcd.printString("Medium",20,4);
+    lcd.printString("Hard",20,5);
+    lcd.refresh();
+    lcd.drawCircle(10,27,2,1);
+    lcd.drawCircle(10,35,2,0);
+    lcd.drawCircle(10,43,2,0);
+
+    gameSpeed= 1.0;
+}
+void mediumSelected() // display when medium is selected
+{
+    lcd.clear();
+    lcd.printString("Please Select",2,0);
+    lcd.printString("Difficulty:",2,1);
+    lcd.printString("Easy",20,3);
+    lcd.printString("Medium",20,4);
+    lcd.printString("Hard",20,5);
+    lcd.refresh();
+    lcd.drawCircle(10,27,2,0);
+    lcd.drawCircle(10,35,2,1);
+    lcd.drawCircle(10,43,2,0);
+    gameSpeed=1.0/4;
+}
+
+void hardSelected() // display when hard is selected
+{
+    lcd.clear();
+    lcd.printString("Please Select",2,0);
+    lcd.printString("Difficulty:",2,1);
+    lcd.printString("Easy",20,3);
+    lcd.printString("Medium",20,4);
+    lcd.printString("Hard",20,5);
+    lcd.refresh();
+    lcd.drawCircle(10,27,2,0);
+    lcd.drawCircle(10,35,2,0);
+    lcd.drawCircle(10,43,2,1);
+    gameSpeed=1.0/8;
+}
+
+
+
+int main()
+{
+    // first need to initialise display
+    lcd.init();
+    displaySplash();
+    wait(1);
+
+    easySelected();
+    wait(2);
+    mediumSelected();
+    wait(2);
+    hardSelected();
+
+    while(1) {
+
+        switch(currentDifficulty) {
+            case EASY:
+
+                switch (joystick.direction)
+
+                case UP:
+                hardSelected;
+                break;
+
+
+            case DOWN:
+                mediumSelected;
+                break;
+
+                break;
+
+
+            case MEDIUM:
+
+                switch (joystick.direction)
+
+                case UP:
+                easySelected;
+                break;
+
+
+            case DOWN:
+                hardSelected;
+                break;
+
+
+
+                break;
+            case HARD:
+                switch (joystick.direction)
+
+                case UP:
+                mediumSelected;
+                break;
+
+
+            case DOWN:
+                easySelected;
+                break;
+                break;
+        }
+
+
+    }
 }
\ No newline at end of file
--- a/main.h	Wed Mar 11 16:03:08 2015 +0000
+++ b/main.h	Wed Apr 08 20:00:37 2015 +0000
@@ -1,33 +1,15 @@
 /**
 @file main.h
 @brief Header file containing functions prototypes, defines and global variables.
-@brief Shows examples of creating Doxygen documentation.
+@brief Game of Snake
 @brief Revision 1.0.
-@author Craig A. Evans
-@date   March 2015
+@author Michael Birney 
+@date   April 2015
 */
 
-#ifndef MAIN_H
-#define MAIN_H
 
-#define PI 3.14159265359
-
-#include "mbed.h"
-
-/**  
-@namespace myled
-@brief GPIO output for status LED
+/** 
+Displays a Snake Logo Splash Screen 
 */
-DigitalOut myled(LED1); 
-
-int printFlag; /*!< print flag set in ISR */
+void displaySplash();
 
-/**
-Adds up two integer variables
-@param a - integer to add
-@param b - integer to add
-@returns the sum of a and b
-*/
-int sum(int a, int b);
-
-#endif