@@ -99,12 +99,12 @@ int Player::getDevCardsInHand()
9999 * @return True if the player has enough resources to buy a road, false otherwise
100100 */
101101bool Player::canBuyRoad (){
102- return getWood () > 0 && getBrick () > 0 ;
102+ return getWood () >= 1 && getBrick () >= 1 ;
103103}
104104
105105/* *
106106 * Subtracts the cost of a road from a player's resources if they have enough
107- * returns true if the resources were subtracted, false otherwise
107+ * @return true if the resources were subtracted, false otherwise
108108 */
109109bool Player::buyRoad (){
110110 if (canBuyRoad ()){
@@ -116,27 +116,70 @@ bool Player::buyRoad(){
116116 return false ;
117117}
118118
119+ /* *
120+ * Determine if the player has enough resources to buy a settlement.
121+ * @return True if the player has enough resources to buy a road, false otherwise
122+ */
119123bool Player::canBuySettlement (){
120- return false ;
124+ return getWood () >= 1 && getBrick () >= 1 && getWheat () >= 1 && getWool () >= 1 ;
121125}
122126
127+ /* *
128+ * Subtracts the cost of a road from a player's resources if they have enough
129+ * @return true if the resources were subtracted, false otherwise
130+ */
123131bool Player::buySettlement (){
132+ if (canBuySettlement ()){
133+ addWood (-1 );
134+ addBrick (-1 );
135+ addWheat (-1 );
136+ addWool (-1 );
137+ return true ;
138+ }
124139 return false ;
125140}
126141
142+ /* *
143+ * Determine if the player has enough resources to buy a city.
144+ * @return True if the player has enough resources to buy a road, false otherwise
145+ */
127146bool Player::canBuyCity (){
128- return false ;
147+ return getWheat () >= 2 && getOre () >= 3 ;
129148}
130149
150+ /* *
151+ * Subtracts the cost of a city from a player's resources if they have enough
152+ * @return true if the resources were subtracted, false otherwise
153+ */
131154bool Player::buyCity (){
155+ if (canBuyCity ()){
156+ addWheat (-2 );
157+ addOre (-3 );
158+ }
132159 return false ;
133160}
134161
162+ /* *
163+ * Determine if the player has enough resources to buy a wonder.
164+ * @return True if the player has enough resources to buy a road, false otherwise
165+ */
135166bool Player::canBuyWonder (){
136- return false ;
167+ return getWood () >= 5 && getBrick () >= 5 && getWheat () >= 5 && getWool () >= 5 && getOre () >= 5 ;
137168}
138169
170+ /* *
171+ * Subtracts the cost of a wonder from a player's resources if they have enough
172+ * @return true if the resources were subtracted, false otherwise
173+ */
139174bool Player::buyWonder (){
175+ if (canBuySettlement ()){
176+ addWood (-5 );
177+ addBrick (-5 );
178+ addWheat (-5 );
179+ addWool (-5 );
180+ addOre (-5 );
181+ return true ;
182+ }
140183 return false ;
141184}
142185
0 commit comments