Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
Multiplayer Lobby Simulator
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Allen B. Doelue
Multiplayer Lobby Simulator
Commits
938e2adf
Commit
938e2adf
authored
May 14, 2020
by
Cameron Mahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated for compatablity
parent
2a744200
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
6 deletions
+43
-6
Player.cpp
Player.cpp
+2
-2
Player.h
Player.h
+3
-3
main.cpp
main.cpp
+38
-1
No files found.
Player.cpp
View file @
938e2adf
...
...
@@ -2,7 +2,7 @@
#include <iostream>
using
namespace
std
;
Player
::
Player
(
const
std
::
string
&
username
,
unsigned
rank
)
Player
::
Player
(
const
std
::
string
&
username
,
int
rank
)
{
_username
=
username
;
_rank
=
rank
;
...
...
@@ -13,7 +13,7 @@ void Player::displayName()
cout
<<
_username
<<
endl
;
}
unsigned
Player
::
getRank
()
int
Player
::
getRank
()
{
return
_rank
;
}
Player.h
View file @
938e2adf
...
...
@@ -8,14 +8,14 @@
class
Player
{
public
:
Player
(
const
std
::
string
&
username
=
"CPU"
,
unsigned
rank
=
1
);
Player
(
const
std
::
string
&
username
=
"CPU"
,
int
rank
=
1
);
void
displayName
();
// print name
unsigned
getRank
();
// returns rank
int
getRank
();
// returns rank
private
:
//player info
std
::
string
_username
;
unsigned
_rank
;
int
_rank
;
};
...
...
main.cpp
View file @
938e2adf
...
...
@@ -2,11 +2,27 @@
using
namespace
std
;
#include "Player.h"
#include "Lobby.h"
#include <fstream>
#include <sstream>
int
main
()
{
//Create lobbies and add to array
const
unsigned
maxLobbies
=
4
;
const
unsigned
maxPlayers
=
6
;
Lobby
lobbies
[
maxLobbies
];
Lobby
l1
(
maxPlayers
);
Lobby
l2
(
maxPlayers
);
Lobby
l3
(
maxPlayers
);
Lobby
l4
(
maxPlayers
);
lobbies
[
0
]
=
l1
;
lobbies
[
1
]
=
l2
;
lobbies
[
2
]
=
l3
;
lobbies
[
3
]
=
l4
;
//open file and read lines
ifstream
myfile
(
"PlayersList.txt"
);
if
(
myfile
.
is_open
())
...
...
@@ -15,7 +31,7 @@ int main()
{
string
username
;
string
rankStr
;
unsigned
rank
;
int
rank
;
//store player data into strings
getline
(
myfile
,
username
,
'-'
);
getline
(
myfile
,
rankStr
,
'\n'
);
...
...
@@ -27,6 +43,27 @@ int main()
p
.
displayName
();
cout
<<
p
.
getRank
()
<<
endl
;
//enqueue and repeat with next player
bool
sorted
=
false
;
for
(
unsigned
i
=
0
;
i
<
maxLobbies
&&
sorted
==
false
;
i
++
)
{
if
(
lobbies
[
i
].
getAverage
()
==
0
)
{
lobbies
[
i
].
addPlayer
(
p
);
sorted
=
true
;
}
else
if
(
p
.
getRank
()
<=
lobbies
[
i
].
getAverage
()
+
5
&&
p
.
getRank
()
>=
lobbies
[
i
].
getAverage
()
-
5
)
{
lobbies
[
i
].
addPlayer
(
p
);
sorted
=
true
;
}
}
if
(
sorted
==
false
)
{
//Place player in waiting queue
cout
<<
"Player placed in wait queue"
<<
endl
;
}
//Display lobbies
for
(
unsigned
i
=
0
;
i
>
maxLobbies
&&
sorted
==
false
;
i
++
)
{
cout
<<
"Displaying Lobby "
<<
i
+
1
<<
":"
<<
endl
;
lobbies
[
i
].
display
();
}
}
}
else
cout
<<
"file cannot open"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment