ThePythonGameBook

learn Python. Create Games

User Tools

Site Tools


en:python:goblins:step007

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:python:goblins:step007 [2013/07/13 22:55]
Horst JENS [source code]
en:python:goblins:step007 [2014/01/09 11:07] (current)
Line 112: Line 112:
  
 It is time to improve the Gobling Dice Duel using a function for output: It is time to improve the Gobling Dice Duel using a function for output:
- +=== source code === 
-<code python slowgoblins007.py+//click reload on your browser if you see no source ​code here or visit [[https://​github.com/​horstjens/​ThePythonGameBook/​blob/​master/​python/goblins/slowgoblins007.py|Github.com]] // 
-def output(combatround,​hitpointsStinky,​hitpointsGrunty):​ +<​html><​script src="http://gist-it.appspot.com/​github/​horstjens/​ThePythonGameBook/​blob/​master/​python/​goblins/​slowgoblins007.py?​footer=minimal"></script></html>
-    """​printing out three values"""​ +
-    print("​{0:​2d} Stinky: {1:2d} Grunty: {2:​2d}"​.format(combatround,​ hitpointsStinky,​ hitpointsGrunty)) +
-    # no return necessary because this functions returns nothing (yet) +
-     +
-import random +
-hitpointsStinky ​22 +
-hitpointsGrunty = 43 +
-combatround = 0 +
-print(" ​--- Goblin Dice Duel ---"​) +
-print("​round ​   hitpoints"​) +
-while hitpointsStinky >0: +
-    output(combatround,​ hitpointsStinky,​ hitpointsGrunty) +
-    combatround += 1 +
-    hitpointsGrunty ​-= random.randint(0,​6) +
-    if hitpointsGrunty <0: +
-        break +
-    hitpointsStinky -= random.randint(0,​6) +
-output(combatround,​ hitpointsStinky,​ hitpointsGrunty) # output of final strike +
-print("Game Over"​) +
-if hitpointsStinky ​hitpointsGrunty:​ +
-    print("​Stinky wins"​) +
-elif hitpointsGrunty ​hitpointsStinky:​ +
-    print("​Grunty wins"​) +
-else: +
-    print("​Nobody wins ?") +
-print("​thank you for playing Goblin Dice Duel. bye-bye!"​) +
-</code>+
  
 === online === === online ===
/var/www/horst/thepythongamebook.com/data/attic/en/python/goblins/step007.1373748950.txt.gz · Last modified: 2014/01/09 11:07 (external edit)