@@ -258,7 +258,7 @@ void Player::setGenralModifier()
258258 *@param offer An array representing your offer to the bank
259259 *@param demand An array representing your demand
260260 */
261- void Player::tradeWithBank (int offer[], int demand[] )
261+ void Player::tradeWithBank (std::array< int , 5 > offer, std::array< int , 5 > demand)
262262{
263263 for (int i=0 ; i<5 ; i++)
264264 {
@@ -273,12 +273,12 @@ void Player::tradeWithBank(int offer[], int demand[])
273273 * @param demand An array representing your demand
274274 * @return true if bank accepted and trade was successful.
275275 */
276- bool Player::offerBankTrade (int offer[], int demand[] )
276+ bool Player::offerBankTrade (std::array< int , 5 > offer, std::array< int , 5 > demand)
277277{
278- if (!checkResources (offer))
278+ if (!checkResources (offer. data () ))
279279 return false ;
280280
281- int offerToBank[ 5 ] ;
281+ std::array< int , 5 > offerToBank ;
282282
283283 for (int i=0 ; i<5 ; i++)
284284 {
@@ -292,66 +292,23 @@ bool Player::offerBankTrade(int offer[], int demand[])
292292}
293293
294294
295- /* *
296- * Offer a trade to another player with an offer and a demand.
297- * @param p The other player that is receiving the trade.
298- * @param offer The resources this player is offering to the other player.
299- * @param demand The resources that this player wants in return from the other player.
300- * @return If the trade succeeded.
301- */
302- bool Player::offerTrade (Player* p, int offer[], int demand[])
303- {
304- if (sizeof offer/sizeof (int ) != 5 || sizeof demand/sizeof (int ) != 5 )
305- return false ; // Invalid Trade
306-
307- if (!this ->checkResources (offer))
308- return false ; // YOu dont have enough to offer this
309-
310- return p->recieveOffer (this , offer, demand);
311- }
312-
313-
314- /* *
315- * Receive a trade offer from another player.
316- * @param p The player offering the trade.
317- * @param offer The resources the other player is giving.
318- * @param demand The resources the other player wants in return.
319- * @return If the trade succeeded.
320- */
321- bool Player::recieveOffer (Player* p, int offer[], int demand[])
322- {
323- if ( !this ->checkResources (demand) )
324- return false ;
325-
326- bool input = true ;
327-
328- // TODO:Display Offer to User and wait for input
329-
330- if (input)
331- {
332- this ->acceptOffer (p, offer, demand);
333- return true ;
334- }
335- else
336- return false ;
337-
338- }
339-
340-
341295/* *
342296 * Accept the trade offer from another player.
343297 * @param p The player offering the trade.
344298 * @param offer The resources the other player is offering.
345299 * @param demand The resources the other player wants in return.
346300 */
347301
348- bool Player::acceptOffer (Player* p, int offer[], int demand[] )
302+ bool Player::acceptOffer (Player& p, std::array< int , 5 > offer, std::array< int , 5 > demand)
349303{
350- p->addWood (demand[WOOD_INDEX] - offer[WOOD_INDEX]);
351- p->addBrick (demand[BRICK_INDEX] - offer[BRICK_INDEX]);
352- p->addOre (demand[ORE_INDEX] - offer[ORE_INDEX]);
353- p->addWheat (demand[WHEAT_INDEX] - offer[WHEAT_INDEX]);
354- p->addWool (demand[WOOL_INDEX] - offer[WOOL_INDEX]);
304+ if (!checkResources (offer.data ()) || !p.checkResources (demand.data ())) {
305+ return false ;
306+ }
307+ p.addWood (demand[WOOD_INDEX] - offer[WOOD_INDEX]);
308+ p.addBrick (demand[BRICK_INDEX] - offer[BRICK_INDEX]);
309+ p.addOre (demand[ORE_INDEX] - offer[ORE_INDEX]);
310+ p.addWheat (demand[WHEAT_INDEX] - offer[WHEAT_INDEX]);
311+ p.addWool (demand[WOOL_INDEX] - offer[WOOL_INDEX]);
355312
356313 this ->addWood (offer[WOOD_INDEX] - demand[WOOD_INDEX]);
357314 this ->addBrick (offer[BRICK_INDEX] - demand[BRICK_INDEX]);
0 commit comments