This class is the engine of the program. It encapsulates all the methods to do with managing scores, commands and player states(dead/alive).
Diff: Operator.cpp
- Revision:
- 11:48190450b7e5
- Parent:
- 10:e0e820636025
- Child:
- 12:bdaf4e1d615e
diff -r e0e820636025 -r 48190450b7e5 Operator.cpp --- a/Operator.cpp Mon Apr 24 09:47:05 2017 +0000 +++ b/Operator.cpp Mon May 01 17:04:21 2017 +0000 @@ -41,19 +41,19 @@ return ran; } -void Operator::Correct(int next_player, Controller &ctrl) +void Operator::correct(int next_player, Controller &ctrl) { - myplayers[next_player].score++; //increment score for player - score = myplayers[next_player].score; - double freq_change = score*20; + myplayers[next_player]._score++; //increment score for player + _score = myplayers[next_player]._score; + double _freqChange = _score*20; //printf("OPP score = %d\n", score); ctrl.led(1,1); ctrl.led(2,1); ctrl.led(3,1); - ctrl.sound(50.0 + freq_change,0.2); //update speed of reaction + ctrl.sound(50.0 + _freqChange,0.2); //update speed of reaction } -void Operator::InCorrect(int next_player, Controller &ctrl) +void Operator::inCorrect(int next_player, Controller &ctrl) { //printf("OPP.Incorrect player = %d\n", next_player); ctrl.sound(200,1); @@ -82,7 +82,7 @@ //printf("OPP.check_next_player(1) next_player %d\n", mynext_player); if (_num_players > 1) { - if ( (myplayers[next_player].score % 10 == 0) || (myplayers[next_player].status == false)) { //on 0, 10 etc swap player unless other player is dead + if ( (myplayers[next_player]._score % 10 == 0) || (myplayers[next_player].status == false)) { //on 0, 10, 20... etc swap player unless other player is dead myplayers[next_player].wait = display.get_wait(); //save speed lcd.clear(); @@ -95,14 +95,14 @@ } //printf("OPP.check_next_player(2) next_player %d\n", mynext_player); display.put_wait(myplayers[mynext_player].wait); //put speed - DisplayNextPlayer(ctrl,lcd,mynext_player); //Display next player + _displayNextPlayer(ctrl,lcd,mynext_player); //Display next player } } return mynext_player; } -void Operator::DisplayNextPlayer(Controller &ctrl, N5110 &lcd, int thenext_player) +void Operator::_displayNextPlayer(Controller &ctrl, N5110 &lcd, int thenext_player) { printf("OPP.DisplayNextPlayer threnext_player %d\n", thenext_player); char buff[14]; @@ -134,8 +134,8 @@ myplayers[0].wait = 0.3; myplayers[1].wait = 0.3; myplayers[0].status = true; - myplayers[0].score = 0; - myplayers[1].score = 0; + myplayers[0]._score = 0; + myplayers[1]._score = 0; if (num_of_players == 1) { myplayers[1].status = false; @@ -147,16 +147,16 @@ -void Operator::Game_Over(Controller &ctrl, N5110 &lcd) +void Operator::gameOver(Controller &ctrl, N5110 &lcd) { ctrl.init(); //reset flags while(ctrl.check_event(Controller::BACK_PRESSED) == false) { if (_num_players == 1) { - Assessment(lcd, myplayers[0].score); //Display results for single player + _assessment(lcd, myplayers[0]._score); //Display results for single player //printf("OPP num of Players = %d\n", _num_players); } else { - MultiResults(lcd); //display results for multiPlayer + _multiResults(lcd); //display results for multiPlayer } ctrl.ledsOFF(); ctrl.led(4,1); @@ -165,31 +165,31 @@ } setup_players(1); - score = 0; + _score = 0; } -void Operator::Assessment(N5110 &lcd, int score) +void Operator::_assessment(N5110 &lcd, int _score) { - //printf("OPP.ASSESSMENT score = %d\n", score); + //printf("OPP.ASSESSMENT score = %d\n", _score); lcd.printString("Game Over",16,0); char buffer[14]; - if (score < 10) { - sprintf(buffer,"0%d",score); + if (_score < 10) { + sprintf(buffer,"0%d",_score); lcd.printString("Newbie",26,4); - } else if (score < 20) { - sprintf(buffer,"%2d",score); + } else if (_score < 20) { + sprintf(buffer,"%2d",_score); lcd.printString("Amuteur",24,4); - } else if (score < 30) { - sprintf(buffer,"%2d",score); + } else if (_score < 30) { + sprintf(buffer,"%2d",_score); lcd.printString("Expert",26,4); - } else if (score < 40) { - sprintf(buffer,"%2d",score); + } else if (_score < 40) { + sprintf(buffer,"%2d",_score); lcd.printString("Professional",10,4); - } else if (score < 50) { - sprintf(buffer,"%2d",score); + } else if (_score < 50) { + sprintf(buffer,"%2d",_score); lcd.printString("World Class",14,4); } else { - sprintf(buffer,"%2d",score); + sprintf(buffer,"%2d",_score); lcd.printString("Legendary",16,4); } @@ -199,18 +199,18 @@ } -void Operator::MultiResults(N5110 &lcd) +void Operator::_multiResults(N5110 &lcd) { //printf("OPP.MULTIRESULTS\n"); lcd.clear(); lcd.printString("Game Over",16,0); char buffer[14]; - sprintf(buffer,"Player 1 - %d",myplayers[0].score); + sprintf(buffer,"Player 1 - %d",myplayers[0]._score); lcd.printString(buffer,5,2); - sprintf(buffer,"Player 2 - %d",myplayers[1].score); + sprintf(buffer,"Player 2 - %d",myplayers[1]._score); lcd.printString(buffer,5,3); - int score1 = myplayers[0].score; - int score2 = myplayers[1].score; + int score1 = myplayers[0]._score; + int score2 = myplayers[1]._score; if (score1 > score2) {