Commit 938e2adf authored by Cameron Mahan's avatar Cameron Mahan

Updated for compatablity

parent 2a744200
......@@ -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;
}
......@@ -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;
};
......
......@@ -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";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment