Okay, I am writing a dopewars clone/wannabe in python. I have it pretty much the way I want it, except that selling items does not work. Buying them does fine, it is just selling them.
Here is the code:
#!/usr/bin/env python
#
# pimp.py
#
# @authors: KarimRuan,
# Copyright 2009
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import sys, os
import random
global cash
cash = 500
global dealers
dealers = 2
global hp
hp = 25
global gang
gang = 1
global guns
guns = 0
global thugHP
thugHP = 20
def la_prompt():
print """COMING SOON"""
return
def la():
clear()
global cash, dealers, hp, gang
print "CASH: ", cash, "dealers: ", dealers, "HP: ", hp, "GANG MEMBERS: ", gang
print
print 'you are in Los Angelos.'
print
print 'Rictor sells GUNS. Use "trade guns". Ace sells DEALERS. use "buy DEALERS".'
print 'You should tell your dealers "dealers work".'
print "You can also go : cleveland, bronxe, NY"
i = random.randrange(1, 5)
if i == 1:
print "2 thugs want to join your gang!"
gang = gang + 2
la_prompt()
elif i == 2:
fight()
la_prompt()
elif i == 3:
print 'You find $500'
cash = cash + 500
la_prompt()
elif i == 4:
cop_fight()
la_prompt()
elif i == 5:
print 'Two dealers want to join your crew.'
dealers = dealers + 2
la_prompt()
else:
print "Error."
la_prompt()
la_prompt()
def foo_sell():
global cash, dealers
clear()
print """\
Sell how many DEALERS?
a. 1 dealer for $50
b. 2 dealers for $100
c. 3 dealers for $150
or:
d. exit
"""
x = raw_input("> ")
if x == 'a':
if dealers > 1:
print "You sell 1 dealer for $50."
dealers = dealers - 1
cash = cash + 50
foo_sell()
else:
print "You do not have enough dealers to sell."
print 'You have ', dealers, ' dealers to sell.'
foo_sell()
elif x == 'b':
if dealers > 2:
print 'You sell 2 dealers for $100.'
dealers = dealers - 2
cash = cash + 100
foo_sell()
else:
print "You do not have enough to sell 2 dealers."
print "You have ", dealers, " dealers to sell."
foo_sell()
elif x == 'c':
if dealers > 3:
print 'You sell 3 dealers for $150.'
dealers = dealers - 3
cash = cash + 150
foo_sell()
else:
print 'You do not have enough to sell 3 dealers.'
print 'You have ', dealers, ' dealers to sell.'
bob_sell()
elif x == 'd':
cleveland()
def foo_buy():
global cash, dealers
print """\
a. buy 1 guns for $100
b. buy 2 dealers for $200
c. buy 3 dealers for $300
d. exit
"""
x = raw_input("> ")
if x == 'a':
if cash < 100:
print "Not enough cash."
foo_buy()
else:
dealers = dealers + 1
cash = cash - 100
foo_buy()
elif x == 'b':
if cash < 200:
print "Not enough cash."
foo_buy()
else:
dealers = dealers + 2
cash = cash - 200
foo_buy()
elif x == 'c':
if cash < 300:
print "Not enough cash."
foo_buy()
else:
dealers = dealers + 3
cash = cash - 300
foo_buy()
elif x == 'd':
cleveland()
def foo_prompt():
x = raw_input("> ")
if x == 'buy dealers':
foo_buy()
elif x == 'sell dealers':
foo_sell()
elif x == 'exit':
cleveland()
else:
print "Not Recognized."
foo_prompt()
def foo_trade():
clear()
global cash, dealers
print "YOUR CASH: ", cash
print "YOUR dealers: ", dealers
print
print """\
YO YO YO, I gots some mad hustlin' dealers for sale. Jus use
'buy dealers'. I can also take some of them dealers off ya hands.
Jus use 'sell dealers'. Use 'exit' to leave my shop.
"""
foo_prompt()
################################################
# BOB TRADING
################################################
def bob_sell():
global cash, guns
clear()
print """\
Sell how many GUNS?
a. 5 guns for $35
b. 10 guns for $75
c. 20 guns for $175
or:
d. exit
"""
x = raw_input("> ")
if x == 'a':
if guns > 5:
print "You sell 5 guns for $35."
guns = guns - 5
cash = cash + 35
bob_sell()
else:
print "You do not have enough guns to sell."
print 'You have ', guns, 'to sell.'
bob_sell()
elif x == 'b':
if guns > 10:
print 'You sell 10 guns for $75.'
guns = guns - 10
cash = cash + 75
bob_sell()
else:
print "You do not have enough to sell 10 guns."
print "You have ", guns, " to sell."
bob_sell()
elif x == 'c':
if guns > 20:
print 'You sell 20 guns for $175.'
guns = guns - 20
cash = cash + 175
bob_sell()
else:
print 'You do not have enough to sell 20 guns.'
print 'You have ', guns, ' to sell.'
bob_sell()
elif x == 'd':
cleveland()
def bob_buy():
global cash, guns
print """\
a. buy 5 guns for $50
b. buy 10 guns for $100
c. buy 20 guns for $200
d. exit
"""
x = raw_input("> ")
if x == 'a':
if cash < 50:
print "Not enough cash."
bob_buy()
else:
guns = guns + 5
cash = cash - 50
bob_buy()
elif x == 'b':
if cash < 100:
print "Not enough cash."
bob_buy()
else:
guns = guns + 10
cash = cash - 100
bob_buy()
elif x == 'c':
if cash < 200:
print "Not enough cash."
bob_buy()
else:
guns = guns + 20
cash = cash - 200
bob_buy()
elif x == 'd':
cleveland()
def bob_prompt():
x = raw_input("> ")
if x == 'buy guns':
bob_buy()
elif x == 'sell guns':
bob_sell()
elif x == 'exit':
cleveland()
else:
print "Not Recognized."
bob_prompt()
def bob_trade():
clear()
global cash, guns
print "YOUR CASH: ", cash
print "YOUR GUNS: ", guns
print
print """\
HI: my name is Bob. Do you want to 'sell guns' or 'buy guns'?
type 'exit' to exit shop.
"""
bob_prompt()
def work_dealers():
global cash
cearn = random.randrange(50, 99)
print "you earned ", cearn, "cash."
cash = cash + cearn
work_dealers
'''
def work_dealers():
global cash
income = random.randint(self, 1, 9)
cash = cash + income
work_dealers()
'''
def clev_income():
work_dealers()
def clev_prompt():
global cash, dealers, hp, gang, thugHP
x = raw_input("> ")
if x == 'dealers work':
clev_income()
clev_prompt()
elif x == 'trade guns':
bob_trade()
clev_prompt()
elif x == 'buy dealers':
foo_trade()
clev_prompt()
elif x == 'go la':
la()
elif x == 'go bronxe':
bronxe()
elif x == 'go ny':
ny()
elif x == 'look':
cleveland()
elif x == 'exit':
sys.exit(0)
else:
print 'Not Recognized.'
clev_prompt()
def cop_fight():
global hp, thugHP, cash
charhp = hp
thughp = thugHP
print """YOU ARE IN A FIGHT!"""
print """\
+++++++++++++++++
+ COP +
+++++++++++++++++
"""
while (hp > 0) and (thugHP > 0):
# player attacks
chardmg = random.randrange(2) + 1
print 'You attack the COP!'
print 'You deal ', chardmg, 'damage'
thugHP -= chardmg
print "YOUR HP: ", hp
print "COP HP: ", thugHP
raw_input()
# thug attacks
thugdmg = random.randrange(1) + 1
print 'The COP attacks you!'
print 'The COP deals ', thugdmg, 'damage to you!'
charhp -= thugdmg
print "Your HP: ", hp
print 'COP HP: ', thugHP
raw_input()
if charhp < 0:
print "The COP killed you."
print "GAME OVER"
gameover()
else:
print "You killed the COP!"
cearn = random.randrange(10, 25)
print "YOU EARNED ", cearn, "CASH!\n"
cash = cash + cearn
return
def fight():
global hp, thugHP, cash
charhp = hp
thughp = thugHP
print """YOU ARE IN A FIGHT!"""
print """\
+++++++++++++++++
+ THUG +
+++++++++++++++++
"""
while (hp > 0) and (thugHP > 0):
# player attacks
chardmg = random.randrange(2) + 1
print 'You attack the thug!'
print 'You deal ', chardmg, 'damage'
thugHP -= chardmg
print "YOUR HP: ", hp
print "THUG HP: ", thugHP
raw_input()
# thug attacks
thugdmg = random.randrange(1) + 1
print 'The thug attacks you!'
print 'The thug deals ', thugdmg, 'damage to you!'
charhp -= thugdmg
print "Your HP: ", hp
print 'Thug HP: ', thugHP
raw_input()
if charhp < 0:
print "The thug killed you."
print "GAME OVER"
gameover()
else:
print "You killed the thug!"
cearn = random.randrange(10, 25)
print "YOU EARNED ", cearn, "CASH!\n"
cash = cash + cearn
return
def cleveland():
clear()
global cash, dealers, hp, gang
print "CASH: ", cash, "dealers: ", dealers, "HP: ", hp, "GANG MEMBERS: ", gang
print
print 'you are in cleveland.'
print
print 'Bob sells GUNS. Use "trade guns". Foo sells DEALERS. use "buy dealers".'
print 'You should tell your dealers "dealers work".'
print "You can also go : la, bronxe, NY"
i = random.randrange(1, 5)
if i == 1:
print "2 thugs want to join your gang!"
gang = gang + 2
clev_prompt()
elif i == 2:
fight()
clev_prompt()
elif i == 3:
print 'You find $50'
cash = cash + 50
clev_prompt()
elif i == 4:
cop_fight()
clev_prompt()
elif i == 5:
print 'Two dealers want to join your crew.'
dealers = dealers + 2
clev_prompt()
else:
print "Error."
clev_prompt()
clev_prompt()
def game():
cleveland()
la()
# bronxe() TODO
# ny() TODO
def menu_prompt():
x = raw_input("> ")
if x == 'a':
clear()
game()
elif x == 'b':
clear()
loadgame()
elif x == 'c':
clear()
credits()
else:
print "THAT IS NOT A VALID OPTION."
menu_prompt()
def clear():
print """
"""
def menu():
clear()
print """\
++ ++ ++ ++ + + ++ ++ ++++++ + + + +
+ + + + + ++ + + + + + + + + + + + +
+ + ++++ ++ + + + + + +++ + + + + +
+ + + + ++ + ++ + + ++++++ + ++ ++++
A: PLAY NEW GAME
B: LOAD GAME (COMING SOON)
C: CREDITS (COMING SOON)
"""
menu_prompt()
def main():
print """\
++++ + ++ ++ ++++ + + + +++++ +++++
++++ + + + + ++++ + + + +++ +++++ +
+ + + + + + + + + + + +++++
+ +
+ BY: KARIMRUAN +++++
"""
raw_input()
menu()
main()
Any help would be greatly appreciated! I also attached the .py incase it is easier to test it without having to delete line numbers.