//Highscores.h //Fully documented #pragma once
#include <stdio.h> #include <stdlib.h> #include #include #include <msclr\marshal_cppstd.h>
namespace MasterMindProyectoFinal {
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>
/// Resumen de Highscores
/// </summary>
public ref class Highscores : public System::Windows::Forms::Form
{
public:
Highscores(void)
{
InitializeComponent();
compare_players_time(); //updates the top3 list
}
protected:
/// <summary>
/// Limpiar los recursos que se estén usando.
/// </summary>
~Highscores()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ top3_hard_label;
private: System::Windows::Forms::Label^ player1_hard_label;
private: System::Windows::Forms::Label^ player2_hard_label;
private: System::Windows::Forms::Label^ player3_hard_label;
private: System::Windows::Forms::Label^ top3_medium_label;
private: System::Windows::Forms::Label^ top3_easy_label;
private: System::Windows::Forms::Label^ player1_medium_label;
private: System::Windows::Forms::Label^ player2_easy_label;
private: System::Windows::Forms::Label^ player3_medium_label;
private: System::Windows::Forms::Label^ player1_easy_label;
private: System::Windows::Forms::Label^ player2_medium_label;
private: System::Windows::Forms::Label^ player3_easy_label;
private: System::Windows::Forms::Label^ num_p1_h_label; private: System::Windows::Forms::Label^ num_p2_h_label; private: System::Windows::Forms::Label^ num_p3_h_label; private: System::Windows::Forms::Label^ num_p1_m_label; private: System::Windows::Forms::Label^ num_p2_m_label; private: System::Windows::Forms::Label^ num_p3_m_label; private: System::Windows::Forms::Label^ num_p1_e_label; private: System::Windows::Forms::Label^ num_p2_e_label; private: System::Windows::Forms::Label^ num_p3_e_label;
protected:
private:
/// <summary>
/// Variable del diseñador necesaria.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code ///
}
#pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Highscores::Close(); //Closes the highscores window }
private: System::Void Highscores_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void compare_players_time()
{
//This function will compare the data from the the winners in the file to see who has the best time and place it in its correct place
using namespace std;
string title;
string data;
String^ data_STR;
ifstream winnersFile;
winnersFile.open("SavedWinners.txt", ios::in); //Opens the file
while (!winnersFile.eof())
{
/*
This reads the information in the file, compares the time of each player with the one in the top 3,
and if a player in the file has a better time it adds this player to the top 3
*/
/*
////* ==> the code refered by this denotation is for moving the other players
to their respect places after placing the compared player from the file, in the top 3
*/
winnersFile >> title;
winnersFile >> data;
//This is used for the Top 3 of the Hard difficulty
if (data == "Hard")
{
winnersFile >> title;
winnersFile >> data;
string p1_label_str = msclr::interop::marshal_as<std::string>(num_p1_h_label->Text);
int p1_label_int = stoi(p1_label_str);
string p2_label_str = msclr::interop::marshal_as<std::string>(num_p2_h_label->Text);
int p2_label_int = stoi(p2_label_str);
string p3_label_str = msclr::interop::marshal_as<std::string>(num_p3_h_label->Text);
int p3_label_int = stoi(p3_label_str);
int data_time_int = stoi(data);
data_STR = gcnew String(data.c_str());
if (data_time_int < p1_label_int)
{
////*
String^ prev_player1 = player1_hard_label->Text;
String^ prev_p1_num = num_p1_h_label->Text;
String^ prev_player2 = player2_hard_label->Text;
String^ prev_p2_num = num_p1_h_label->Text;
//Places the data of the compared player in first place
num_p1_h_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player1_hard_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player1_hard_label->Text = player1_hard_label->Text + " " + data_STR;
////*
player2_hard_label->Text = prev_player1;
num_p2_h_label->Text = prev_p1_num;
player3_hard_label->Text = prev_player2;
num_p3_h_label->Text = prev_p2_num;
}
else if (data_time_int < p2_label_int)
{
////*
String^ prev_player2 = player2_hard_label->Text;
String^ prev_p2_num = num_p2_h_label->Text;
//Places the data of the compared player in second place
num_p2_h_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player2_hard_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player2_hard_label->Text = player2_hard_label->Text + " " + data_STR;
////*
player3_hard_label->Text = prev_player2;
num_p3_h_label->Text = prev_p2_num;
}
else if (data_time_int < p3_label_int)
{
//Places the data of the compared player in third place
num_p3_h_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player3_hard_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player3_hard_label->Text = player3_hard_label->Text + " " + data_STR;
}
winnersFile >> title;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> title;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
}
//This is used for the Top 3 of the Medium difficulty
else if (data == "Medium")
{
winnersFile >> title;
winnersFile >> data;
string p1_label_str = msclr::interop::marshal_as<std::string>(num_p1_m_label->Text);
int p1_label_int = stoi(p1_label_str);
string p2_label_str = msclr::interop::marshal_as<std::string>(num_p2_m_label->Text);
int p2_label_int = stoi(p2_label_str);
string p3_label_str = msclr::interop::marshal_as<std::string>(num_p3_m_label->Text);
int p3_label_int = stoi(p3_label_str);
int data_time_int = stoi(data);
data_STR = gcnew String(data.c_str());
if (data_time_int < p1_label_int)
{
////*
String^ prev_player1 = player1_medium_label->Text;
String^ prev_p1_num = num_p1_m_label->Text;
String^ prev_player2 = player2_medium_label->Text;
String^ prev_p2_num = num_p1_m_label->Text;
//Places the data of the compared player in first place
num_p1_m_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player1_medium_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player1_medium_label->Text = player1_medium_label->Text + " " + data_STR;
////*
player2_medium_label->Text = prev_player1;
num_p2_m_label->Text = prev_p1_num;
player3_medium_label->Text = prev_player2;
num_p3_m_label->Text = prev_p2_num;
}
else if (data_time_int < p2_label_int)
{
////*
String^ prev_player2 = player2_medium_label->Text;
String^ prev_p2_num = num_p1_m_label->Text;
//Places the data of the compared player in second place
num_p2_m_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player2_medium_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player2_medium_label->Text = player2_medium_label->Text + " " + data_STR;
////*
player3_medium_label->Text = prev_player2;
num_p3_m_label->Text = prev_p2_num;
}
else if (data_time_int < p3_label_int)
{
//Places the data of the compared player in third place
num_p3_m_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player3_medium_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player3_medium_label->Text = player3_medium_label->Text + " " + data_STR;
}
winnersFile >> title;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> title;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
}
//This is used for the Top 3 of the Easy difficulty
else if (data == "Easy")
{
winnersFile >> title;
winnersFile >> data;
string p1_label_str = msclr::interop::marshal_as<std::string>(num_p1_e_label->Text);
int p1_label_int = stoi(p1_label_str);
string p2_label_str = msclr::interop::marshal_as<std::string>(num_p2_e_label->Text);
int p2_label_int = stoi(p2_label_str);
string p3_label_str = msclr::interop::marshal_as<std::string>(num_p3_e_label->Text);
int p3_label_int = stoi(p3_label_str);
int data_time_int = stoi(data);
data_STR = gcnew String(data.c_str());
if (data_time_int < p1_label_int)
{
////*
String^ prev_player1 = player1_easy_label->Text;
String^ prev_p1_num = num_p1_e_label->Text;
String^ prev_player2 = player2_easy_label->Text;
String^ prev_p2_num = num_p1_e_label->Text;
//Places the data of the compared player in first place
num_p1_e_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player1_easy_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player1_easy_label->Text = player1_easy_label->Text + " " + data_STR;
////*
player2_easy_label->Text = prev_player1;
num_p2_e_label->Text = prev_p1_num;
player3_easy_label->Text = prev_player2;
num_p3_e_label->Text = prev_p2_num;
}
else if (data_time_int < p2_label_int)
{
////*
String^ prev_player2 = player2_easy_label->Text;
String^ prev_p2_num = num_p1_e_label->Text;
//Places the data of the compared player in second place
num_p2_e_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player2_easy_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player2_easy_label->Text = player2_easy_label->Text + " " + data_STR;
////*
player3_easy_label->Text = prev_player2;
num_p3_e_label->Text = prev_p2_num;
}
else if (data_time_int < p3_label_int)
{
//Places the data of the compared player in third place
num_p3_e_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player3_easy_label->Text = data_STR;
winnersFile >> title;
winnersFile >> data;
data_STR = gcnew String(data.c_str());
player3_easy_label->Text = player3_easy_label->Text + " " + data_STR;
}
winnersFile >> title;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> title;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
winnersFile >> data;
}
}
winnersFile.close();
}
};
}