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@6:9882809b0694, 2017-04-16 (annotated)
- Committer:
- domkay97
- Date:
- Sun Apr 16 13:45:15 2017 +0000
- Revision:
- 6:9882809b0694
- Parent:
- 5:84dfbfb17ef2
- Child:
- 7:5d9b9d0bc6e7
Tidying up and formatting
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 | 6:9882809b0694 | 15 | { |
domkay97 | 6:9882809b0694 | 16 | } |
domkay97 | 0:3097759acb02 | 17 | |
domkay97 | 0:3097759acb02 | 18 | |
domkay97 | 6:9882809b0694 | 19 | int Operator::random_instruction(Display &display, N5110 &lcd) |
domkay97 | 6:9882809b0694 | 20 | { |
domkay97 | 6:9882809b0694 | 21 | int ran = rand() % 7 + 1; |
domkay97 | 6:9882809b0694 | 22 | printf("OPP ran = %d\n", ran); |
domkay97 | 6:9882809b0694 | 23 | display.display_instruction(lcd, ran); |
domkay97 | 6:9882809b0694 | 24 | return ran; |
domkay97 | 6:9882809b0694 | 25 | } |
domkay97 | 5:84dfbfb17ef2 | 26 | |
domkay97 | 6:9882809b0694 | 27 | void Operator::Correct(Controller &pad) |
domkay97 | 6:9882809b0694 | 28 | { |
domkay97 | 6:9882809b0694 | 29 | score++; |
domkay97 | 6:9882809b0694 | 30 | printf("OPP score = %d\n", score); |
domkay97 | 6:9882809b0694 | 31 | pad.led(1,1); |
domkay97 | 6:9882809b0694 | 32 | pad.led(2,1); |
domkay97 | 6:9882809b0694 | 33 | pad.led(3,1); |
domkay97 | 6:9882809b0694 | 34 | pad.sound(100.0,0.2); |
domkay97 | 6:9882809b0694 | 35 | } |
domkay97 | 6:9882809b0694 | 36 | |
domkay97 | 6:9882809b0694 | 37 | void Operator::Game_Over(Controller &pad, N5110 &lcd) |
domkay97 | 6:9882809b0694 | 38 | { |
domkay97 | 6:9882809b0694 | 39 | pad.sound(700.0,1); |
domkay97 | 6:9882809b0694 | 40 | while(pad.check_event(Controller::BACK_PRESSED) == false) { |
domkay97 | 6:9882809b0694 | 41 | Assessment(lcd, score); |
domkay97 | 6:9882809b0694 | 42 | pad.ledsOFF(); |
domkay97 | 6:9882809b0694 | 43 | pad.led(4,1); |
domkay97 | 6:9882809b0694 | 44 | pad.led(5,1); |
domkay97 | 6:9882809b0694 | 45 | pad.led(6,1); |
domkay97 | 6:9882809b0694 | 46 | } |
domkay97 | 3:7213eee4c093 | 47 | score = 0; |
domkay97 | 6:9882809b0694 | 48 | } |
domkay97 | 5:84dfbfb17ef2 | 49 | |
domkay97 | 6:9882809b0694 | 50 | void Operator::Assessment(N5110 &lcd, int score) |
domkay97 | 6:9882809b0694 | 51 | { |
domkay97 | 6:9882809b0694 | 52 | printf("OPP.ASSESSMENT score = %d\n", score); |
domkay97 | 6:9882809b0694 | 53 | lcd.printString("Game Over",16,0); |
domkay97 | 6:9882809b0694 | 54 | char buffer[14]; |
domkay97 | 6:9882809b0694 | 55 | if (score < 10) { |
domkay97 | 6:9882809b0694 | 56 | sprintf(buffer,"0%d",score); |
domkay97 | 6:9882809b0694 | 57 | lcd.printString("Newbie",26,4); |
domkay97 | 6:9882809b0694 | 58 | } else if (score < 20) { |
domkay97 | 6:9882809b0694 | 59 | sprintf(buffer,"%2d",score); |
domkay97 | 6:9882809b0694 | 60 | lcd.printString("Amuteur",25,4); |
domkay97 | 6:9882809b0694 | 61 | } else if (score < 30) { |
domkay97 | 6:9882809b0694 | 62 | sprintf(buffer,"%2d",score); |
domkay97 | 6:9882809b0694 | 63 | lcd.printString("Semi-Pro",24,4); |
domkay97 | 6:9882809b0694 | 64 | } else if (score < 30) { |
domkay97 | 6:9882809b0694 | 65 | sprintf(buffer,"%2d",score); |
domkay97 | 6:9882809b0694 | 66 | lcd.printString("Expert",15,4); |
domkay97 | 6:9882809b0694 | 67 | } else if (score < 40) { |
domkay97 | 6:9882809b0694 | 68 | sprintf(buffer,"%2d",score); |
domkay97 | 6:9882809b0694 | 69 | lcd.printString("Professional",14,4); |
domkay97 | 6:9882809b0694 | 70 | } else if (score < 50) { |
domkay97 | 6:9882809b0694 | 71 | sprintf(buffer,"%2d",score); |
domkay97 | 6:9882809b0694 | 72 | lcd.printString("Legendary",16,4); |
domkay97 | 6:9882809b0694 | 73 | } else { |
domkay97 | 6:9882809b0694 | 74 | sprintf(buffer,"%2d",score); |
domkay97 | 6:9882809b0694 | 75 | lcd.printString("World Class",15,4); |
domkay97 | 6:9882809b0694 | 76 | } |
domkay97 | 6:9882809b0694 | 77 | lcd.printString(buffer,37,2); |
domkay97 | 6:9882809b0694 | 78 | lcd.drawCircle(42,20,10,FILL_TRANSPARENT); |
domkay97 | 6:9882809b0694 | 79 | lcd.refresh(); |
domkay97 | 3:7213eee4c093 | 80 | } |