Burning Bridges
Enviado de meu SM-G3502T usando Tapatalk
You're making progress. Your procedural generation is almost as good as Oblivion's.
import random
import os
# Manu dictionaries
main_menu_list = {'new game': 1,
'quit': 4}
game_option_list = {'move': 1,
'inventory': 2,
'player stats': 3,
'merchant': 4,
'quit': 5}
cheats_list = {'+100 health': 1,
'go to menu': 2}
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']
weapons = {'piece of glass': 3,
'knife' : 5,
'wooden stick' : 6,
'machete' : 10,
'pistol' : 15,
'machine gun' : 30}
armor = {'plain clothes' : 0,
'leather armor' : 3,
'metal armor' : 5,
'combat armor' : 7}
main_loop = True
game_loop = False
gameplay_loop = False
cheats = False
choice = ""
player1 = ""
enemies = []
new_enemy = 0
enemy1 = ""
enemy2 = ""
enemy3 = ""
def inpc():
print
print " - your choice - "
x = raw_input()
print
return x
def print_options(option_dict):
print
for option in sorted(option_dict.items(), key=lambda x: x[1]):
print " ", option[0]
def print_places(places_list):
print
places.sort(key=lambda x: x.size)
for place in places:
print " ", place.name, " - ", place.type
def clrscreen():
if os.name in ("nt", "dos"):
os.system('CLS')
else:
for x in range(49):
print ""
def cur():
print
print "=" * (10 + len(player1.current))
print "==== %s ====" % player1.current
print "=" * (10 + len(player1.current))
def wlcdescscreen():
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 theglowscr():
print "============ THE GLOW ==============="
print "====================================="
print
print_options(main_menu_list)
def worldgen():
placesx = []
for x in range(0, cities):
newplace = PlaceCity()
placesx.append(newplace)
for x in range(0, villages):
newplace = PlaceVillage()
placesx.append(newplace)
for x in range(0, bases):
newplace = PlaceBase()
placesx.append(newplace)
for x in range(0, others):
newplace = PlaceOther()
placesx.append(newplace)
return placesx
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 x in range(self.enemies_count):
new_enemy = Enemy()
self.enemies.append(new_enemy)
self.size = 2
class PlaceBase(object):
def __init__(self):
self.name = random.choice(base_names)
village_names.remove(self.name)
self.enemies_count = random.randint(5, 10)
self.enemies = []
self.type = "base"
for x in range(self.enemies_count):
new_enemy = Enemy()
self.enemies.append(new_enemy)
self.size = 3
class PlaceOther(object):
def __init__(self):
self.name = random.choice(other_names)
village_names.remove(self.name)
self.enemies_count = random.randint(0, 4)
self.enemies = []
self.type = "base"
for x in range(self.enemies_count):
new_enemy = Enemy()
self.enemies.append(new_enemy)
self.size = 1
class Weapon(object):
def __init__(self, name, damage):
self.name = name
self.damage = damage
class Armor(object):
def __init__(self, name, armor_value):
self.name = name
self.armor = armor_value
class Player(object):
def __init__(self):
self.lvl = 1
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.initiative = (self.lvl * 5) + self.pre * 5
self.maxhealth = (self.lvl * 10) + 50 + self.end * 10 + self.str * 5
self.health = self.maxhealth
self.current = "shack"
self.money = 0
self.weapon = Weapon("bare hands", 3)
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 "================="
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 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.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 = random.choice(weapons)
self.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 "================="
print
def inv(self):
print
print "================="
print " WEAPON : ", self.weapon
print " ARMOR : ", self.armor
print "-----------------"
print "inventory:"
if len(self.inventory) > 0:
print
for item in self.inventory:
print " ", item
print
else:
print
print " EMPTY "
print
print "================="
# MAIN LOOP // MAIN MENU #######################################
# MAIN MENU LOOP START ########################################
while main_loop is True:
theglowscr()
print
choice = raw_input()
clrscreen()
if choice == 'new game':
player1 = Player()
player1.desc()
places = worldgen()
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:
clrscreen()
if 'continue' not in main_menu_list:
wlcdescscreen()
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()
if choice in places:
player1.current = choice
clrscreen()
else:
print "wrong answer going back to previous menu"
elif choice == "inventory":
clrscreen()
player1.inv()
raw_input()
pass
elif choice == "player stats":
clrscreen()
player1.desc()
raw_input()
elif choice == "merchant":
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 ##############################################
print
print "GAME OVER"
raw_input()
Traceback (most recent call last):
File "D:/Coding/Projects/PyCharm/Vendor/The Glow.py", line 299, in <module>
places = worldgen()
File "D:/Coding/Projects/PyCharm/Vendor/The Glow.py", line 113, in worldgen
newplace = PlaceVillage()
File "D:/Coding/Projects/PyCharm/Vendor/The Glow.py", line 141, in __init__
new_enemy = Enemy()
File "D:/Coding/Projects/PyCharm/Vendor/The Glow.py", line 253, in __init__
self.weapon = random.choice(weapons)
File "D:\Coding\Installed Programs\Languages\Python 2.7.8\lib\random.py", line 275, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
KeyError: 1
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
KeyError: 1
self.weapon = random.choice(weapons)
Traceback (most recent call last):
File "D:/Coding/Projects/PyCharm/Vendor/The Glow.py", line 299, in <module>
places = worldgen()
File "D:/Coding/Projects/PyCharm/Vendor/The Glow.py", line 113, in worldgen
newplace = PlaceVillage()
File "D:/Coding/Projects/PyCharm/Vendor/The Glow.py", line 141, in __init__
new_enemy = Enemy()
File "D:/Coding/Projects/PyCharm/Vendor/The Glow.py", line 253, in __init__
self.weapon = random.choice(weapons)
File "D:\Coding\Installed Programs\Languages\Python 2.7.8\lib\random.py", line 275, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
KeyError: 1
You should read what the error tells you.
Code:return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty KeyError: 1
This means it tries to access something that doesn't exist in seq meaning seq is empty. This is inside Python 2.7.8\lib\random.py meaning a function inside random module. The function call before that was this:
It calls function from random module called choice with a collection of weapons. Since this call breaks because it tries to get something from an empty collection it means the collection weapons you pass it is empty. You need to fill the weapons before passing it to random.choice.Code:self.weapon = random.choice(weapons)
This is platform dependent. On Windows you can use the msvcrt module:If i could find a way in which CMD would work on button press instead of command then enter i would be sooooo haaaaapy..
another interesting question. Saving... What is general gist of saving ?
private XmlNode xmlNode;
..
public string Name
{
get
{
return xmlNode.GetData("Name");
}
set
{
xmlNode.SetData("Name", value);
}
}
public void SetData(string xPath, object value) /
{
string name = xPath.Substring(xPath.LastIndexOf('/') + 1);
XmlNode node = XmlNode.SelectSingleNode(xPath);
if (node == null)
{
node = XmlDocument.CreateNode(XmlNodeType.Element, name, "");
XmlNode.AppendChild(node);
}
node.InnerText = value.ToString();
}
public void SetData(string xPath, List<string> values)
{
string name = xPath.Substring(xPath.LastIndexOf('/') + 1);
XmlNodeList xmlNodeList = XmlNode.SelectNodes(xPath);
foreach (XmlNode xmlNode in xmlNodeList)
{
XmlNode.RemoveChild(xmlNode);
}
foreach (string value in values)
{
XmlNode xmlNode = XmlDocument.CreateNode(XmlNodeType.Element, name, "");
xmlNode.InnerText = value.ToString();
XmlNode.AppendChild(xmlNode);
}
}
public string GetData(string xPath)
{
XmlNode node = XmlNode.SelectSingleNode(xPath);
if (node != null)
{
return node.InnerText;
}
else
{
return null;
}
}
public List<string> GetData(string name)
{
XmlNodeList xmlNodeList = XmlNode.SelectNodes(name);
List<string> values = new List<string>();
foreach (XmlNode xmlNode in xmlNodeList)
{
values.Add(xmlNode.InnerText);
}
return values;
}
public int Age
{
get
{
return int.Parse(xmlNode.GetData("Age"));
}
set
{
xmlNode.SetData("Age", value);
}
}
So i must simply look for what variables i have and use I/O to export them and import them implementing save/load menu nothing else. Though if project is bigger this might be a big task (with all those variables)
So i must simply look for what variables i have and use I/O to export them and import them implementing save/load menu nothing else. Though if project is bigger this might be a big task (with all those variables)
That's what I meant with hand-wiring. It can be done that way, but it's a lot more work, and you will shoot yourself in the foot sooner or later, but that's part of learning.
...
self.ammo_list = [bullet1, ... )
...
print "=BULLETS="
bullets_bar = {}
for x in self.ammo_list:
if x.name in bullets_bar:
bullets_bar[x.name] += 1
else:
bullets_bar[x.name] = 1
print bullets_bar
Status progress on my THE GLOW game:
This is why i have now conflicting thoughts on GOAL4.
#1. I can go into different language syntax. C# probably. It naturally would be good for me (as i won't really loose anything).
#2. I can go on with python add to that kivy and do some game that looks like a game. Which is really something i wouldn't believe i could do just month ago.
Is it really normal that game-play is so quick and easily developed ? I mean i am complete noob in programming and i basically created sandbox game in which game procedurally generates world and where i can add in seconds new weapons armors and stuff, where i can edit now combat math in minutes and possibly rewriting whole thing in day at most.