currentCampaign = name;
}
-Account* Account::add(const string& name)
+void Account::add(const string& name)
{
accounts.push_back(new Account(name));
- return accounts.back();
+ active = accounts.back();
}
Account* Account::get(int i)
{
-
if ((i >= 0) && (i < int(accounts.size()))) {
return accounts[i];
} else
return NULL;
}
-void Account::destroy(int i)
+void Account::setActive(int i)
{
- accounts.erase(accounts.begin() + i);
+ active = get(i);
}
-Account* Account::destroy(Account* a)
+
+void Account::destroyActive()
{
for (unsigned i = 0; i < accounts.size(); i++) {
- if (accounts[i] == a) {
+ if (accounts[i] == active) {
accounts.erase(accounts.begin() + i);
- return NULL;
+ active = nullptr;
+ return;
}
}
- printf("Unexpected error : User %s not found\n", a->getName().c_str());
- return accounts.front();
+ cerr << "Unexpected error : User " << active->getName() << " not found" << endl;
+ if (accounts.empty()) {
+ active = nullptr;
+ } else {
+ active = accounts.front();
+ }
}
int Account::getDifficulty()
progress = level + 1;
}
-Account* Account::loadFile(string filename)
+void Account::loadFile(string filename)
{
FILE *tfile;
int numaccounts;
}
fclose(tfile);
- return get(iactive);
+ active = get(iactive);
} else {
perror(("Couldn't load users from " + filename).c_str());
- return NULL;
+ active = nullptr;
}
}
class Account
{
public:
- static void destroy(int i);
- static Account* destroy(Account* a);
- static Account* add(const std::string& name);
+ static void destroyActive();
+ static void setActive(int i);
+ static void add(const std::string& name);
static Account* get(int i);
- static Account* loadFile(std::string filename);
+ static void loadFile(std::string filename);
static void saveFile(std::string filename);
static int indice(Account* a);
numchallengelevels = 14;
- Account::active = Account::loadFile(Folders::getUserDataPath()+"/users");
+ Account::loadFile(Folders::getUserDataPath()+"/users");
whichjointstartarray[0] = righthip;
whichjointendarray[0] = rightfoot;
for (int i = 0; i < numlevels; i++) {
XYZ midpoint = campaignlevels[i].getCenter();
float itemsize = campaignlevels[i].getWidth();
- const bool active = i >= Account::active->getCampaignChoicesMade();
- if (!active)
+ const bool active = (i >= Account::active->getCampaignChoicesMade());
+ if (!active) {
itemsize /= 2;
+ }
if (i >= 1) {
XYZ start = campaignlevels[i - 1].getCenter();
addLabel(0, "No More Users", 10, 400);
addLabel(-2, "", 20, 400);
addButton(Account::getNbAccounts() + 1, "Back", 10, 10);
- for (int i = 0; i < Account::getNbAccounts(); i++)
+ for (int i = 0; i < Account::getNbAccounts(); i++) {
addButton(i + 1, Account::get(i)->getName(), 10, 340 - 20 * (i + 1));
+ }
break;
case 8:
addButton(0, "Easier", 10, 400);
fireSound();
if (selected == 1) {
flash();
- Account::active = Account::destroy(Account::active);
+ Account::destroyActive();
mainmenu = 7;
} else if (selected == 2) {
flash();
} else if (selected < Account::getNbAccounts() + 1) {
flash();
mainmenu = 5;
- Account::active = Account::get(selected - 1);
+ Account::setActive(selected - 1);
} else if (selected == Account::getNbAccounts() + 1) {
flash();
- if (Account::active)
+ if (Account::active) {
mainmenu = 5;
- else
+ } else {
mainmenu = 1;
+ }
displaytext[0].clear();
displayselected = 0;
entername = 0;
inputText(displaytext[0], &displayselected);
if (!waiting) { // the input as finished
if (!displaytext[0].empty()) { // with enter
- Account::active = Account::add(string(displaytext[0]));
+ Account::add(string(displaytext[0]));
mainmenu = 8;