This class is the engine of the program. It encapsulates all the methods to do with managing scores, commands and player states(dead/alive).
Operator.cpp@4:62dcc005f7a7, 2017-04-14 (annotated)
- Committer:
- domkay97
- Date:
- Fri Apr 14 23:43:24 2017 +0000
- Revision:
- 4:62dcc005f7a7
- Parent:
- 3:7213eee4c093
- Child:
- 5:84dfbfb17ef2
Added score levels informing user of performance
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:0f98beb0993b | 17 | int Operator::read_input(Controller &pad) { |
domkay97 | 0:3097759acb02 | 18 | |
domkay97 | 0:3097759acb02 | 19 | return(pad.check_for_buttons()); |
domkay97 | 0:3097759acb02 | 20 | } |
domkay97 | 0:3097759acb02 | 21 | |
domkay97 | 0:3097759acb02 | 22 | |
domkay97 | 1:0f98beb0993b | 23 | int Operator::random_instruction(Display &display, N5110 &lcd) { |
domkay97 | 2:6eebea9a6a86 | 24 | int ran = rand() % 7 + 1; |
domkay97 | 1:0f98beb0993b | 25 | display.display_instruction(lcd, ran); |
domkay97 | 1:0f98beb0993b | 26 | return ran; |
domkay97 | 1:0f98beb0993b | 27 | } |
domkay97 | 1:0f98beb0993b | 28 | |
domkay97 | 3:7213eee4c093 | 29 | void Operator::Correct(Controller &pad) { |
domkay97 | 3:7213eee4c093 | 30 | score++; |
domkay97 | 3:7213eee4c093 | 31 | pad.led(1,1); |
domkay97 | 3:7213eee4c093 | 32 | pad.led(2,1); |
domkay97 | 3:7213eee4c093 | 33 | pad.led(3,1); |
domkay97 | 3:7213eee4c093 | 34 | pad.tone(100.0,0.2); |
domkay97 | 3:7213eee4c093 | 35 | } |
domkay97 | 3:7213eee4c093 | 36 | void Operator::Game_Over(Controller &pad, N5110 &lcd) { |
domkay97 | 3:7213eee4c093 | 37 | pad.tone(700.0,1); |
domkay97 | 3:7213eee4c093 | 38 | while(pad.check_event(Controller::BACK_PRESSED) == false) { |
domkay97 | 3:7213eee4c093 | 39 | char buffer[14]; |
domkay97 | 4:62dcc005f7a7 | 40 | if (score < 10) { |
domkay97 | 4:62dcc005f7a7 | 41 | sprintf(buffer,"0%d",score); |
domkay97 | 4:62dcc005f7a7 | 42 | lcd.printString("Newbie",26,4); |
domkay97 | 4:62dcc005f7a7 | 43 | } |
domkay97 | 4:62dcc005f7a7 | 44 | else if (score < 20) { |
domkay97 | 4:62dcc005f7a7 | 45 | sprintf(buffer,"%2d",score); |
domkay97 | 4:62dcc005f7a7 | 46 | lcd.printString("Rookie",26,4); } |
domkay97 | 4:62dcc005f7a7 | 47 | else if (score < 30) { |
domkay97 | 4:62dcc005f7a7 | 48 | sprintf(buffer,"%2d",score); |
domkay97 | 4:62dcc005f7a7 | 49 | lcd.printString("Semi-Pro",24,4); } |
domkay97 | 4:62dcc005f7a7 | 50 | else if (score < 30) { |
domkay97 | 4:62dcc005f7a7 | 51 | sprintf(buffer,"%2d",score); |
domkay97 | 4:62dcc005f7a7 | 52 | lcd.printString("Professional",20,4); } |
domkay97 | 4:62dcc005f7a7 | 53 | else if (score < 40) { |
domkay97 | 4:62dcc005f7a7 | 54 | sprintf(buffer,"%2d",score); |
domkay97 | 4:62dcc005f7a7 | 55 | lcd.printString("World Class",20,4); } |
domkay97 | 4:62dcc005f7a7 | 56 | else { |
domkay97 | 4:62dcc005f7a7 | 57 | sprintf(buffer,"%2d",score); |
domkay97 | 4:62dcc005f7a7 | 58 | lcd.printString("Legendary",22,4); } |
domkay97 | 4:62dcc005f7a7 | 59 | lcd.printString(buffer,37,2); |
domkay97 | 4:62dcc005f7a7 | 60 | lcd.drawCircle(42,20,10,FILL_TRANSPARENT); |
domkay97 | 3:7213eee4c093 | 61 | lcd.refresh(); |
domkay97 | 3:7213eee4c093 | 62 | pad.leds_off(); |
domkay97 | 3:7213eee4c093 | 63 | pad.led(4,1); |
domkay97 | 3:7213eee4c093 | 64 | pad.led(5,1); |
domkay97 | 3:7213eee4c093 | 65 | pad.led(6,1); |
domkay97 | 3:7213eee4c093 | 66 | } |
domkay97 | 3:7213eee4c093 | 67 | score = 0; |
domkay97 | 3:7213eee4c093 | 68 | } |