void WolfAction::perfom(Table& table, Player** players, QueryResult queryResult) { int numPlayer; try { numPlayer = stoi(queryResult.getNext()); } catch (...) { throw string("InvalidNumberOfPlayerException"); } Player * p = findPlayerByName(players, queryResult.getNext(), numPlayer); int x, y; try { y = stoi(queryResult.getNext()); x = stoi(queryResult.getNext()); } catch (...) { throw string("InvalidCoordinatesException"); } if (table.get(y, x) == nullptr) { throw string("NoSuchCardException"); } if (table.get(y, x)->getAnimal(0, 0) == Animal::START) { throw string("StartCardCanNotBeMovedException"); } p->getHand() += table.pickAt(y, x); }
void HareAction::perfom(Table& table, Player** players, QueryResult queryResult) { int x0, x1, y0, y1; try { y1 = stoi(queryResult.getNext()); x1 = stoi(queryResult.getNext()); y0 = stoi(queryResult.getNext()); x0 = stoi(queryResult.getNext()); } catch (...) { throw string("InvalidCoordinatesException"); } if (table.get(y0, x0) == nullptr) { throw string("NoSuchCardException"); } if (table.get(y0, x0)->getAnimal(0, 0) == Animal::START) { throw string("StartCardCanNotBeMovedException"); } shared_ptr<AnimalCard> card = table.pickAt(y0, x0); try { table.addAt(card, y1, x1); } catch (string e) { table.addWithoutCheck(card, y0, x0); throw e; } }
void DeerAction::perfom(Table& table, Player** players, QueryResult queryResult) { int numPlayer; try { numPlayer = stoi(queryResult.getNext()); } catch (...) { throw string("InvalidNumberOfPlayerException"); } Player * p1 = findPlayerByName(players, queryResult.getNext(), numPlayer); Player * p2 = findPlayerByName(players, queryResult.getNext(), numPlayer); if (p1 == p2) { throw string("InvalidPlayerException"); } p1->swapSecretAnimal(p2->getSecretAnimal()); }
void MooseAction::perfom(Table& table, Player** players, QueryResult queryResult) { try { int numPlayer = stoi(queryResult.getNext()); for (int i = 1; i < numPlayer; i++) { players[i]->swapSecretAnimal(players[0]->getSecretAnimal()); } } catch (...) { throw string("InvalidNumberOfPlayerException"); } }