Skip to content
Snippets Groups Projects
Commit 2e96a776 authored by TheHresvelgian's avatar TheHresvelgian
Browse files

Organizing code

parent 5f3448b6
No related branches found
No related tags found
No related merge requests found
#include <iostream> // cout, cin #include <iostream> // cout, cin
#include <string> // string #include <string> // string
#include <vector> // vector #include <vector> // vector
#include <iomanip> // setw #include <iomanip> // setw
#include <fstream> // ifstream, ofstream #include <fstream> // ifstream, ofstream
#include "LesData2.h" #include "LesData2.h"
#include "player.h"
using namespace std; using namespace std;
class Player vector<Player*> playerList;
{
private:
string name;
int rating;
int playerID;
string club;
int wins,
draws;
float score;
public:
void newPlayer(Player *player);
bool playerName(const string pname)
{
if (pname == name)
{
return true;
}
else
return false;
};
bool playerId(const int ID)
{
if (ID == playerID)
{
return true;
}
else
return false;
};
string returnName();
void writePlayer() const;
void updatePlayer();
//void player(){};
void player(){name = " "; playerID = 0; club = " "; wins = 0; draws = 0;
score = 0;};
void calculateScore();
void writeToFilePlayer(ofstream &out);
void readFromFilePlayer(ifstream &in);
void viewResults(int i);
};
class Tournament class Tournament
{ {
...@@ -126,22 +90,7 @@ char command; ...@@ -126,22 +90,7 @@ char command;
return 0; return 0;
} }
/**
* Reads new player
*/
void Player::newPlayer(Player *player)
{
cout << "\n\tFull name: ";
getline(cin, player->name);
player->rating = lesInt("\n\tRating: ", 1, 10);
player->playerID = lesInt("\n\tPlayer ID: ", 1, 1000);
cout << "\n\tClub: ";
getline(cin, player->club);
}
/** /**
* Writes out all info on player * Writes out all info on player
...@@ -233,20 +182,7 @@ void Player::readFromFilePlayer(ifstream &in) ...@@ -233,20 +182,7 @@ void Player::readFromFilePlayer(ifstream &in)
getline(in, club); getline(in, club);
} }
/**
* Write one player to file
*
* @param out - the file being written to
*/
void Player::writeToFilePlayer(ofstream &out)
{
out << setw(STRLEN) << name
<< setw(STRLEN) << rating
<< setw(STRLEN) << playerID
<< setw(STRLEN) << club
<< "\n";
}
/** /**
* Writes out all data for one tournament round * Writes out all data for one tournament round
......
/**
* Declaration of all functions
*/
#ifndef CHECKMATE_FUNCTIONS_H
#define CHECKMATE_FUNCTIONS_H
void newPlayer(int id);
#endif //CHECKMATE_FUNCTIONS_H
/**
* Reads new player
*/
#include <iostream> // cout, cin
#include <string> // STRING-KLASSEN
#include "player.h"
#include "LesData2.h"
#include "functions.h"
using namespace std;
extern vector<Player*>playerList;
void newPlayer(int id)
{
cout << "\n\tFull name: ";
getline(cin, player->name);
player->rating = lesInt("\n\tRating: ", 1, 10);
player->playerID = lesInt("\n\tPlayer ID: ", 1, 1000);
cout << "\n\tClub: ";
getline(cin, player->club);
}
\ No newline at end of file
//
// Created by sigru on 25.04.2022.
//
#include <string> // string
#include <vector> // vector
#include <fstream> // ifstream, ofstream
#include "player.h"
#include "LesData2.h"
using namespace std;
Player::Player()
{
firstName = "";
lastName = "";
club = "";
rating = 0;
playerID = 0;
score = 0.0f;
}
Player::Player(string name, string surName, string clubName, int rating, int playerID, float score)
{
setPlayer(name,surName,clubName,rating,playerID,score);
}
void Player::setPlayer(string nm, string srNm, string clbNm, int rtng, int plyrID, float scr)
{
firstName = nm;
lastName = srNm;
club = clbNm;
rating = rtng;
playerID = plyrID;
score = scr;
}
/**
* Prints the player
*
* @see currentRank(playerID);
*/
void Player::printPlayer()
{
cout << lastName << ", " << firstName
<< endl << "Club: " << club << endl
<< "Rating: " << rating << endl
<< "ID: " << playerID << endl
<< "Current score: " << score << endl
<< "Current rank in tournament: " << currentRank(playerID) << endl;
}
void Player::calculateScore()
{
}
/**
* Write one player to file
*
* @param out - the file being written to
*/
void Player::writeToFilePlayer(ofstream &out)
{
out << setw(80) << firstName
<< setw(80) << lastName
<< setw(80) << rating
<< setw(80) << playerID
<< setw(80) << club
<< "\n";
}
|
/**
* Read one player from file
*
* @param in - the file being read from
*/
void Player::readFromFilePlayer(ifstream &in)
{
getline(in, firstName);
getline(in, lastName);
in >> rating;
in.ignore();
in >> playerID;
in.ignore();
getline(in, club);
}
int Player::currentRank(int id)
{
}
\ No newline at end of file
...@@ -5,4 +5,38 @@ ...@@ -5,4 +5,38 @@
#ifndef CHECKMATE_PLAYER_H #ifndef CHECKMATE_PLAYER_H
#define CHECKMATE_PLAYER_H #define CHECKMATE_PLAYER_H
#include <string> // string
#include <vector> // vector
#include <fstream> // ifstream, ofstream
using namespace std;
class Player
{
private:
string firstName;
string lastName;
string club;
int rating;
int playerID;
float score;
public:
vector <int> results;
vector <Player*> playedAgainst;
vector<bool> wasWhite;
Player();
Player(string name, string surName, string clubName, int rating, int playerID, float score);
virtual void setPlayer(string nm, string , string clbNm, int rtng, int plyrID, float score);
virtual void printPlayer();
virtual void calculateScore();
virtual void writeToFilePlayer(ofstream &out);
virtual void readFromFilePlayer(ifstream &in);
int currentRank(int id);
};
#endif //CHECKMATE_PLAYER_H #endif //CHECKMATE_PLAYER_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment