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
4bc03d90
Commit
4bc03d90
authored
3 years ago
by
lokesvelland
Browse files
Options
Downloads
Patches
Plain Diff
first commit test
parent
c24c68b2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.vscode/settings.json
+5
-0
5 additions, 0 deletions
.vscode/settings.json
src/kode/checkmate.cpp
+106
-17
106 additions, 17 deletions
src/kode/checkmate.cpp
with
111 additions
and
17 deletions
.vscode/settings.json
0 → 100644
+
5
−
0
View file @
4bc03d90
{
"files.associations"
:
{
"iostream"
:
"cpp"
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/kode/checkmate.cpp
+
106
−
17
View file @
4bc03d90
...
...
@@ -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
k
ommand
o
;
char
c
ommand
;
// readFromFile();
skrivMeny
();
k
ommand
o
=
lesChar
(
"
\n
Kommando"
);
c
ommand
=
lesChar
(
"
\n
Kommando"
);
while
(
k
ommand
o
!=
'Q'
)
{
switch
(
k
ommand
o
)
{
while
(
c
ommand
!=
'Q'
)
{
switch
(
c
ommand
)
{
case
1
:
newTournament
();
break
;
case
2
:
p
layer
();
break
;
case
2
:
newP
layer
();
break
;
case
3
:
results
();
break
;
case
4
:
updatePlayer
();
break
;
case
5
:
viewPlayers
();
break
;
default:
skrivMeny
();
break
;
}
k
ommand
o
=
lesChar
(
"
\n
Kommando"
);
c
ommand
=
lesChar
(
"
\n
Kommando"
);
}
// writeToFile();
...
...
@@ -69,7 +79,7 @@ char kommando;
/**
* Reads new player
*/
void
Player
::
p
layer
()
{
void
Player
::
newP
layer
()
{
Player
*
player
;
...
...
@@ -88,15 +98,94 @@ void Player::player() {
cout
<<
"
\n\n
Player 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\t
1. Enter info or 2. List"
,
1
,
2
);
cout
<<
"
\n\n
"
;
if
(
choise
==
1
)
{
choise
=
0
;
choise
=
lesInt
(
"
\n\t
1. search by name or 2. search by playerID"
,
1
,
2
);
cout
<<
"
\n\n
"
;
if
(
choise
==
1
)
{
cout
<<
"
\n\t
Name: "
;
getline
(
cin
,
search
);
if
(
findPlayer
(
name
)
==
nullptr
)
{
cout
<<
"
\n\t
Name not recognized!"
;
}
else
{
cout
<<
"
\n\t
Player found!
\n
"
;
findPlayer
(
name
)
->
writePlayer
();
}
}
else
if
(
choise
==
2
)
{
ID
=
lesInt
(
"
\n\t
PlayerID: "
,
1
,
1000
);
if
(
findPlayerID
(
ID
)
==
nullptr
)
{
cout
<<
"
\n\t
PlayerID not recognized!"
;
}
else
{
cout
<<
"
\n\t
Player found!
\n
"
;
findPlayerID
(
ID
)
->
writePlayer
();
}
}
}
else
if
(
choise
==
2
)
{
viewPlayers
();
}
...
...
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