コード例 #1
0
ファイル: ActionCards.cpp プロジェクト: mbelair/FiveAnimals
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);
}
コード例 #2
0
ファイル: ActionCards.cpp プロジェクト: mbelair/FiveAnimals
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;
	}


}
コード例 #3
0
ファイル: ActionCards.cpp プロジェクト: mbelair/FiveAnimals
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());
}
コード例 #4
0
ファイル: ActionCards.cpp プロジェクト: mbelair/FiveAnimals
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");
	}
}