You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.9 KiB
C++
99 lines
2.9 KiB
C++
6 years ago
|
#include <vector>
|
||
|
#include <sstream>
|
||
|
#include "result_screen.h"
|
||
|
|
||
|
using std::string;
|
||
|
using std::vector;
|
||
|
using std::ostringstream;
|
||
|
|
||
6 years ago
|
ResultScreen::ResultScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, int _score, int _difficulty, State _prev_state) {
|
||
6 years ago
|
score = _score;
|
||
|
difficulty = _difficulty;
|
||
6 years ago
|
prev_state = _prev_state;
|
||
6 years ago
|
|
||
|
vector<string> menu_options;
|
||
6 years ago
|
menu_options.push_back("Retry"); //Retry at previous difficulty
|
||
|
menu_options.push_back("To Main Menu"); //Go back to main menu to select new difficulty
|
||
|
menu_options.push_back("Exit"); //Quit game
|
||
6 years ago
|
menu.activate(menu_options);
|
||
|
|
||
|
sprites = _sprites;
|
||
|
}
|
||
|
|
||
|
void ResultScreen::run(ALLEGRO_FONT* font) {
|
||
|
ALLEGRO_EVENT_QUEUE* event_queue = NULL;
|
||
|
event_queue = al_create_event_queue();
|
||
|
al_register_event_source(event_queue, al_get_keyboard_event_source());
|
||
|
|
||
|
redraw(font);
|
||
|
al_flip_display();
|
||
|
|
||
|
bool exit_screen = false;
|
||
|
while (!exit_screen) {
|
||
|
ALLEGRO_EVENT ev;
|
||
|
al_wait_for_event(event_queue, &ev);
|
||
|
|
||
|
if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
|
||
|
switch (ev.keyboard.keycode) {
|
||
|
case ALLEGRO_KEY_UP:
|
||
6 years ago
|
//Move cursor up
|
||
6 years ago
|
menu.up();
|
||
|
break;
|
||
|
case ALLEGRO_KEY_DOWN:
|
||
6 years ago
|
//Move cursor down
|
||
6 years ago
|
menu.down();
|
||
|
break;
|
||
6 years ago
|
case ALLEGRO_KEY_SPACE:
|
||
|
//Select menu item
|
||
6 years ago
|
cont();
|
||
|
exit_screen = true;
|
||
|
break;
|
||
|
case ALLEGRO_KEY_ESCAPE:
|
||
6 years ago
|
//Force quit game
|
||
6 years ago
|
back();
|
||
|
exit_screen = true;
|
||
|
break;
|
||
|
}
|
||
|
redraw(font);
|
||
|
al_flip_display();
|
||
|
}
|
||
|
}
|
||
6 years ago
|
|
||
|
//Garbage collection
|
||
|
al_destroy_event_queue(event_queue);
|
||
6 years ago
|
}
|
||
|
|
||
|
void ResultScreen::redraw(ALLEGRO_FONT * font) {
|
||
6 years ago
|
//Determine whether the player receives the bad or good ending; minimum requirement for good ending is 30 catches.
|
||
6 years ago
|
string manager_sprite = (score > 29) ? "Mr. ManagerHappy" : "Mr. ManagerSad";
|
||
6 years ago
|
string result_text = (score > 29) ? "Great job! You helped Mr. Manager's team bond more than ever!" : "You didn't catch a lot of employees. Try to catch more next time!";
|
||
6 years ago
|
|
||
6 years ago
|
//Display score, level, and menu
|
||
6 years ago
|
al_draw_bitmap(sprites[manager_sprite], SCREEN_W / 2 - 120, SCREEN_H / 2 - 40, NULL);
|
||
|
menu.draw(SCREEN_W / 2, SCREEN_H / 2 - 30, 20.0, font);
|
||
|
ostringstream score_msg;
|
||
|
score_msg << "Final Score: " << score;
|
||
|
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 - 90, ALLEGRO_ALIGN_CENTER, score_msg.str().c_str());
|
||
|
ostringstream difficulty_msg;
|
||
|
difficulty_msg << "Level: " << difficulty;
|
||
|
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 - 75, ALLEGRO_ALIGN_CENTER, difficulty_msg.str().c_str());
|
||
|
al_draw_text(font, al_map_rgb(255, 255, 255), SCREEN_W / 2, SCREEN_H / 2 - 60, ALLEGRO_ALIGN_CENTER, result_text.c_str());
|
||
|
}
|
||
|
|
||
|
void ResultScreen::back() {
|
||
|
next_state = Exit;
|
||
|
}
|
||
|
|
||
|
void ResultScreen::cont() {
|
||
|
string result = menu.get_selected();
|
||
|
if(result == "Retry") {
|
||
6 years ago
|
next_state = prev_state;
|
||
6 years ago
|
}
|
||
|
else if (result == "To Main Menu") {
|
||
|
next_state = Start;
|
||
|
}
|
||
|
else {
|
||
|
next_state = Exit;
|
||
|
}
|
||
|
}
|