__author__ = 'Perkel'
import random
import os
# Menu dictionaries
main_menu_list = {'new game': 1,
'quit': 4}
game_option_list = {'move': 1,
'check place': 2,
'combat': 3,
'inventory': 4,
'player stats': 5,
'merchant': 6,
'quit': 7}
cheats_list = {'+100 health': 1,
'go to menu': 2}
combat_actions_list = {'attack': 1,
'inventory': 2,
'enemy description': 3,
'run': 4}
inventory_list = {'equip': 1,
'quit': 2}
vendor_options = {'buy': 1,
'sell': 2,
'quit': 3}
citi_names = ['the new camp', 'the orchard', 'junktown', 'the glow', 'los capri', 'zandara', 'roxenfurt']
village_names = ['sandy place', 'old scrapyard', 'cows pen', 'roccoti', 'windhill', 'shady sands', 'trek']
base_names = ['siera tin', 'pudric fort', 'spike fort', 'west fortifications']
other_names = ['sulfur cave', 'deep cave', 'old ranch', 'dirty shack', 'shady shack', 'west gas station']
cities = random.randint(1, 2)
villages = random.randint(3, 5)
bases = random.randint(1, 2)
others = random.randint(3, 5)
newplace = 0
enemyname1 = ['dirty', 'old', 'young', 'hungry', 'fat', 'strong', 'crazy', 'hard']
enemyname2 = ['beggar', 'raider', 'bandit', 'thief', 'scavenger']
sexchoice = ['woman', 'man']
# weapon - name - type - price - min_damage - max_damage
melee_weapons = [['knife', 'melee', 35, 3, 5],
['combat knife', 'melee', 60, 4, 7],
['steel pipe', 'melee', 45, 5, 6],
['crowbar', 'melee', 90, 5, 9],
['baseball bat', 'melee', 120, 6, 8],
['fork', 'melee', 10, 1, 3],
['wooden stick', 'melee', 5, 1, 6]]
# weapon - name - type - bullet_type - magazine_size - price - damage_min - damage_max - number_of_attacks_per_use
range_weapons = [['9mm pistol', 'gun', '9mm bullet', 10, 150, 5, 7, 1],
['9mm sub-machine gun', 'gun', '9mm bullet', 25, 400, 3, 5, 5],
['9mm home-made pistol','gun', '9mm bullet', 5, 80, 2, 7, 1],
['20Ga home-made shotgun', 'gun', '20Ga shell', 1, 230, 10, 20, 1],
['20Ga shotgun', 'gun', '20Ga shell', 2, 950, 15, 30, 1]]
# bullet - name - type - damage_multiplier - piercing_power
bullets = [['9mm bullet', '9mm bullet', 1, 1],
['9mm surplus bullet', '9mm bullet', 0.90, 1],
['9mm P+ bullet', '9mm bullet', 1, 0.5],
['20Ga shell', '20Ga shell', 1, 1]]
armor = {'plain clothes': 0,
'leather armor': 3,
'metal armor': 5,
'combat armor': 7}
main_loop = True
game_loop = False
gameplay_loop = False
cheats = False
player_turn = False
vendor_loop = False
inventory_loop = False
choice = ""
player1 = ""
enemies = []
new_enemy = 0
# COMBAT VARS
turn_list = []
def combat():
turn_list.append(player1)
for enemy in player1.current.enemies:
x = enemy
turn_list.append(x)
turn_list.sort(key=lambda z: z.initiative, reverse=True)
count = 1
dead_enemies = 0
while len(turn_list) > 1 and player1 in turn_list:
clrscreen()
print
print "==== TURN ", count, " ===="
print
for character in turn_list:
if character == player1 and player1 in turn_list:
player1.player_turn = True
while player1.player_turn is True:
print "actions:"
print_options(combat_actions_list)
choice_1 = raw_input()
if choice_1 in combat_actions_list:
if choice_1 == 'attack':
player1.enemy_desc = True
while player1.enemy_desc is True:
clrscreen()
print "enemies:"
print
for enemy in player1.current.enemies:
print enemy.name, " - ", "%d|%d" % (enemy.health, enemy.maxhealth)
print
choice_1 = raw_input()
for enemy in player1.current.enemies:
if enemy.name == choice_1:
combat_attack(player1, enemy)
if enemy.health <= 0:
turn_list.remove(enemy)
player1.current.enemies.remove(enemy)
dead_enemies += 1
player1.enemy_desc = False
player1.player_turn = False
elif choice_1 == 'inventory':
clrscreen()
player1.inv()
raw_input()
elif choice_1 == 'enemy description':
clrscreen()
print "enemies:"
print
for player_enemy in player1.current.enemies:
print player_enemy.name, " - ", "%d|%d" % (player_enemy.health, player_enemy.maxhealth)
print
raw_input()
elif choice_1 == 'run':
clrscreen()
player1.player_turn = False
for x in turn_list:
turn_list.remove(x)
print " you are running away from battle"
raw_input()
break
else:
clrscreen()
pass
else:
combat_attack(character, player1)
if player1.health <= 0:
for x in turn_list:
turn_list.remove(x)
count += 1
clrscreen()
print " ============= "
print " Combat ended "
print " ============= "
experience_gained = dead_enemies * 10
money_gained = dead_enemies * random.randint(2, 9)
player1.experience += experience_gained
player1.money += money_gained
print " experience gained: ", experience_gained, "exp"
print " money found: ", money_gained, "$"
raw_input()
def combat_attack(character_1, character_2):
# hit chance
hit_chance = random.randint(1, 20)
if character_1.weapon.weapon_type == "gun":
if hit_chance <= (character_1.pre * 2) + 5 - int(character_2.agl / 2):
clrscreen()
damage = 0
for x in range(0, character_1.weapon.attacks):
cur_damage = int(random.randint(character_1.weapon.min_damage, character_1.weapon.max_damage) - character_2.armor.armor)
damage += cur_damage
print character_1.name, " shoots ", character_2.name,\
" for ", cur_damage, " points of damage"
raw_input()
character_2.health -= int(damage)
print character_2.name, " health: ", "%d|%d" % (character_2.health, character_2.maxhealth)
raw_input()
else:
clrscreen()
print character_1.name, " misses"
raw_input()
elif character_1.weapon.weapon_type == "melee":
if hit_chance <= (character_1.agl * 2) + 5 - int(character_2.agl / 2):
clrscreen()
damage = 0
for x in range(0, character_1.weapon.attacks):
cur_damage = int(random.randint(character_1.weapon.min_damage, character_1.weapon.max_damage) + (character_1.str / 2) - character_2.armor.armor)
damage += cur_damage
print character_1.name, " strikes ", character_2.name,\
" for ", cur_damage, " points of damage"
raw_input()
character_2.health -= damage
print character_2.name, " health: ", "%d|%d" % (character_2.health, character_2.maxhealth)
raw_input()
else:
clrscreen()
print character_1.name, " misses"
raw_input()
def print_options(option_dict):
print
for option in sorted(option_dict.items(), key=lambda option_1: option_1[1]):
print " ", option[0]
print
def print_places(places_list):
print
places.sort(key=lambda class_object: class_object.size, reverse=True)
for x in places_list:
print x.type, " " * (7 - len(x.type)), "- ", x.name
def print_bullets(bullet_list):
bullets_types = {}
for x in bullet_list:
if x.name not in bullets_types:
bullets_types[x.name] = 1
else:
bullets_types[x.name] += 1
bullet_vendor_list = []
for key, value in bullets_types.iteritems():
temp = [key, value]
bullet_vendor_list.append(temp)
for x in sorted(bullet_vendor_list):
print " ", x[1], " " * (2 - len(str(x[1]))), "-", x[0]
def clrscreen():
if os.name in ("nt", "dos"):
os.system('CLS')
else:
for position in range(49):
print ""
def cur():
print
print "=" * (10 + len(player1.current.name))
print "==== %s ====" % player1.current.name
print "=" * (10 + len(player1.current.name))
def welcome_screen():
print
print "You are currently standing in your shack asking yourself different questions about future."
print "Calculating your chance to live here you finally decided that this is no place where you can live safely."
print "You decided that you need to move away from here. Problem is that you don't have supplies for it"
print "After a while you calculated you will need at least 1200 pesters to buy enough supplies to reach"
print "other safer zone"
raw_input()
def the_glow_scr():
print "============ THE GLOW ==============="
print "====================================="
print
print_options(main_menu_list)
def world_gen():
placesx = []
for number in range(0, cities):
new_place = PlaceCity()
placesx.append(new_place)
for number in range(0, villages):
new_place = PlaceVillage()
placesx.append(new_place)
for number in range(0, bases):
new_place = PlaceBase()
placesx.append(new_place)
for number in range(0, others):
new_place = PlaceOther()
placesx.append(new_place)
return placesx
def buy(player, merchant):
choice_buy = raw_input("make a choice:")
for x in merchant.weapon_list:
if x.name == choice_buy:
if player.money < x.price:
print " to expensive for me - ", x.price, "$", "my money:", player.money
raw_input()
else:
player.inventory.append(x)
player.money -= x.price
print x.name, "bought"
raw_input()
def sell(player, merchant):
choice_sell = raw_input("make a choice:")
for x in player.inventory:
if x.name == choice_sell:
if merchant.money < x.price:
print "too expensive for merchant"
raw_input()
else:
merchant.weapon_list.append(x)
player.inventory.remove(x)
player.money += x.price
merchant.money -= x.price
print x.name, "sold"
raw_input()
class PlaceCity(object):
def __init__(self):
self.name = random.choice(citi_names)
citi_names.remove(self.name)
self.vendor = True
self.type = "city"
self.size = 5
class PlaceVillage(object):
def __init__(self):
self.name = random.choice(village_names)
village_names.remove(self.name)
self.enemies_count = random.randint(1, 5)
self.enemies = []
self.type = "village"
for number in range(self.enemies_count):
new_enemy_1 = Enemy()
self.enemies.append(new_enemy_1)
self.size = 2
class PlaceBase(object):
def __init__(self):
self.name = random.choice(base_names)
base_names.remove(self.name)
self.enemies_count = random.randint(5, 10)
self.enemies = []
self.type = "base"
for number in range(self.enemies_count):
new_enemy_1 = Enemy()
self.enemies.append(new_enemy_1)
self.size = 3
class PlaceOther(object):
def __init__(self):
self.name = random.choice(other_names)
other_names.remove(self.name)
self.enemies_count = random.randint(0, 4)
self.enemies = []
self.type = "other"
for number in range(self.enemies_count):
new_enemy_1 = Enemy()
self.enemies.append(new_enemy_1)
self.size = 1
class Weapon(object):
def __init__(self, weapon_name, weapon_damage, weapon_type):
self.name = weapon_name
self.damage = weapon_damage
self.weapon_type = weapon_type
class WeaponRange(object):
def __init__(self, name, weapon_type, bullet_type, mag_size, price, min_damage, max_damage, attacks):
self.name = name
self.weapon_type = weapon_type
self.bullet_type = bullet_type
self.price = price
self.min_damage = min_damage
self.max_damage = max_damage
self.attacks = attacks
self.mag_size = mag_size
self.mag_current = []
def description(self):
clrscreen()
print
print " === ", self.name, "=== "
print " ", "type : ", self.weapon_type
print " ", "bullet type : ", self.bullet_type
print " ", "mag size : ", self.mag_size
print " ", "damage : ", "%d x %d-%d" % (self.attacks, self.min_damage, self.max_damage)
print " ", "base price : ", self.price
print
raw_input()
class WeaponMelee(object):
def __init__(self, name, weapon_type, price, min_damage, max_damage):
self.name = name
self.price = price
self.weapon_type = weapon_type
self.attacks = 1
self.min_damage = min_damage
self.max_damage = max_damage
def description(self):
clrscreen()
print
print " === ", self.name, "=== "
print " ", "type : ", self.weapon_type
print " ", "damage : ", "%d-%d" % (self.min_damage, self.max_damage)
print " ", "base price : ", self.price
print
raw_input()
class Armor(object):
def __init__(self, name, armor_value):
self.name = name
self.armor = armor_value
class Bullet(object):
def __init__(self, name, bullet_type, damage_modifier, piercing_power):
self.name = name
self.bullet_type = bullet_type
self.damage_modifier = damage_modifier
self.piercing_power = piercing_power
class Player(object):
def __init__(self):
self.lvl = 1
self.experience = 0
self.name = raw_input("CHARACTER NAME: ")
clrscreen()
self.age = raw_input("CHARACTER AGE: ")
clrscreen()
self.sex = raw_input("CHARACTER SEX: ")
clrscreen()
self.str = random.randint(1, 5)
self.pre = random.randint(1, 5)
self.end = random.randint(1, 5)
self.agl = random.randint(1, 5)
self.initiative = (self.lvl * 5) + self.pre * 5
# debug self.maxhealth = 10
self.maxhealth = (self.lvl * 10) + 5 + self.end * 10 + self.str * 5
self.health = self.maxhealth
self.current = random.choice(places)
self.player_turn = False
self.enemy_desc = False
self.money = random.randint(300, 500)
self.weapon = WeaponRange('9mm pistol', 'gun', '9mm bullet', 10, 150, 5, 7, 1)
self.armor = Armor("plain clothes", 0)
self.inventory = []
def desc(self):
print
print "================="
print " NAME : %s" % self.name
print " AGE : %s" % self.age
print " SEX : %s" % self.sex
print "-----------------"
print " HEALTH : %d|%d" % (self.health, self.maxhealth)
print " STRENGTH : %s" % self.str
print " ENDURANCE : %s" % self.end
print " PRECISION : %s" % self.pre
print " AGILITY : %s" % self.agl
print "================="
print " EXPERIENCE: %dexp" % self.experience
print " LEVEL : %d" % self.lvl
def inv(self):
print
print "================="
print " WEAPON : ", self.weapon.name
print " ARMOR : ", self.armor.name
print "-----------------"
print "inventory:"
if len(self.inventory) > 0:
print
for item in self.inventory:
print " ", item.name
print
else:
print
print " EMPTY "
print
print "================="
print " MONEY : %d$" % self.money
print "================="
def equip(self):
equip_choice = raw_input("what item ?: ")
for x in self.inventory:
if x.name == equip_choice:
self.inventory.append(self.weapon)
self.weapon = x
self.inventory.remove(x)
return False
else:
pass
class Enemy(object):
def __init__(self):
self.name = random.choice(enemyname1) + " " + random.choice(enemyname2)
self.lvl = 1
self.age = random.randint(20, 40)
self.sex = random.choice(sexchoice)
self.str = random.randint(1, 5)
self.pre = random.randint(1, 5)
self.end = random.randint(1, 5)
self.agl = random.randint(1, 5)
self.initiative = (self.lvl * 5) + self.pre * 5
self.maxhealth = (self.lvl * 10) + self.end * 10 + self.str * 5
self.health = self.maxhealth
self.money = random.randint(1, 50)
self.weapon = WeaponMelee('knife', 'melee', 35, 3, 5)
self.armor = Armor('plain clothes', 0)
self.inventory = [self.weapon, self.armor]
def desc(self):
print
print "================="
print " NAME : %s" % self.name
print " AGE : %s" % self.age
print " SEX : %s" % self.sex
print "-----------------"
print " STRENGTH : %s" % self.str
print " ENDURANCE : %s" % self.end
print " PRECISION : %s" % self.pre
print " AGILITY : %s" % self.agl
print "================="
print
def inv(self):
print
print "================="
print " WEAPON : ", self.weapon.name
print " ARMOR : ", self.armor.name
print "-----------------"
print "inventory:"
if len(self.inventory) > 0:
print
for item in self.inventory:
print " ", item
print
else:
print
print " EMPTY "
print
print "================="
class Merchant(object):
def __init__(self):
amount_of_weapons = player1.current.size * random.randint(1, 4)
amount_of_ammo = player1.current.size * random.randint(30, 100)
amount_of_food = player1.current.size * random.randint(5,10)
amount_of_drugs = player1.current.size * random.randint(3, 5)
amount_of_money = player1.current.size * random.randint(100, 500)
self.name = "zozek"
self.weapon_list = []
self.ammo_list = []
self.food_list = []
self.drugs_list = []
self.money = amount_of_money
for x in range(0, amount_of_ammo):
bullet = random.choice(bullets)
self.ammo_list.append(Bullet(bullet[0], bullet[1], bullet[2], bullet[3]))
for x in range(0, amount_of_weapons):
cat_choice = random.choice(sexchoice)
if cat_choice == 'man':
weapon = random.choice(range_weapons)
self.weapon_list.append(WeaponRange(weapon[0], weapon[1], weapon[2], weapon[3], weapon[4], weapon[5], weapon[6], weapon[7]))
else:
weapon = random.choice(melee_weapons)
self.weapon_list.append(WeaponMelee(weapon[0], weapon[1], weapon[2], weapon[3], weapon[4]))
def inventory(self):
clrscreen()
print
print "Hi my name is ", self.name
print len(self.weapon_list), " weapons"
print len(self.ammo_list), " bullets"
print self.money, " money"
print
raw_input()
def print_weapons(self):
clrscreen()
weapon_gun_list = []
weapon_melee_list = []
for x in self.weapon_list:
if x.weapon_type == 'gun':
weapon_gun_list.append(x)
else:
weapon_melee_list.append(x)
weapon_gun_list.sort(key=lambda class_object: class_object.name, reverse=True)
weapon_melee_list.sort(key=lambda class_object: class_object.name, reverse=True)
print "=MERCHANT="
print
print "===GUNS==="
for x in weapon_gun_list:
print " ", x.name, " - ", "%d$" % x.price, " - ", "%d x %d-%d" % (x.attacks, x.min_damage, x.max_damage)
print "===MELEE=="
for x in weapon_melee_list:
print " ", x.name, " - ", "%d$" % x.price, " - ", "%d-%d" % (x.min_damage, x.max_damage)
self.ammo_list.sort(key=lambda class_object: class_object.bullet_type, reverse=True)
# TODO MAKE BULLETS COUNT
# variable that will count different types of bullets
print "=BULLETS="
print_bullets(self.ammo_list)
print "=========="
raw_input()
# MAIN LOOP // MAIN MENU #######################################
# MAIN MENU LOOP START ########################################
while main_loop is True:
the_glow_scr()
print
choice = raw_input()
clrscreen()
if choice == 'new game':
welcome_screen()
places = world_gen()
player1 = Player()
player1.desc()
print
raw_input("press any key to continue")
if 'continue' in main_menu_list:
game_loop = True
else:
main_menu_list['continue'] = 2
main_menu_list['cheats'] = 3
game_loop = True
elif choice == 'continue':
game_loop = True
elif choice == 'cheats':
cheats = True
elif choice == 'quit':
clrscreen()
break
else:
print
clrscreen()
# MAIN MENU LOOP END ########################################
# GAME LOOP START ##########################################
while game_loop is True:
if player1.health <= 0:
clrscreen()
print " You are dead as fuck"
raw_input()
break
clrscreen()
cur()
print_options(game_option_list)
print
choice = raw_input()
if choice in game_option_list:
if choice == "move":
clrscreen()
print "Where :"
print_places(places)
print
choice = raw_input()
for place in places:
if choice == place.name:
player1.current = place
clrscreen()
elif choice == "check place":
clrscreen()
print "Enemies"
for enemy_l in player1.current.enemies:
print " ", enemy_l.name, " - ", enemy_l.sex, " ", enemy_l.armor.name, enemy_l.weapon.name
print
raw_input()
elif choice == 'combat':
if len(player1.current.enemies) > 0:
clrscreen()
combat()
else:
clrscreen()
print " NO ENEMY TO FIGHT"
raw_input()
elif choice == "inventory":
inventory_loop = True
while inventory_loop is True:
clrscreen()
player1.inv()
print_options(inventory_list)
choice = raw_input()
if choice == "equip":
player1.inv()
player1.equip()
elif choice == "quit":
inventory_loop = False
else:
pass
pass
elif choice == "player stats":
clrscreen()
player1.desc()
raw_input()
elif choice == "merchant":
vendor_loop = True
while vendor_loop is True:
player1.current.vendor = Merchant()
player1.current.vendor.inventory()
player1.current.vendor.print_weapons()
raw_input()
print
print_options(vendor_options)
choice = raw_input()
if choice == "quit":
vendor_loop = False
elif choice == "buy":
buy(player1, player1.current.vendor)
elif choice == "sell":
sell(player1, player1.current.vendor)
else:
pass
elif choice == "quit":
game_loop = False
clrscreen()
else:
clrscreen()
else:
clrscreen()
# GAME LOOP END #################################################
# CHEATS LOOP
while cheats is True:
clrscreen()
print_options(cheats_list)
print
choice = raw_input()
if choice == '+100 health':
player1.health += 100
clrscreen()
elif choice == 'go to menu':
cheats = False
else:
clrscreen()
# CHEATS LOOP END ##############################################