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:
- 9:54c620f7d736
- Parent:
- 8:93f18f1c1241
- Child:
- 10:e0e820636025
--- a/Operator.cpp Fri Apr 21 10:55:23 2017 +0000 +++ b/Operator.cpp Sun Apr 23 16:36:37 2017 +0000 @@ -18,10 +18,10 @@ ctrl.ledsOFF(); int instruction_val = random_instruction(display, lcd); //sets instruction_val as the random instruction from display - printf("MAIN instruction_val = %d\n", instruction_val); + printf("OPP:test_player instruction_val = %d\n", instruction_val); display.drawCircle(ctrl, lcd); //Draws circle, displays instruction and allows the circle to be drawn faster with time int button_val = ctrl.check_for_buttons(); //sets button_val as the instruction performed by the user - printf("MAIN button_val = %d\n", button_val); + printf("OPP:test_player button_val = %d\n", button_val); if (button_val == instruction_val) { //if the user performs the instruction correctly perform: @@ -55,14 +55,17 @@ void Operator::InCorrect(int next_player, Controller &ctrl) { + printf("OPP.Incorrect player = %d\n", next_player); ctrl.sound(200,1); myplayers[next_player].status = false; //set player to dead (false) } bool Operator::check_dead() { - - if (!myplayers[0].status && !myplayers[1].status) { + printf("OPP.check_dead P1 %d\n", myplayers[0].status); + printf("OPP.check_dead P2 %d\n", myplayers[1].status); + + if (!myplayers[0].status && !myplayers[1].status) { // if both players false then both dead = true return true; } else { return false; @@ -76,10 +79,10 @@ { int mynext_player = next_player; - + 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)) { + if ( (myplayers[next_player].score % 10 == 0) || (myplayers[next_player].status == false)) { //on 0, 10 etc swap player unless other player is dead myplayers[next_player].wait = display.get_wait(); //save speed lcd.clear(); @@ -90,43 +93,44 @@ if (next_player == 1 && myplayers[0].status) { //change to next player mynext_player = 0; } - - // if (mynext_player != next_player) { - char buff[14]; - display.put_wait(myplayers[mynext_player].wait); //put speed - sprintf(buff,"Player %d ",mynext_player+1); - lcd.printString(buff,3,2); - - lcd.refresh(); - lcd.printString("3",20,4); - ctrl.sound(50,1); - lcd.refresh(); - wait(1); - lcd.printString("2",20,4); - lcd.refresh(); - ctrl.sound(200,1); - wait(1); - lcd.printString("1",20,4); - lcd.refresh(); - ctrl.sound(300,1); - wait(1); - lcd.printString("0",20,4); - lcd.refresh(); - ctrl.sound(400,2); - wait(2); - // } + 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 } - - } return mynext_player; } +void Operator::DisplayNextPlayer(Controller &ctrl, N5110 &lcd, int thenext_player) +{ + printf("OPP.DisplayNextPlayer threnext_player %d\n", thenext_player); + char buff[14]; + sprintf(buff,"Player %d ",thenext_player+1); + lcd.printString(buff,20,2); + lcd.refresh(); + lcd.printString("3",40,4); + ctrl.sound(50,1); + lcd.refresh(); + wait(1); + lcd.printString("2",40,4); + lcd.refresh(); + ctrl.sound(200,1); + wait(1); + lcd.printString("1",40,4); + lcd.refresh(); + ctrl.sound(300,1); + wait(1); + lcd.printString("0",40,4); + lcd.refresh(); + ctrl.sound(400,2); + wait(2); +} + + void Operator::setup_players(int num_of_players) { - myplayers[0].wait = 0.3; myplayers[1].wait = 0.3; myplayers[0].status = true; @@ -149,10 +153,10 @@ while(ctrl.check_event(Controller::BACK_PRESSED) == false) { if (_num_players == 1) { - Assessment(lcd, myplayers[0].score); + Assessment(lcd, myplayers[0].score); //Display results for single player printf("OPP num of Players = %d\n", _num_players); } else { - MultiResults(lcd); + MultiResults(lcd); //display results for multiPlayer } ctrl.ledsOFF(); ctrl.led(4,1); @@ -177,19 +181,17 @@ lcd.printString("Amuteur",24,4); } else if (score < 30) { sprintf(buffer,"%2d",score); - lcd.printString("Semi-Pro",23,4); - } else if (score < 30) { - sprintf(buffer,"%2d",score); lcd.printString("Expert",26,4); } else if (score < 40) { sprintf(buffer,"%2d",score); lcd.printString("Professional",10,4); } else if (score < 50) { sprintf(buffer,"%2d",score); - lcd.printString("Legendary",16,4); + lcd.printString("World Class",14,4); } else { - sprintf(buffer,"%2d",score); - lcd.printString("World Class",14,4); + sprintf(buffer,"%2d",score); + lcd.printString("Legendary",16,4); + } lcd.printString(buffer,37,2); lcd.drawCircle(42,20,10,FILL_TRANSPARENT); @@ -207,8 +209,8 @@ lcd.printString(buffer,5,2); 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) {