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