Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG1004_2022_group4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Magnus Westerheim Johannessen
PROG1004_2022_group4
Commits
00fff0ee
Commit
00fff0ee
authored
3 years ago
by
Loke Nesse Svelland
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
6b17431d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/kode/MVP.cpp
+315
-0
315 additions, 0 deletions
src/kode/MVP.cpp
with
315 additions
and
0 deletions
src/kode/MVP.cpp
0 → 100644
+
315
−
0
View file @
00fff0ee
/**
* The minimal viable product of Group 4's product
* @file MVP.cpp
*
* @copyright Copyright (c) 2022
*
*/
#include
<iostream>
// cout, cin
#include
<string>
// string
#include
<vector>
// vector
#include
<iomanip>
// setw
#include
<fstream>
// ifstream, ofstream
#include
"LesData2.h"
using
namespace
std
;
class
Tournament
{
private:
public:
void
theTournament
();
};
class
Player
:
public
Tournament
{
private:
string
name
;
int
rating
;
int
playerID
;
string
club
;
int
wins
,
draws
;
float
score
;
public:
// sets all data as empty or 0
Player
()
{
name
=
club
=
""
;
rating
=
playerID
=
wins
=
draws
=
score
=
0
;};
void
newPlayer
(
const
string
nme
);
void
writePlayer
()
const
;
string
returnName
();
void
editSelectedPlayer
();
void
addWin
();
void
addDraw
();
};
class
Match
:
public
Tournament
{
private:
vector
<
int
*>
tableNr
;
};
// Global values
const
int
STRLEN
=
100
;
int
gRounds
=
0
;
int
gTables
=
0
;
// Vectors
vector
<
Player
*>
gPlayers
;
vector
<
Player
*>
player1
;
vector
<
Player
*>
player2
;
// global functions
void
addPlayer
();
void
writeMenu
();
void
editPlayer
();
void
viewPlayers
();
Player
*
findPlayer
(
const
string
name
);
void
newMatch
();
int
main
()
{
char
command
;
//readFromFile();
//readFromFileTournament();
//amntTables();
writeMenu
();
command
=
lesChar
(
"
\n
Command"
);
while
(
command
!=
'Q'
)
{
switch
(
command
)
{
case
'A'
:
addPlayer
();
break
;
case
'W'
:
viewPlayers
();
break
;
case
'E'
:
editPlayer
();
break
;
case
'M'
:
newMatch
();
break
;
default:
writeMenu
();
break
;
}
command
=
lesChar
(
"
\n
Command"
);
}
//writeToFileTournament();
//writeToFile();
return
0
;
}
void
Player
::
newPlayer
(
const
string
nme
)
{
name
=
nme
;
rating
=
lesInt
(
"
\n\t
Players rating: "
,
1
,
3000
);
playerID
=
lesInt
(
"
\n\t
Players ID: "
,
1
,
10000
);
cout
<<
"
\n\t
Players club: "
;
getline
(
cin
,
club
);
}
/**
* edits selected player from list
*
*/
void
Player
::
editSelectedPlayer
()
{
cout
<<
"
\n\t
Players Name: "
;
getline
(
cin
,
name
);
rating
=
lesInt
(
"
\n\t
Players rating: "
,
1
,
3000
);
playerID
=
lesInt
(
"
\n\t
Players ID: "
,
1
,
10000
);
cout
<<
"
\n\t
Players club: "
;
getline
(
cin
,
club
);
}
/*
* Writes out all info on player
*
*/
void
Player
::
writePlayer
()
const
{
cout
<<
"
\n
"
<<
"Player name: "
<<
name
<<
'\n'
<<
"Player rating: "
<<
rating
<<
'\n'
<<
"PlayerID: "
<<
playerID
<<
'\n'
<<
"Players club: "
<<
club
<<
'\n'
<<
"Amount of draws: "
<<
draws
<<
'\n'
<<
"Amount of wins: "
<<
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
]
->
returnName
()
==
name
)
return
gPlayers
[
i
];
}
return
nullptr
;
}
string
Player
::
returnName
(){
return
name
;
}
void
Player
::
addWin
()
{
wins
++
;
}
void
Player
::
addDraw
()
{
draws
++
;
}
void
Tournament
::
theTournament
()
{
int
matches
;
matches
=
lesInt
(
"
\n\t
How many matches wil be played: "
,
2
,
(
gPlayers
.
size
()
/
2
));
}
//=============================================================================
//
// NON CLASS FUNCTIONS
//
// ============================================================================
/**
* Add a player
*
* @see - Player::newPlayer()
*/
void
addPlayer
()
{
Player
*
newPlayer
;
string
name
;
newPlayer
=
new
Player
;
cout
<<
"
\n\t
new players name: "
;
getline
(
cin
,
name
);
newPlayer
->
newPlayer
(
name
);
gPlayers
.
push_back
(
newPlayer
);
cout
<<
"
\n\n
Player added!
\n\n
"
;
}
/**
* Writes out all players and their stats
*
* @see writePlayer() const
*/
void
viewPlayers
()
{
for
(
size_t
i
=
0
;
i
<
gPlayers
.
size
();
i
++
){
cout
<<
"
\n\t
Player "
<<
i
+
1
;
gPlayers
[
i
]
->
writePlayer
();
}
}
/**
* find player to edit
*
* @see viewPlayers()
* @see editSelectedPlayer()
* @see returnName()
*/
void
editPlayer
()
{
int
choise
,
playerNr
;
string
name
;
choise
=
lesInt
(
"
\n\t
1. Enter info 2. List"
,
1
,
2
);
// searches after player by name
if
(
choise
==
1
)
{
cout
<<
"
\n\t
Players name: "
;
getline
(
cin
,
name
);
for
(
size_t
i
=
0
;
i
<
gPlayers
.
size
();
i
++
)
{
if
(
gPlayers
[
i
]
->
returnName
()
==
name
)
{
gPlayers
[
i
]
->
editSelectedPlayer
();
}
}
// pickes player out from list
}
else
if
(
choise
==
2
)
{
viewPlayers
();
playerNr
=
lesInt
(
"
\n\t
Player: "
,
1
,
gPlayers
.
size
());
for
(
size_t
i
=
0
;
i
<
gPlayers
.
size
();
i
++
)
{
if
(
gPlayers
[
playerNr
-
1
]
->
returnName
()
==
gPlayers
[
i
]
->
returnName
())
{
gPlayers
[
i
]
->
editSelectedPlayer
();
}
}
}
}
/**
* Sets up a new match
*
*/
void
newMatch
()
{
string
name
;
int
WorD
,
who
;
viewPlayers
();
cout
<<
"
\n\t
Player1 name: "
;
getline
(
cin
,
name
);
for
(
size_t
i
=
0
;
i
<
gPlayers
.
size
();
i
++
)
{
if
(
gPlayers
[
i
]
->
returnName
()
==
name
)
{
player1
.
push_back
(
gPlayers
[
i
]);
}
}
cout
<<
"
\n\t
Player2 name: "
;
getline
(
cin
,
name
);
for
(
size_t
i
=
0
;
i
<
gPlayers
.
size
();
i
++
)
{
if
(
gPlayers
[
i
]
->
returnName
()
==
name
)
{
player2
.
push_back
(
gPlayers
[
i
]);
}
}
WorD
=
lesInt
(
"
\n\t
Was there a 1. win or 2. draw"
,
1
,
2
);
if
(
WorD
==
2
){
player1
[
0
]
->
addDraw
();
player2
[
0
]
->
addDraw
();
cout
<<
"
\n\t
Match was a draw! both players rewarded 0.5 points
\n\n
"
;
}
else
if
(
WorD
==
1
)
{
cout
<<
"
\n\t
Who won 1. "
<<
player1
[
0
]
->
returnName
()
<<
" or 2. "
<<
player2
[
0
]
->
returnName
();
who
=
lesInt
(
": "
,
1
,
2
);
if
(
who
==
1
)
{
player1
[
0
]
->
addWin
();
}
else
{
player2
[
0
]
->
addWin
();
}
}
}
/**
* writes the programs menu options
*/
void
writeMenu
()
{
cout
<<
"
\n
Menu:
\n
"
<<
"
\t
A - Add player
\n
"
<<
"
\t
W - view players
\n
"
<<
"
\t
E - Edit player
\n
"
<<
"
\t
M - New match
\n
"
<<
"
\t
Q - Quit
\n\n
"
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment