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@3:7213eee4c093, 2017-04-14 (annotated)
- Committer:
- domkay97
- Date:
- Fri Apr 14 22:30:05 2017 +0000
- Revision:
- 3:7213eee4c093
- Parent:
- 2:6eebea9a6a86
- Child:
- 4:62dcc005f7a7
Moved functionality from main to operator;
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 | 3:7213eee4c093 | 40 | sprintf(buffer,"Score = %2d",score); |
domkay97 | 3:7213eee4c093 | 41 | lcd.printString(buffer,0,1); |
domkay97 | 3:7213eee4c093 | 42 | lcd.refresh(); |
domkay97 | 3:7213eee4c093 | 43 | pad.leds_off(); |
domkay97 | 3:7213eee4c093 | 44 | pad.led(4,1); |
domkay97 | 3:7213eee4c093 | 45 | pad.led(5,1); |
domkay97 | 3:7213eee4c093 | 46 | pad.led(6,1); |
domkay97 | 3:7213eee4c093 | 47 | } |
domkay97 | 3:7213eee4c093 | 48 | score = 0; |
domkay97 | 3:7213eee4c093 | 49 | } |