This class is the engine of the program. It encapsulates all the methods to do with managing scores, commands and player states(dead/alive).

Committer:
domkay97
Date:
Sat Apr 15 15:39:31 2017 +0000
Revision:
5:84dfbfb17ef2
Parent:
4:62dcc005f7a7
Child:
6:9882809b0694
Tidying up code for leveling with assessment methord

Who changed what in which revision?

UserRevisionLine numberNew contents of line
domkay97 0:3097759acb02 1 #include "Operator.h"
domkay97 0:3097759acb02 2
domkay97 0:3097759acb02 3 Operator::Operator()
domkay97 0:3097759acb02 4 {
domkay97 0:3097759acb02 5
domkay97 0:3097759acb02 6 }
domkay97 0:3097759acb02 7
domkay97 0:3097759acb02 8 Operator::~Operator()
domkay97 0:3097759acb02 9 {
domkay97 0:3097759acb02 10
domkay97 0:3097759acb02 11 }
domkay97 0:3097759acb02 12
domkay97 0:3097759acb02 13
domkay97 0:3097759acb02 14 void Operator::init()
domkay97 3:7213eee4c093 15 {
domkay97 0:3097759acb02 16 }
domkay97 5:84dfbfb17ef2 17
domkay97 1:0f98beb0993b 18 int Operator::read_input(Controller &pad) {
domkay97 0:3097759acb02 19
domkay97 0:3097759acb02 20 return(pad.check_for_buttons());
domkay97 0:3097759acb02 21 }
domkay97 0:3097759acb02 22
domkay97 0:3097759acb02 23
domkay97 1:0f98beb0993b 24 int Operator::random_instruction(Display &display, N5110 &lcd) {
domkay97 2:6eebea9a6a86 25 int ran = rand() % 7 + 1;
domkay97 1:0f98beb0993b 26 display.display_instruction(lcd, ran);
domkay97 1:0f98beb0993b 27 return ran;
domkay97 1:0f98beb0993b 28 }
domkay97 1:0f98beb0993b 29
domkay97 3:7213eee4c093 30 void Operator::Correct(Controller &pad) {
domkay97 3:7213eee4c093 31 score++;
domkay97 3:7213eee4c093 32 pad.led(1,1);
domkay97 3:7213eee4c093 33 pad.led(2,1);
domkay97 3:7213eee4c093 34 pad.led(3,1);
domkay97 3:7213eee4c093 35 pad.tone(100.0,0.2);
domkay97 3:7213eee4c093 36 }
domkay97 5:84dfbfb17ef2 37
domkay97 3:7213eee4c093 38 void Operator::Game_Over(Controller &pad, N5110 &lcd) {
domkay97 3:7213eee4c093 39 pad.tone(700.0,1);
domkay97 5:84dfbfb17ef2 40 while(pad.check_event(Controller::BACK_PRESSED) == false) {
domkay97 5:84dfbfb17ef2 41 Assessment(lcd, score);
domkay97 5:84dfbfb17ef2 42 pad.leds_off();
domkay97 5:84dfbfb17ef2 43 pad.led(4,1);
domkay97 5:84dfbfb17ef2 44 pad.led(5,1);
domkay97 5:84dfbfb17ef2 45 pad.led(6,1);
domkay97 3:7213eee4c093 46 }
domkay97 3:7213eee4c093 47 score = 0;
domkay97 5:84dfbfb17ef2 48 }
domkay97 5:84dfbfb17ef2 49
domkay97 5:84dfbfb17ef2 50 void Operator::Assessment(N5110 &lcd, int score) {
domkay97 5:84dfbfb17ef2 51 lcd.printString("Game Over",16,0);
domkay97 5:84dfbfb17ef2 52 char buffer[14];
domkay97 5:84dfbfb17ef2 53 if (score < 10) {
domkay97 5:84dfbfb17ef2 54 sprintf(buffer,"0%d",score);
domkay97 5:84dfbfb17ef2 55 lcd.printString("Newbie",26,4); }
domkay97 5:84dfbfb17ef2 56 else if (score < 20) {
domkay97 5:84dfbfb17ef2 57 sprintf(buffer,"%2d",score);
domkay97 5:84dfbfb17ef2 58 lcd.printString("Amuteur",25,4); }
domkay97 5:84dfbfb17ef2 59 else if (score < 30) {
domkay97 5:84dfbfb17ef2 60 sprintf(buffer,"%2d",score);
domkay97 5:84dfbfb17ef2 61 lcd.printString("Semi-Pro",24,4); }
domkay97 5:84dfbfb17ef2 62 else if (score < 30) {
domkay97 5:84dfbfb17ef2 63 sprintf(buffer,"%2d",score);
domkay97 5:84dfbfb17ef2 64 lcd.printString("Professional",20,4); }
domkay97 5:84dfbfb17ef2 65 else if (score < 40) {
domkay97 5:84dfbfb17ef2 66 sprintf(buffer,"%2d",score);
domkay97 5:84dfbfb17ef2 67 lcd.printString("Expert",26,4); }
domkay97 5:84dfbfb17ef2 68 else if (score < 50) {
domkay97 5:84dfbfb17ef2 69 sprintf(buffer,"%2d",score);
domkay97 5:84dfbfb17ef2 70 lcd.printString("Legendary",20,4); }
domkay97 5:84dfbfb17ef2 71 else {
domkay97 5:84dfbfb17ef2 72 sprintf(buffer,"%2d",score);
domkay97 5:84dfbfb17ef2 73 lcd.printString("World Class",18,4); }
domkay97 5:84dfbfb17ef2 74 lcd.printString(buffer,37,2);
domkay97 5:84dfbfb17ef2 75 lcd.drawCircle(42,20,10,FILL_TRANSPARENT);
domkay97 5:84dfbfb17ef2 76 lcd.refresh();
domkay97 3:7213eee4c093 77 }