Skip to content
Snippets Groups Projects
Commit 4bc03d90 authored by lokesvelland's avatar lokesvelland
Browse files

first commit test

parent c24c68b2
No related branches found
No related tags found
No related merge requests found
{
"files.associations": {
"iostream": "cpp"
}
}
\ No newline at end of file
......@@ -15,7 +15,14 @@ private:
int wins;
public:
void player();
void newPlayer();
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; };
void writePlayer() const;
void updatePlayer();
int playerWin() {wins = 0;};
};
......@@ -29,9 +36,12 @@ const int STRLEN = 80;
// - tables (variable)
// Funksjoner:
void player();
void newPlayer();
void writePlayer();
void updatePlayer();
int playerWin();
Player* findPlayer(const string name);
Player* findPlayerID(const int ID);
void results();
void newTournament();
void viewPlayers();
......@@ -43,22 +53,22 @@ void readFromFile();
int main() {
char kommando;
char command;
// readFromFile();
skrivMeny();
kommando = lesChar("\nKommando");
command = lesChar("\nKommando");
while(kommando != 'Q') {
switch(kommando) {
while(command != 'Q') {
switch(command) {
case 1: newTournament(); break;
case 2: player(); break;
case 2: newPlayer(); break;
case 3: results(); break;
case 4: updatePlayer(); break;
case 5: viewPlayers(); break;
default: skrivMeny(); break;
}
kommando = lesChar("\nKommando");
command = lesChar("\nKommando");
}
// writeToFile();
......@@ -69,7 +79,7 @@ char kommando;
/**
* Reads new player
*/
void Player::player() {
void Player::newPlayer() {
Player* player;
......@@ -88,15 +98,94 @@ void Player::player() {
cout << "\n\nPlayer added!\n\n";
}
/**
* Writes out all info on player
*
*/
void Player::writePlayer() const {
cout << "\n" << name << '\n'
<< rating << '\n'
<< playerID << '\n'
<< club << '\n'
<< wins << "\n\n";
}
/**
* Finds player based on name and returns pointer
*
* @param name
* @return Player*
*/
Player* findPlayer(const string name) {
for(int i = 0; i < gPlayers.size(); i++) {
if(gPlayers[i]->playerName(name) == true) {
return gPlayers[i];
} else return nullptr;
}
}
/**
* Finds player based on PlayerID and returns pointer
*
* @param ID
* @return Player*
*/
Player* findPlayerID(const int ID) {
for(int i = 0; i < gPlayers.size(); i++) {
if(gPlayers[i]->playerId(ID) == true) {
return gPlayers[i];
} else return nullptr;
}
}
/**
* Updates the info of an excisting player
*
* @see viewPlayers()
* @see findPlayer()
* @see findPlayerID()
*/
void Player::updatePlayer() {
viewPlayers();
int choise,
ID;
string search;
choise = lesInt("\n\t1. Enter info or 2. List",1 , 2);
cout << "\n\n";
if(choise == 1) {
choise = 0;
choise = lesInt("\n\t1. search by name or 2. search by playerID", 1, 2);
cout << "\n\n";
if(choise == 1) {
cout << "\n\tName: "; getline(cin,search);
if(findPlayer(name) == nullptr) {
cout << "\n\tName not recognized!";
} else {
cout << "\n\tPlayer found!\n";
findPlayer(name)->writePlayer();
}
} else if(choise == 2) {
ID = lesInt("\n\tPlayerID: ", 1, 1000);
if(findPlayerID(ID) == nullptr) {
cout << "\n\tPlayerID not recognized!";
} else {
cout << "\n\tPlayer found!\n";
findPlayerID(ID)->writePlayer();
}
}
} else if(choise == 2) {
viewPlayers();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment