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
3f0b4378
Commit
3f0b4378
authored
May 11, 2020
by
Cameron Mahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trying to commit changes
parent
ea5b5f7e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
114 additions
and
6 deletions
+114
-6
Lobby.cpp
Lobby.cpp
+46
-0
Lobby.h
Lobby.h
+25
-0
Player.cpp
Player.cpp
+2
-2
Player.h
Player.h
+3
-3
main.cpp
main.cpp
+38
-1
No files found.
Lobby.cpp
0 → 100644
View file @
3f0b4378
#include "Lobby.h"
#include "Player.h"
#include <iostream>
using
namespace
std
;
Lobby
::
Lobby
(){
capacity
=
6
;
Player
players
[
capacity
];
size
=
0
;
rankSum
=
0
;
}
Lobby
::
Lobby
(
unsigned
int
cap
)
{
capacity
=
cap
;
Player
players
[
capacity
];
size
=
0
;
rankSum
=
0
;
}
int
Lobby
::
getAverage
()
{
if
(
size
==
0
)
{
return
0
;
}
rankSum
=
0
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
rankSum
+=
players
[
i
].
getRank
();
}
return
rankSum
/
size
;
}
void
Lobby
::
addPlayer
(
Player
p
){
cout
<<
"start add"
<<
endl
;
cout
<<
"player rank: "
<<
p
.
getRank
()
<<
endl
;
players
[
size
]
=
p
;
cout
<<
"increase size"
<<
endl
;
size
++
;
}
void
Lobby
::
display
(){
for
(
unsigned
int
i
=
0
;
i
<
size
;
i
++
)
{
cout
<<
"Player "
<<
i
+
1
<<
endl
;
players
[
i
].
displayName
();
cout
<<
players
[
i
].
getRank
()
<<
endl
;
}
}
Lobby.h
0 → 100644
View file @
3f0b4378
#ifndef LOBBY_H
#define LOBBY_H
#include <iostream>
#include "Player.h"
class
Lobby
{
public
:
Lobby
();
Lobby
(
unsigned
int
cap
);
int
getAverage
();
unsigned
int
getCapacity
()
{
return
capacity
;
}
unsigned
int
getSize
()
{
return
size
;
}
void
addPlayer
(
Player
p
);
void
display
();
private
:
unsigned
int
capacity
;
unsigned
int
size
;
unsigned
int
rankSum
;
Player
players
[];
};
#endif //LOBBY_H
Player.cpp
View file @
3f0b4378
...
...
@@ -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 @
3f0b4378
...
...
@@ -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 @
3f0b4378
...
...
@@ -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
unsigned
maxLobbies
=
4
;
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