-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighScoreForm.h
More file actions
191 lines (179 loc) · 7.47 KB
/
HighScoreForm.h
File metadata and controls
191 lines (179 loc) · 7.47 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#pragma once
#include "AboutForm.h"
#include "Player.h"
#include "Memory.h"
namespace MemoryGame {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for HighScoreForm
/// </summary>
public ref class HighScoreForm : public System::Windows::Forms::Form
{
private:
Memory* memoryGame = new Memory(4, 4);
public:
HighScoreForm(void)
{
InitializeComponent();
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~HighScoreForm()
{
if (components)
{
delete components;
}
if (memoryGame)
{
delete memoryGame;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
protected:
private: System::Windows::Forms::ToolStripMenuItem^ gameToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ aboutGameToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ closeToolStripMenuItem;
private: System::Windows::Forms::DataGridView^ highScoreGridView;
private: System::Windows::Forms::Label^ label1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(HighScoreForm::typeid));
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->gameToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->aboutGameToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->closeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->highScoreGridView = (gcnew System::Windows::Forms::DataGridView());
this->label1 = (gcnew System::Windows::Forms::Label());
this->menuStrip1->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->highScoreGridView))->BeginInit();
this->SuspendLayout();
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->gameToolStripMenuItem });
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(884, 24);
this->menuStrip1->TabIndex = 0;
this->menuStrip1->Text = L"menuStrip1";
//
// gameToolStripMenuItem
//
this->gameToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
this->aboutGameToolStripMenuItem,
this->closeToolStripMenuItem
});
this->gameToolStripMenuItem->Name = L"gameToolStripMenuItem";
this->gameToolStripMenuItem->Size = System::Drawing::Size(50, 20);
this->gameToolStripMenuItem->Text = L"Game";
//
// aboutGameToolStripMenuItem
//
this->aboutGameToolStripMenuItem->Name = L"aboutGameToolStripMenuItem";
this->aboutGameToolStripMenuItem->Size = System::Drawing::Size(140, 22);
this->aboutGameToolStripMenuItem->Text = L"About game";
this->aboutGameToolStripMenuItem->Click += gcnew System::EventHandler(this, &HighScoreForm::aboutGameToolStripMenuItem_Click);
//
// closeToolStripMenuItem
//
this->closeToolStripMenuItem->Name = L"closeToolStripMenuItem";
this->closeToolStripMenuItem->Size = System::Drawing::Size(140, 22);
this->closeToolStripMenuItem->Text = L"Close";
this->closeToolStripMenuItem->Click += gcnew System::EventHandler(this, &HighScoreForm::closeToolStripMenuItem_Click);
//
// highScoreGridView
//
this->highScoreGridView->AllowUserToAddRows = false;
this->highScoreGridView->AllowUserToDeleteRows = false;
this->highScoreGridView->AllowUserToResizeColumns = false;
this->highScoreGridView->AllowUserToResizeRows = false;
this->highScoreGridView->BackgroundColor = System::Drawing::Color::MediumSlateBlue;
this->highScoreGridView->BorderStyle = System::Windows::Forms::BorderStyle::None;
this->highScoreGridView->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->highScoreGridView->Location = System::Drawing::Point(24, 93);
this->highScoreGridView->Name = L"highScoreGridView";
this->highScoreGridView->ReadOnly = true;
this->highScoreGridView->RowHeadersWidthSizeMode = System::Windows::Forms::DataGridViewRowHeadersWidthSizeMode::DisableResizing;
this->highScoreGridView->Size = System::Drawing::Size(478, 463);
this->highScoreGridView->TabIndex = 1;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(238)));
this->label1->ForeColor = System::Drawing::Color::White;
this->label1->Location = System::Drawing::Point(20, 55);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(88, 20);
this->label1->TabIndex = 2;
this->label1->Text = L"High Score";
//
// HighScoreForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::Color::MediumSlateBlue;
this->ClientSize = System::Drawing::Size(884, 689);
this->Controls->Add(this->label1);
this->Controls->Add(this->highScoreGridView);
this->Controls->Add(this->menuStrip1);
this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
this->MainMenuStrip = this->menuStrip1;
this->Name = L"HighScoreForm";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Memory Game - High Score";
this->Load += gcnew System::EventHandler(this, &HighScoreForm::HighScoreForm_Load);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->highScoreGridView))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void closeToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void aboutGameToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
AboutForm^ aboutForm = gcnew AboutForm();
aboutForm->Show();
}
private: System::Void HighScoreForm_Load(System::Object^ sender, System::EventArgs^ e) {
try {
memoryGame->getHighScore()->readHighScores();
std::vector<Player> scores = memoryGame->getHighScore()->getPlayersScore();
DataTable^ dt = gcnew DataTable();
highScoreGridView->RowTemplate->Height = 30;
highScoreGridView->ColumnHeadersHeight = 30;
dt->Columns->Add("Player Name");
dt->Columns->Add("Player Steps");
for (int i = 0; i < scores.size(); i++) {
dt->Rows->Add(gcnew cli::array<String^> { gcnew String(scores[i].getPlayerName().c_str()), scores[i].getPlayerStep().ToString() });
}
highScoreGridView->DataSource = dt;
}
catch (const std::exception& e) {
MessageBox::Show(gcnew String(e.what()), "Memory Game", MessageBoxButtons::OK, MessageBoxIcon::Error);
this->Close();
}
}
};
}