
Labyrinth of the Minotaur A simple roguelike/RPG using a nokia 5110 screen
Dependencies: N5110 PowerControl mbed
Revision 24:4c4467971c91, committed 2015-05-08
- Comitter:
- ThomasBGill
- Date:
- Fri May 08 11:16:54 2015 +0000
- Parent:
- 23:1b8b1d043403
- Child:
- 25:4d9841e579e2
- Commit message:
- Pin detect library added
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Fri May 08 11:16:54 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- a/WorldBuilder/WorldBuilder.cpp Thu May 07 17:04:22 2015 +0000 +++ b/WorldBuilder/WorldBuilder.cpp Fri May 08 11:16:54 2015 +0000 @@ -315,7 +315,7 @@ void World() { Walls(); - if(level == 5) { + if(level%5 == 0) { LabyrinthBuilder(); } else { DungeonBuilder();
--- a/main.cpp Thu May 07 17:04:22 2015 +0000 +++ b/main.cpp Fri May 08 11:16:54 2015 +0000 @@ -3,15 +3,16 @@ #include "PowerControl/EthernetPowerControl.h" #include "WorldBuilder.h" #include "Graphics.h" +#include "PinDetect.h" // vcc sce rst dc mosi clk led N5110 lcd(p5, p6, p7, p8, p11, p13, p21); -InterruptIn Act(p22); -InterruptIn Start(p23); -InterruptIn Up(p24); -InterruptIn Down(p25); -InterruptIn Left(p26); -InterruptIn Right(p27); +PinDetect Act(p22); +PinDetect Start(p23); +PinDetect Up(p24); +PinDetect Down(p25); +PinDetect Left(p26); +PinDetect Right(p27); AnalogIn Noise(p19); #define USR_POWERDOWN (0x104) @@ -96,6 +97,9 @@ int HScore1; int HScore2; int HScore3; +int HScore4; + +bool BossFight = false; //Power Saving int semihost_powerdown() @@ -154,15 +158,17 @@ fprintf(fp,"%d\r\n",HScore1); // print score to file fprintf(fp,"%d\r\n",HScore2); // print score to file fprintf(fp,"%d\r\n",HScore3); // print score to file + fprintf(fp,"%d\r\n",HScore4); // print score to file fclose(fp); // close file } void readDataFromFile() { - FILE *fp = fopen("/local/highscore.txt", "w"); // open 'highscore.txt' for writing + FILE *fp = fopen("/local/highscore.txt", "r"); // open 'highscore.txt' for writing fscanf(fp,"%d", &HScore1); // read score from file and save to int fscanf(fp,"%d", &HScore2); // read score from file and save to int fscanf(fp,"%d", &HScore3); // read score from file and save to int + fscanf(fp,"%d", &HScore4); // read score from file and save to int fclose(fp); // close file } @@ -171,14 +177,19 @@ readDataFromFile(); if(score >= HScore1) { + HScore4 = HScore3; HScore3 = HScore2; HScore2 = HScore1; HScore1 = score; } else if(score >= HScore2) { + HScore4 = HScore3; HScore3 = HScore2; HScore2 = score; - } else if(score > HScore3) { + } else if(score >= HScore3) { + HScore4 = HScore3; HScore3 = score; + } else if(score > HScore4) { + HScore4 = score; } writeDataToFile(); @@ -235,8 +246,7 @@ lcd.printString("Options", 6, 3); lcd.refresh(); Sleep(); - } - if (menu == 1) { + } else if (menu == 1) { lcd.printString("New Game", 6, 1); lcd.printString("High Scores <", 6, 2); lcd.printString("Options", 6, 3); @@ -331,7 +341,9 @@ { while (1) { - level++; + //level++; + + level = 5; score = score + 100; @@ -339,7 +351,7 @@ LevelScreen(); - //RevealMap(); //Uncomment for debugging to view map + RevealMap(); //Uncomment for debugging to view map while (1) { @@ -355,6 +367,11 @@ if (px == exx && py == exy) { + if(level%5 == 0) { + BossFight = true; + Fight(); + } + break; } @@ -455,13 +472,30 @@ void Fight() { - int m = rand() % (level + 1); + int m; + + lcd.clear(); + + if(BossFight) { + BossFight = false; + + m = 5; //Monster is a minotaur + + lcd.printString("BOSS!", 30, 2); + } else { + + int mr = level + 1; + + if (mr > 4) { + mr = 4; + lcd.printString("FIGHT!", 24, 2); + } + + m = rand() % mr; + } int mh = EnemyList[m].EHealth; - lcd.clear(); - lcd.printString("FIGHT!", 24, 2); - for (int i = 0; i<5; i++) { lcd.inverseMode(); lcd.refresh(); @@ -1064,6 +1098,8 @@ HighScoreCheck(); + //readDataFromFile(); + char buffer1[14]; int write = sprintf(buffer1, "1. %d", HScore1); @@ -1073,11 +1109,15 @@ char buffer3[14]; write = sprintf(buffer3, "3. %d", HScore3); + char buffer4[14]; + write = sprintf(buffer4, "4. %d", HScore4); + lcd.clear(); lcd.printString("High Scores", 6, 0); lcd.printString(buffer1, 6, 2); lcd.printString(buffer2, 6, 3); lcd.printString(buffer3, 6, 4); + lcd.printString(buffer4, 6, 5); lcd.refresh(); wait(1.0); Sleep();