{"id":597,"date":"2020-09-16T15:09:52","date_gmt":"2020-09-16T15:09:52","guid":{"rendered":"http:\/\/mipython.magwebdesigns.net\/WP\/?p=597"},"modified":"2020-10-01T02:40:49","modified_gmt":"2020-10-01T02:40:49","slug":"mi-python-txt-rpg-adventure-tutorial-4-ascii-graphics-and-character-dialog","status":"publish","type":"post","link":"http:\/\/mipython.magwebdesigns.net\/WP\/2020\/09\/16\/mi-python-txt-rpg-adventure-tutorial-4-ascii-graphics-and-character-dialog\/","title":{"rendered":"MI Python TXT RPG  Adventure Tutorial 4 |  More Inventory and the Store"},"content":{"rendered":"\n<p>First a little house cleaning.  We need to update our Players inventory drop function.  Let&#8217;s add that in now.  <\/p>\n\n\n\n<p> Add this to the Player class in the Player.py file.  We are updating our nested function within our inventory method.  We are doing the same thing we did with items.   We just change the Player&#8217;s \/ Room&#8217;s object list to remove \/ append from the weapon and armors lists respectively. <\/p>\n\n\n\n<pre class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/><\/div><\/td><td><div class=\"text codecolorer\">def drop(room):<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;DROP (I)TEM | (W)EAPON | (A)RMOR ?&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; user_input = self.user_input()<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;I&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;DROPPING ITEM&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; for item in self.items:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;DROPPING &quot; + item.name)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.items.remove(item)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; room.items.append(item)<br \/>\n&nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; elif user_input == &quot;W&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;DROPPING WEAPON&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; for weapon in self.weapons:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;DROPPING &quot; + weapon.name)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.weapons.remove(weapon)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; room.weapons.append(weapon)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; elif user_input == &quot;A&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;DROPPING ARMOR&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; for armor in self.armors:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;DROPPING &quot; + armor.name)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.armors.remove(armor)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; room.armors.append(armor)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; else:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; pass<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n\n\n\n<p>Then, the Player can&#8217;t &#8220;die&#8221; in game.  Without risk their can be no reward.  So,  lets add a que_free method to the Player similar to the Character que_free method. <\/p>\n\n\n\n<pre class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"text codecolorer\">def que_free(self,room):<br \/>\n&nbsp; &nbsp; pass<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n\n\n\n<pre id=\"block-e7c196f1-96d4-4cce-afee-1c574343a041\" class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">&nbsp;<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n\n\n\n<pre id=\"block-12ff6baa-b656-4161-84bb-ecc63a010c8b\" class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">Lets also add experience to the game. &nbsp;So the player can level up. &nbsp;We will add the defeated enemy's xp to our players xp variable. &nbsp;In our Game grid method lets add.<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n\n\n\n<pre id=\"block-e7c196f1-96d4-4cce-afee-1c574343a041\" class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/><\/div><\/td><td><div class=\"text codecolorer\">&nbsp; def grid(self,player):<br \/>\n&nbsp; &nbsp; ....<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ### &nbsp; QUE ENEMY FREE ON 0 HP &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if enemy.hp &amp;lt;=0:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.xp += enemy.xp<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; enemy.queue_free(enemy,room)<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n\n\n\n<p>Add a &#8220;random&#8221; encounter method to our Game  class.  We will call this method to generate random encounters every &#8220;turn&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/><\/div><\/td><td><div class=\"text codecolorer\">def random_encounter(self,player):<br \/>\n<br \/>\n&nbsp; &nbsp; #rooms = &amp;#91;start_room,orc_room,peon_room,rat_room]<br \/>\n&nbsp; &nbsp; enemies = &amp;#91;orc_peon,orc_peon]<br \/>\n<br \/>\n&nbsp; &nbsp; roll = random.randint(0,100)<br \/>\n<br \/>\n&nbsp; &nbsp; if roll &amp;lt;= 10:<br \/>\n&nbsp; &nbsp; &nbsp; #print(&quot;2 ORC PEONS&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; print(enemies&amp;#91;0].name)<br \/>\n&nbsp; &nbsp; &nbsp; print(enemies&amp;#91;1].name)<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; #enemies&amp;#91;0].pos_x = player.pos_x and enemies&amp;#91;0].pos_y = player.pos_y<br \/>\n&nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; #enemies&amp;#91;1]<br \/>\n<br \/>\n&nbsp; &nbsp; elif roll &gt;=11 and roll &amp;lt;= 20:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;ORC PEON&quot;)<br \/>\n&nbsp; &nbsp; elif roll &gt;=21 and roll &amp;lt;= 95 :<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;NO ENCOUNTERS&quot;)<br \/>\n&nbsp; &nbsp; elif roll &gt;= 96:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;TREASURE ROOM&quot;)<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Store Class:<\/h2>\n\n\n\n<p>Lets add a &#8220;store&#8221; class to our game.  the Player needs a place to buy and sell off inventory.  On further refinement \/ refactoring we might modify our Room class its self.  But, for the scope of this Python Rpg text tutorial we will just initialize a new class.  This store class will be instantiated when we are on a certain grid position that we will designate in the Stores pos_x and pos_y attributes.  We then pass the store into the Game grid room list just like we do with the Room class. <\/p>\n\n\n\n<p>The Store class will have  4 methods. A status method like all the other classes. A menu method that displays user options.  Thirdly a buy method. Lastly a sell method.   For the buy and sell methods we will pass in the object list as the argument.  Instead of writing out each object list (items,weapons,armors).<\/p>\n\n\n\n<p>Lets make our Store class. <\/p>\n\n\n\n<pre class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/>46<br \/>47<br \/>48<br \/>49<br \/>50<br \/>51<br \/>52<br \/>53<br \/>54<br \/>55<br \/>56<br \/>57<br \/>58<br \/>59<br \/>60<br \/>61<br \/>62<br \/>63<br \/>64<br \/>65<br \/>66<br \/>67<br \/>68<br \/>69<br \/>70<br \/>71<br \/>72<br \/>73<br \/>74<br \/>75<br \/>76<br \/>77<br \/>78<br \/>79<br \/>80<br \/>81<br \/>82<br \/>83<br \/>84<br \/>85<br \/>86<br \/>87<br \/>88<br \/>89<br \/>90<br \/>91<br \/>92<br \/>93<br \/>94<br \/>95<br \/>96<br \/>97<br \/>98<br \/>99<br \/>100<br \/>101<br \/>102<br \/>103<br \/>104<br \/>105<br \/>106<br \/>107<br \/>108<br \/>109<br \/>110<br \/>111<br \/>112<br \/>113<br \/>114<br \/>115<br \/>116<br \/>117<br \/>118<br \/>119<br \/>120<br \/>121<br \/>122<br \/>123<br \/>124<br \/>125<br \/>126<br \/>127<br \/>128<br \/>129<br \/>130<br \/>131<br \/>132<br \/>133<br \/>134<br \/>135<br \/>136<br \/>137<br \/>138<br \/>139<br \/>140<br \/>141<br \/>142<br \/>143<br \/>144<br \/>145<br \/>146<br \/>147<br \/>148<br \/>149<br \/>150<br \/>151<br \/>152<br \/>153<br \/>154<br \/>155<br \/>156<br \/>157<br \/>158<br \/><\/div><\/td><td><div class=\"text codecolorer\">from Player import *<br \/>\nfrom Item import *<br \/>\n#from main import *<br \/>\n<br \/>\n<br \/>\nclass Store():<br \/>\n&nbsp; def __init__(self,pos_x,pos_y,player,items,weapons,armors):<br \/>\n&nbsp; &nbsp; self.name = &quot;STORE&quot;<br \/>\n&nbsp; &nbsp; self.pos_x = pos_x<br \/>\n&nbsp; &nbsp; self.pos_y = pos_y<br \/>\n&nbsp; &nbsp; self.items = items<br \/>\n&nbsp; &nbsp; self.weapons = weapons<br \/>\n&nbsp; &nbsp; self.armors = armors<br \/>\n&nbsp; <br \/>\n&nbsp; def status(self):<br \/>\n&nbsp; &nbsp; print(self.name + &quot; IS INSTANTIATED&quot;)<br \/>\n&nbsp; &nbsp; self.menu(player)<br \/>\n<br \/>\n&nbsp; def menu(self,player):<br \/>\n&nbsp; &nbsp; print(&quot;STORE MENU&quot;)<br \/>\n&nbsp; &nbsp; print(&quot;(B)UY | (S)ELL | (L)EAVE&quot;)<br \/>\n<br \/>\n&nbsp; &nbsp; user_input = player.user_input()<br \/>\n<br \/>\n&nbsp; &nbsp; if user_input == &quot;B&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;BUYING&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;BUY (I)TEM | (W)EAPON | (A)RMOR ?&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; user_input = player.user_input()<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;I&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;BUYING ITEMS&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; self.buy(player,self.items,player.items)<br \/>\n&nbsp; &nbsp; &nbsp; elif user_input == &quot;W&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;BUYING WEAPONS&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; self.buy(player,self.weapons,player.weapons)<br \/>\n&nbsp; &nbsp; &nbsp; elif user_input == &quot;A&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;BUYING ARMOR&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; self.buy(player,self.armors,player.armors)<br \/>\n<br \/>\n<br \/>\n&nbsp; &nbsp; elif user_input == &quot;S&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;SELLING&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;SELL (I)TEM | (W)EAPON | (A)RMOR ?&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; user_input = player.user_input()<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;I&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;SELLING ITEMS&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; self.sell(player,self.items,player.items)<br \/>\n&nbsp; &nbsp; &nbsp; elif user_input == &quot;W&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;SELLING WEAPONS&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; self.sell(player,self.weapons,player.weapons)<br \/>\n&nbsp; &nbsp; &nbsp; elif user_input == &quot;A&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;SELLING ARMOR&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; self.sell(player,self.armors,player.armors)<br \/>\n<br \/>\n&nbsp; &nbsp; elif user_input == &quot;L&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; print(player.name + &quot; IS LEAVING&quot;)<br \/>\n<br \/>\n<br \/>\n&nbsp; ### &nbsp; PASS IN ITEM WEAPON OR ARMOR LIST AS OBJ_LISTS FOR STORE AND PLAYER<br \/>\n&nbsp; def buy(self,player,store_obj_list,player_obj_list):<br \/>\n&nbsp; &nbsp; print(player.name + &quot; IS BUYING&quot;)<br \/>\n&nbsp; &nbsp; i = 0<br \/>\n&nbsp; &nbsp; for obj in store_obj_list: &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; i += 1<br \/>\n&nbsp; &nbsp; &nbsp; print(str(i) + &quot; &quot; + obj.name + &quot; &quot; + str(obj.gp_value) + &quot; GP&quot;)<br \/>\n<br \/>\n&nbsp; &nbsp; print(&quot;BUY WHICH NUMBER 1-&quot; + str(len(store_obj_list)))<br \/>\n<br \/>\n&nbsp; &nbsp; user_input = player.user_input()<br \/>\n<br \/>\n&nbsp; &nbsp; try:<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;1&quot;: <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; if player.gp &gt;= store_obj_list&amp;#91;0].gp_value:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;BUYING &quot; + store_obj_list&amp;#91;0].name)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.gp -= store_obj_list&amp;#91;0].gp_value<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player_obj_list.append(store_obj_list&amp;#91;0])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store_obj_list.remove(store_obj_list&amp;#91;0])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; else:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;NOT ENOUGH GP&quot;)<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; except:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;NO ITEM HERE&quot;) &nbsp; <br \/>\n<br \/>\n&nbsp; &nbsp; try:<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;2&quot;: <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; if player.gp &gt;= store_obj_list&amp;#91;1].gp_value:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;BUYING &quot; + store_obj_list&amp;#91;1].name)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.gp -= store_obj_list&amp;#91;1].gp_value<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player_obj_list.append(store_obj_list&amp;#91;1])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store_obj_list.remove(store_obj_list&amp;#91;1])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; else:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;NOT ENOUGH GP&quot;)<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; except:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;NO ITEM HERE&quot;) &nbsp;<br \/>\n<br \/>\n&nbsp; &nbsp; try:<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;3&quot;: <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; if player.gp &gt;= store_obj_list&amp;#91;2].gp_value:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;BUYING &quot; + store_obj_list&amp;#91;2].name)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.gp -= store_obj_list&amp;#91;2].gp_value<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player_obj_list.append(store_obj_list&amp;#91;2])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; store_obj_list.remove(store_obj_list&amp;#91;2])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; else:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(&quot;NOT ENOUGH GP&quot;)<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; except:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;NO ITEM HERE&quot;) &nbsp;<br \/>\n<br \/>\n<br \/>\n<br \/>\n&nbsp; def sell(self,player,store_obj_list,player_obj_list):<br \/>\n&nbsp; &nbsp; print(player.name + &quot; IS SELLING&quot;)<br \/>\n<br \/>\n&nbsp; &nbsp; i = 0<br \/>\n&nbsp; &nbsp; for obj in player_obj_list: &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; i += 1<br \/>\n&nbsp; &nbsp; &nbsp; print(str(i) + &quot; &quot; + obj.name + &quot; &quot; + str(obj.gp_value) + &quot; GP&quot;)<br \/>\n<br \/>\n&nbsp; &nbsp; print(&quot;SELL WHICH NUMBER 1-&quot; + str(len(player_obj_list)))<br \/>\n<br \/>\n&nbsp; &nbsp; user_input = player.user_input()<br \/>\n&nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; try:<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;1&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;SELLING &quot; + player_obj_list&amp;#91;0].name )<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(player.name + &quot; GETS &quot; + str(player_obj_list&amp;#91;0].gp_value * .70) + &quot; GP&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; player.gp += player_obj_list&amp;#91;0].gp_value * .70<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; store_obj_list.append(player_obj_list&amp;#91;0])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; player_obj_list.remove(player_obj_list&amp;#91;0])<br \/>\n<br \/>\n&nbsp; &nbsp; except:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;NO ITEM HERE&quot;)<br \/>\n<br \/>\n&nbsp; &nbsp; try:<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;2&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;SELLING &quot; + player_obj_list&amp;#91;1].name )<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(player.name + &quot; GETS &quot; + str(player_obj_list&amp;#91;1].gp_value * .70) + &quot; GP&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; player.gp += player_obj_list&amp;#91;1].gp_value * .70<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; store_obj_list.append(player_obj_list&amp;#91;1])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; player_obj_list.remove(player_obj_list&amp;#91;1])<br \/>\n<br \/>\n&nbsp; &nbsp; except:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;NO ITEM HERE&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; try:<br \/>\n&nbsp; &nbsp; &nbsp; if user_input == &quot;3&quot;:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(&quot;SELLING &quot; + player_obj_list&amp;#91;2].name )<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; print(player.name + &quot; GETS &quot; + str(player_obj_list&amp;#91;2].gp_value * .70) + &quot; GP&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; player.gp += player_obj_list&amp;#91;2].gp_value * .70<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; store_obj_list.append(player_obj_list&amp;#91;2])<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; player_obj_list.remove(player_obj_list&amp;#91;2])<br \/>\n<br \/>\n&nbsp; &nbsp; except:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;NO ITEM HERE&quot;)<br \/>\n<br \/>\nstore = Store(1,0,player,&amp;#91;gem,gem,gem],&amp;#91;],&amp;#91;])<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n\n\n\n<p>We also need to add our store to the Game grid rooms list.  Then we implement some basic error handling so our game wont crash when we leave our store since there wont be enemies in the store unless a random encounter triggers.   The try Python method just &#8220;tries&#8221; to execute the enemy for loop in that particular room.  If it can&#8217;t then the except Python method is called.  This pass&#8217;s (same as breaks ?)<\/p>\n\n\n\n<pre class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/><\/div><\/td><td><div class=\"text codecolorer\">&nbsp; def grid(self,player):<br \/>\n&nbsp; &nbsp; rooms = &amp;#91;start_room,peon_room,gem_room,store]<br \/>\n<br \/>\n&nbsp; &nbsp; ########################################<br \/>\n&nbsp; &nbsp; #player.status()<br \/>\n&nbsp; &nbsp; #self.options(player,rooms)<br \/>\n&nbsp; &nbsp; ########################################<br \/>\n<br \/>\n&nbsp; &nbsp; player.status()<br \/>\n&nbsp; &nbsp; self.options(player)<br \/>\n<br \/>\n&nbsp; &nbsp; for room in rooms:<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; if player.pos_x == room.pos_x and player.pos_y == room.pos_y:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; room.status()<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; player.inventory(room)<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; try:<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for enemy in room.enemies:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; enemy.pos_x = room.pos_x<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; enemy.pos_y = room.pos_y<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if enemy.pos_x == player.pos_x and enemy.pos_y == player.pos_y:<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.battle(player,enemy)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ### &nbsp; QUE ENEMY FREE ON 0 HP &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if enemy.hp &amp;lt;=0:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; enemy.queue_free(enemy,room)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; except:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Quest Class:<\/h2>\n\n\n\n<p>Lets also add quest capability  to our game.   This is also similar to the Room class but for the scope of this tutorial we are writing a new class instead of inheriting or using super classes.    We will create two new classes below.  A Quest and a Quest_Ender class.<\/p>\n\n\n\n<pre class=\"wp-block-code\">\n\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/>46<br \/>47<br \/>48<br \/>49<br \/>50<br \/>51<br \/>52<br \/>53<br \/>54<br \/>55<br \/>56<br \/>57<br \/>58<br \/>59<br \/>60<br \/>61<br \/>62<br \/>63<br \/>64<br \/>65<br \/>66<br \/>67<br \/>68<br \/>69<br \/>70<br \/>71<br \/>72<br \/>73<br \/>74<br \/>75<br \/>76<br \/>77<br \/>78<br \/>79<br \/>80<br \/>81<br \/>82<br \/>83<br \/>84<br \/>85<br \/>86<br \/>87<br \/>88<br \/><\/div><\/td><td><div class=\"text codecolorer\">from Player import *<br \/>\nfrom Character import *<br \/>\nfrom Item import *<br \/>\n<br \/>\nclass Quest():<br \/>\n&nbsp; def __init__(self,name,desc,pos_x,pos_y,npcs,enemies,items,weapons,armors,ender):<br \/>\n&nbsp; &nbsp; self.name = name<br \/>\n&nbsp; &nbsp; self.desc = desc<br \/>\n&nbsp; &nbsp; self.pos_x = pos_x<br \/>\n&nbsp; &nbsp; self.pos_y = pos_y<br \/>\n&nbsp; &nbsp; self.npcs = npcs<br \/>\n&nbsp; &nbsp; self.enemies = enemies<br \/>\n&nbsp; &nbsp; self.items = items<br \/>\n&nbsp; &nbsp; self.armors = armors<br \/>\n&nbsp; &nbsp; self.weapons = weapons<br \/>\n&nbsp; &nbsp; self.ender = ender<br \/>\n&nbsp; &nbsp; #self.complete = False<br \/>\n<br \/>\n&nbsp; def status(self):<br \/>\n&nbsp; &nbsp; print(self.name)<br \/>\n&nbsp; &nbsp; print(self.desc)<br \/>\n&nbsp; &nbsp; print(&quot;QUEST X: &quot; + str(self.pos_x))<br \/>\n&nbsp; &nbsp; print(&quot;QUEST Y: &quot; + str(self.pos_y))<br \/>\n<br \/>\n<br \/>\n&nbsp; &nbsp; if self.ender.quest_ended == False:<br \/>\n&nbsp; &nbsp; &nbsp; self.uncompleted()<br \/>\n&nbsp; &nbsp; else:<br \/>\n&nbsp; &nbsp; &nbsp; self.completed()<br \/>\n<br \/>\n&nbsp; &nbsp; print(&quot;YOU SEE:&quot;)<br \/>\n&nbsp; &nbsp; for npc in self.npcs:<br \/>\n&nbsp; &nbsp; &nbsp; print(npc.name)<br \/>\n&nbsp; &nbsp; for enemy in self.enemies:<br \/>\n&nbsp; &nbsp; &nbsp; print(enemy.name)<br \/>\n&nbsp; &nbsp; for item in self.items:<br \/>\n&nbsp; &nbsp; &nbsp; print(item.name)<br \/>\n&nbsp; &nbsp; for weapon in self.weapons:<br \/>\n&nbsp; &nbsp; &nbsp; print(weapon.name)<br \/>\n&nbsp; &nbsp; for armor in self.armors:<br \/>\n&nbsp; &nbsp; &nbsp; print(armor.name)<br \/>\n&nbsp; &nbsp; <br \/>\n<br \/>\n&nbsp; def uncompleted(self):<br \/>\n&nbsp; &nbsp; print(&quot;QUEST STARTS HERE AND IS NOT COMPLETED&quot;)<br \/>\n<br \/>\n&nbsp; def completed(self):<br \/>\n&nbsp; &nbsp; print(&quot;QUEST IS COMPLETED&quot;)<br \/>\n<br \/>\n<br \/>\n<br \/>\nclass Quest_Ender():<br \/>\n&nbsp; def __init__(self,name,desc,pos_x,pos_y,npcs,enemies,items,armors,weapons):<br \/>\n&nbsp; &nbsp; self.name = name<br \/>\n&nbsp; &nbsp; self.desc = desc<br \/>\n&nbsp; &nbsp; self.pos_x = pos_x<br \/>\n&nbsp; &nbsp; self.pos_y = pos_y<br \/>\n&nbsp; &nbsp; self.npcs = npcs<br \/>\n&nbsp; &nbsp; self.enemies = enemies<br \/>\n&nbsp; &nbsp; self.items = items<br \/>\n&nbsp; &nbsp; self.armors = armors<br \/>\n&nbsp; &nbsp; self.weapons = weapons<br \/>\n&nbsp; &nbsp; self.quest_ended = False<br \/>\n<br \/>\n&nbsp; def status(self):<br \/>\n&nbsp; &nbsp; print(&quot;YOU SEE:&quot;)<br \/>\n&nbsp; &nbsp; for npc in self.npcs:<br \/>\n&nbsp; &nbsp; &nbsp; print(npc.name)<br \/>\n&nbsp; &nbsp; for enemy in self.enemies:<br \/>\n&nbsp; &nbsp; &nbsp; print(enemy.name)<br \/>\n&nbsp; &nbsp; for item in self.items:<br \/>\n&nbsp; &nbsp; &nbsp; print(item.name)<br \/>\n&nbsp; &nbsp; for weapon in self.weapons:<br \/>\n&nbsp; &nbsp; &nbsp; print(weapon.name)<br \/>\n&nbsp; &nbsp; for armor in self.armors:<br \/>\n&nbsp; &nbsp; &nbsp; print(armor.name)<br \/>\n<br \/>\n&nbsp; &nbsp; if len(self.enemies) == 0:<br \/>\n&nbsp; &nbsp; &nbsp; print(&quot;PLAYER HAS COMPLETED THE QUEST&quot;)<br \/>\n&nbsp; &nbsp; &nbsp; self.quest_ended = True<br \/>\n<br \/>\n<br \/>\n### QUEST ENDERS &nbsp; &nbsp;name,desc,pos_x,pos_y,npcs,enemies,items,armors,weapons<br \/>\nquest_1_ender = Quest_Ender(&quot;QUEST 1 ENDER&quot;,&quot;THIS ENDS QUEST 1&quot;,3,0,&amp;#91;],&amp;#91;orc_peon],&amp;#91;],&amp;#91;],&amp;#91;])<br \/>\n<br \/>\n### &nbsp;QUESTS<br \/>\n### &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;name,desc,pos_x,pos_y,npcs,enemies,items,weapons,armors,ender<br \/>\nquest_1 = Quest(&quot;QUEST 1&quot;,&quot;THIS IS QUEST ONE&quot;,2,0,&amp;#91;],&amp;#91;],&amp;#91;],&amp;#91;],&amp;#91;],quest_1_ender)<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>First a little house cleaning. We need to update our Players inventory drop function. Let&#8217;s add that in now. Add this to the Player class in the Player.py file. We are updating our nested function within our inventory method. We are doing the same thing we did with items. We just change the Player&#8217;s \/ Room&#8217;s object list to remove \/ append from the weapon and armors lists respectively. Then, the Player can&#8217;t &#8220;die&#8221; in game. Without risk their can be no reward. So, lets add a que_free method to&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-597","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/posts\/597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/comments?post=597"}],"version-history":[{"count":4,"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/posts\/597\/revisions"}],"predecessor-version":[{"id":617,"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/posts\/597\/revisions\/617"}],"wp:attachment":[{"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/media?parent=597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/categories?post=597"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mipython.magwebdesigns.net\/WP\/wp-json\/wp\/v2\/tags?post=597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}