Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Created by .ignore support plugin (hsz.mobi)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Pyramid Game!
76 changes: 41 additions & 35 deletions Pyramid.py → demo/Pyramid.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#! /usr/bin/env python2

from random import randint
from random import choice
"""
VYLEPSENIA:
1.) simulacia hraca s dvoma rukami. Hrac moze niest ziadnu, jednu jednorucnu,
dve jednorucne alebo jednu obojrucnu zbran. V hre su aj stity, brane ako jednorucne zbrane.
-> pridana metoda Player.equip(self, hand, weapon)
dve jednorucne alebo jednu obojrucnu zbran. V hre su aj stity, brane ako jednorucne zbrane.
-> pridana metoda Player.equip(self, hand, weapon)
-> zmena suboja (utok a obrana sa pocitaju z oboch ruk)
-> definovany predmet ruka = Weapon(...)
2.) upraveny vyber cennych predmetov, zbrani a priser, aby hra bola hratelnejsia -> celkom hardcore ked hrac nema stastie, chcelo by to progresivne zvysovanie urovne priser
2.) upraveny vyber cennych predmetov, zbrani a priser, aby hra bola hratelnejsia -> celkom hardcore ked hrac nema stastie, chcelo by to progresivne zvysovanie urovne priser
3.) zavedena minimalna pauza medzi odpocinkami:
premenna can_rest sa po kazdom odpocinku nastavi na 10, zmensuje sa kazdou platnou akciou hraca(-1 za "vezmi", "poloz", "vyzbroj", -3 za "jdi")
odpocinok povoleny ked can_rest <= 0
Expand Down Expand Up @@ -44,7 +46,7 @@ def describe(self):
print "Obourucna zbran."
else:
print "Jednorucna zbran."



items = [ # name, description, value, weight
Expand Down Expand Up @@ -102,7 +104,7 @@ def __init__(self, name):
self.max_health = randint(150,200)
self.health = self.max_health
self.capacity = randint(150,200)
self.left_hand = ruka
self.left_hand = ruka
self.right_hand = weapons[3]
self.bag = {}
def rest(self):
Expand All @@ -121,32 +123,32 @@ def add_to_bag(self, item): #input object (tvaru items[x] alebo weap
print "Predmet \"" + item.name + "\" vlozen do batohu."
self.bag[item.name] = Item(item.name, item.description, item.value, item.weight)
self.capacity -= item.weight
return True
return True
def equip(self, hand, weapon = ruka): #input weapon ako object, moznost unequip nezadanim zbrane; vrati zoznam objektov
previous_weapons = []
if weapon.is_twohanded == False: #prikaz equip jednorucnu zbran
if self.right_hand.is_twohanded == True: #prave equipnuta zbran je obojrucna
if hand == "prava":
self.left_hand = ruka
self.left_hand = ruka
previous_weapons.append(self.right_hand)
self.right_hand = weapon
else:
self_right_hand = ruka
previous_weapons.append(self.left_hand)
self.left_hand = weapon
elif hand == "leva": #equipujem jednorucnu zbran ked bola equipnuta jednorucna
if self.left_hand == ruka:
if self.left_hand == ruka:
self.left_hand = weapon
else:
previous_weapons.append(self.left_hand)
self.left_hand = weapon
else:
previous_weapons.append(self.left_hand)
self.left_hand = weapon
elif hand == "prava":
if self.right_hand == ruka:
self.right_hand = weapon
else:
previous_weapons.append(self.right_hand)
self.right_hand = weapon
elif weapon.is_twohanded == True: #vrati dva objekty v zozname
elif weapon.is_twohanded == True: #vrati dva objekty v zozname
if self.left_hand == ruka != self.right_hand:
previous_weapons.append(self.right_hand)
elif self.right_hand == ruka != self.left_hand:
Expand All @@ -156,8 +158,8 @@ def equip(self, hand, weapon = ruka): #input weapon ako object, moznost
previous_weapons.append(self.left_hand)
self.left_hand = weapon
self.right_hand = weapon
return previous_weapons
return previous_weapons

def take_from_bag(self, item_name): #input string
if item_name in self.bag:
vec = self.bag[item_name]
Expand All @@ -183,7 +185,7 @@ def describe(self):
self.left_hand.describe()
print "Prava ruka:",
self.right_hand.describe()

def score(self):
skore = 0
for vec in self.bag:
Expand All @@ -202,7 +204,7 @@ def attack_player(player, monster):
if monster.health <= 0:
print "Protivnik je porazen!"
return True

def attack_monster(player, monster):
print "Protivnik \"" + monster.name + "\" na tebe utoci."
damage = int((randint(8,12)*0.1) * monster.attack) - (player.left_hand.defence + player.right_hand.defence)
Expand All @@ -225,17 +227,17 @@ def fight(player, monster):
result = attack_player(player, monster)
if monster.health <=0:
break
print
print
result = attack_monster(player, monster)
print
print
else: #monster starts
while monster.health > 0 and player.health > 0:
result = attack_monster(player, monster)
if player.health <= 0:
break
print
print
result = attack_player(player, monster)
print
print
return result

class Room(object):
Expand Down Expand Up @@ -273,7 +275,7 @@ def describe(self):
print "- ", d
if self.monster != None:
self.monster.react_to_noise()
if self.monster.sleeping == True:
if self.monster.sleeping == True:
print "V mistnosti je " + self.monster.name + ". Spi."
return True
else:
Expand Down Expand Up @@ -385,12 +387,12 @@ def describe(self):
rooms[15].add_direction("dolu", tomb)


def randomize(rooms, monsters, items, weapons):

def randomize(rooms, monsters, items, weapons):
for mistnost in rooms:
seed = [randint(1,4), randint(0,2), randint(1,3)]
if seed[0] != 1: mistnost.set_monster(choice(monsters)) #75% sanca na priseru v miestnosti
for i in range (seed[1]): mistnost.add_item(choice(items)) #0-2 predmety v miestnosti; vyzera byt bugle, stretla som aj 4 itemy
for i in range (seed[1]): mistnost.add_item(choice(items)) #0-2 predmety v miestnosti; vyzera byt bugle, stretla som aj 4 itemy
if seed[2] == 1: mistnost.add_weapon(choice(weapons)) #33% sanca na zbran v miestnosti

def play(start = start):
Expand Down Expand Up @@ -423,17 +425,17 @@ def play(start = start):
prikaz = str(raw_input("Zadej prikaz: "))
while len(prikaz) == 0:
prikaz = str(raw_input("Zadej prikaz: "))
prikaz = prikaz.lower()
prikaz = prikaz.lower()
prikaz = prikaz.split()
while prikaz[0] not in ["info", "jdi", "vezmi", "vyzbroj", "odpocinek", "poloz", "konec", "napoveda"]:
while prikaz[0] not in ["info", "jdi", "vezmi", "vyzbroj", "odpocinek", "poloz", "konec", "napoveda"]:
print "Nepodporovany vstup.",
prikaz = str(raw_input("Zadej prikaz: "))
prikaz = prikaz.lower()
prikaz = prikaz.split()
if prikaz[0] == "info":
if prikaz[0] == "info":
player.describe()

elif prikaz[0] == "jdi":
elif prikaz[0] == "jdi":
if prikaz[1] in current_room.directions:
if can_rest > 0: #uprava pocitadla umoznujuceho odpocinok
can_rest -= 3
Expand All @@ -443,7 +445,7 @@ def play(start = start):
print "--- neuspesny konec hry ---"
game_over = True
elif current_room.ending == True:
max_skore = 500 #faraonova maska
max_skore = 500 #faraonova maska
for room in rooms:
for item in room.items:
max_skore += room.items[item].value
Expand All @@ -460,15 +462,15 @@ def play(start = start):
print "Zadej ruku, do ktere chces zbran vzit."
else:
if len(prikaz) < 3:
if can_rest > 0: #uprava pocitadla umoznujuceho odpocinok
if can_rest > 0: #uprava pocitadla umoznujuceho odpocinok
can_rest -= 1
previous_weapons = player.equip(prikaz[1])
if previous_weapons != []:
for weapon in previous_weapons:
current_room.add_weapon(weapon)
player.describe()
print
else:
else:
if prikaz[2] in current_room.weapons:
if can_rest > 0: #uprava pocitadla umoznujuceho odpocinok
can_rest -= 1
Expand All @@ -481,14 +483,14 @@ def play(start = start):
print
else:
print "Tato zbran v mistnosti neni."

elif prikaz[0] == "vezmi":
vec = prikaz[1]
if vec in current_room.items:
if vec in current_room.items:
can_take = player.add_to_bag(current_room.items[vec])
if can_take == True:
current_room.remove_item(vec)
if can_rest > 0: #uprava pocitadla umoznujuceho odpocinok
if can_rest > 0: #uprava pocitadla umoznujuceho odpocinok
can_rest -= 1
else:
print "Tento predmet se v mistnosti nenachazi."
Expand All @@ -499,7 +501,7 @@ def play(start = start):
added_health = player.rest()
print "Tvoje postava si odpocinula a nabrala " + str(added_health) + " zdravi."
print "Zdravi: " + str(player.health) + "/" + str(player.max_health)
can_rest = 10 #zacne odpocitavanie, kedy postava bude moct znova odpocivat
can_rest = 10 #zacne odpocitavanie, kedy postava bude moct znova odpocivat
else:
print "Jeste se ti nechce odpocivat."
else: print "V mistnosti s priserou nemuzes odpocivat, ty blazne!"
Expand Down Expand Up @@ -528,3 +530,7 @@ def play(start = start):
print "napoveda:\t\t vypise tuto napovedu"
print

if __name__ == "__main__":
play()


13 changes: 13 additions & 0 deletions pyramid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /usr/bin/env python2
# Purpose of this line to make it normal executable file on linux



def main():
# TODO



if __name__ == "__main__":
main()

Empty file added pyramid/__init__.py
Empty file.
Empty file added pyramid/core/__init__.py
Empty file.
Empty file added pyramid/draw/__init__.py
Empty file.
Empty file added pyramid/draw/console.py
Empty file.
Empty file added pyramid/entities/__init__.py
Empty file.
Empty file added pyramid/entities/item.py
Empty file.
Empty file added pyramid/entities/map.py
Empty file.
Empty file added pyramid/entities/monster.py
Empty file.
Empty file added pyramid/entities/player.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added requirements.txt
Empty file.
Empty file added setup.py
Empty file.
Empty file added tests/entitites/map.py
Empty file.
Empty file added tests/entitites/monster.py
Empty file.
Empty file added tests/entitites/player.py
Empty file.
22 changes: 22 additions & 0 deletions tests/sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env python2
import unittest


class TestStringMethods(unittest.TestCase):

def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')

def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())

def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)

if __name__ == '__main__':
unittest.main()