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

Updated for compatablity

parent 2a744200
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
Player::Player(const std::string& username, unsigned rank) Player::Player(const std::string& username, int rank)
{ {
_username = username; _username = username;
_rank = rank; _rank = rank;
...@@ -13,7 +13,7 @@ void Player::displayName() ...@@ -13,7 +13,7 @@ void Player::displayName()
cout<<_username<<endl; cout<<_username<<endl;
} }
unsigned Player::getRank() int Player::getRank()
{ {
return _rank; return _rank;
} }
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
class Player class Player
{ {
public: public:
Player(const std::string& username = "CPU", unsigned rank = 1); Player(const std::string& username = "CPU", int rank = 1);
void displayName(); // print name void displayName(); // print name
unsigned getRank(); // returns rank int getRank(); // returns rank
private: private:
//player info //player info
std::string _username; std::string _username;
unsigned _rank; int _rank;
}; };
......
...@@ -2,11 +2,27 @@ ...@@ -2,11 +2,27 @@
using namespace std; using namespace std;
#include "Player.h" #include "Player.h"
#include "Lobby.h"
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
int main() 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 //open file and read lines
ifstream myfile("PlayersList.txt"); ifstream myfile("PlayersList.txt");
if(myfile.is_open()) if(myfile.is_open())
...@@ -15,7 +31,7 @@ int main() ...@@ -15,7 +31,7 @@ int main()
{ {
string username; string username;
string rankStr; string rankStr;
unsigned rank; int rank;
//store player data into strings //store player data into strings
getline(myfile, username, '-'); getline(myfile, username, '-');
getline(myfile, rankStr, '\n'); getline(myfile, rankStr, '\n');
...@@ -27,6 +43,27 @@ int main() ...@@ -27,6 +43,27 @@ int main()
p.displayName(); p.displayName();
cout<<p.getRank()<<endl; cout<<p.getRank()<<endl;
//enqueue and repeat with next player //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"; 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