-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScores_window.cpp
More file actions
84 lines (74 loc) · 2.14 KB
/
Scores_window.cpp
File metadata and controls
84 lines (74 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//Team H08: William O'Rosky, Akshay Jagadeesh, Tyler Nardecchia
//CSCE 121-509
//Due: December 2, 2015
//Scores_window.cpp
#include "Scores_window.h"
using namespace Graph_lib;
//constructor
Scores_window::Scores_window(Point xy, int w, int h, const string& title):Window{xy,w,h,title}
{
//Set up GUI
Fl_Color old_color = fl_color();
fl_color(80,0,0);
color(fl_color());
title_label = new Text{Point{(win_width/2)-50, 75}, "Scores"};
title_label->set_font(Graph_lib::Font::courier_bold);
title_label->set_color(Color{0});
title_label_rectangle = new Rectangle{Point{300,40},175,55};
title_label_rectangle->set_fill_color(Color{16});
title_label->set_font_size(30);
initials_input = new In_box{Point{(win_width/2)-85, (win_height/3)-20}, 200, 50, ""};
initials_label = new Text{Point{210,180}, "Initials:"};
initials_label->set_color(Color{16});
initials_label->set_font_size(20);
scores_file.open(scores_filename, ifstream::in);
if (!scores_file)
error("can't open input file ",scores_filename);
scores = get_scores(scores_file);
scores_file.close();
attach(*title_label_rectangle);
attach(*title_label);
attach(*initials_input);
attach(*initials_label);
display_scores(scores);
}
//functions
//public function that returns the player's initials entered
//in the In_box; if the player enters more than 3 characters,
//only the first 3 are used
string Scores_window::get_initials()
{
initials = initials_input->get_string();
if (initials.length() > 3)
initials = initials.substr(0,3);
return initials;
}
//inputs the scores from scores.txt
vector<string> Scores_window::get_scores(ifstream& scores_file)
{
vector<string> tmp;
string name;
string score;
while(scores_file >> name >> score)
{
string s = name + '\t' + score;
tmp.push_back(s);
}
return tmp;
}
//displays the initials and scores to the screen
void Scores_window::display_scores(vector<string> scores)
{
auto y = 225;
auto i = 0;
//for (int i = 0; i < scores.size(); ++i)
for(string x : scores)
{
Text* t = new Text{Point{(win_width/2)-35, y}, to_string(i + 1) + ") " + scores[i]};
t->set_color(Color{16});
t->set_font_size(20);
attach(*t);
y += 50;
i++;
}
}