The Python Game Book

code games. learn Python.

User Tools

Site Tools


en:secret:goblins:step008

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:secret:goblins:step008 [2020/05/03 20:44]
horst ↷ Links adapted because of a move operation
en:secret:goblins:step008 [2020/05/03 21:35] (current)
horst ↷ Links adapted because of a move operation
Line 30: Line 30:
 === online === === online ===
 Or you can try it out online (click on the graphic below): \\ Or you can try it out online (click on the graphic below): \\
-[[http://www.pythontutor.com/visualize.html#code=%0Adef+sign(a,b)%3A%0A++++%22%22%22compares+a+with+b+and+returns+a+%22%3C%22,%22%3D%22+or+%22%3E%22+sign%22%22%22%0A++++if+a+%3C+b%3A%0A++++++++return+%22%3C%22%0A++++elif+a+%3E+b%3A%0A++++++++return+%22%3E%22%0A++++else%3A%0A++++++++return+%22%3D%22%0A%0Adef+compareValues(hpA,+attA,+defA,+hpB,+attB,+defB)%3A%0A++++%22%22%22returns+a+string+with+a+table+comparing+the+values+of+A+and+B%22%22%22%0A++++text+%3D+%22%5Cn++++++++++Stiny+%7C+vs.+%7C+Grunty+%22%0A++++text%2B%3D+%22%5Cn+---------------%2B-----%2B-----------%22%0A++++text%2B%3D+%22%5Cn+hitpoints%3A+%7B0%3A3d%7D+%7C++%7B1%7D++%7C+%7B2%3A3d%7D%22.format(hpA,+sign(hpA,+hpB),+hpB+)%0A++++text%2B%3D+%22%5Cn+attack%3A++++%7B0%3A3d%7D+%7C++%7B1%7D++%7C+%7B2%3A3d%7D%22.format(attA,+sign(attA,+attB),+attB)%0A++++text%2B%3D+%22%5Cn+defense%3A+++%7B0%3A3d%7D+%7C++%7B1%7D++%7C+%7B2%3A3d%7D%22.format(defA,+sign(defA,defB),+defB)%0A++++text%2B%3D+%22%5Cn%22%0A++++return+text%0A%0A%0A%0AhitpointsStinky+%3D+22%0AattackStinky+%3D+6%0AdefenseStinky+%3D+9%0AhitpointsGrunty+%3D+43%0AattackGrunty+%3D+5%0AdefenseGrunty+%3D+3%0A%0A%23+python+lines+can+be+several+physical+lines+long+if+inside+brackets%0Aprint(compareValues(hitpointsStinky,+attackStinky,+defenseStinky,%0A++++++++++++++++++++hitpointsGrunty,+attackGrunty,+defenseGrunty))%0A&mode=display&cumulative=true&heapPrimitives=true&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&curInstr=14|{{en:goblins:slowgoblins008comparedemo.png?300|click me}}]]+[[http://www.pythontutor.com/visualize.html#code=%0Adef+sign(a,b)%3A%0A++++%22%22%22compares+a+with+b+and+returns+a+%22%3C%22,%22%3D%22+or+%22%3E%22+sign%22%22%22%0A++++if+a+%3C+b%3A%0A++++++++return+%22%3C%22%0A++++elif+a+%3E+b%3A%0A++++++++return+%22%3E%22%0A++++else%3A%0A++++++++return+%22%3D%22%0A%0Adef+compareValues(hpA,+attA,+defA,+hpB,+attB,+defB)%3A%0A++++%22%22%22returns+a+string+with+a+table+comparing+the+values+of+A+and+B%22%22%22%0A++++text+%3D+%22%5Cn++++++++++Stiny+%7C+vs.+%7C+Grunty+%22%0A++++text%2B%3D+%22%5Cn+---------------%2B-----%2B-----------%22%0A++++text%2B%3D+%22%5Cn+hitpoints%3A+%7B0%3A3d%7D+%7C++%7B1%7D++%7C+%7B2%3A3d%7D%22.format(hpA,+sign(hpA,+hpB),+hpB+)%0A++++text%2B%3D+%22%5Cn+attack%3A++++%7B0%3A3d%7D+%7C++%7B1%7D++%7C+%7B2%3A3d%7D%22.format(attA,+sign(attA,+attB),+attB)%0A++++text%2B%3D+%22%5Cn+defense%3A+++%7B0%3A3d%7D+%7C++%7B1%7D++%7C+%7B2%3A3d%7D%22.format(defA,+sign(defA,defB),+defB)%0A++++text%2B%3D+%22%5Cn%22%0A++++return+text%0A%0A%0A%0AhitpointsStinky+%3D+22%0AattackStinky+%3D+6%0AdefenseStinky+%3D+9%0AhitpointsGrunty+%3D+43%0AattackGrunty+%3D+5%0AdefenseGrunty+%3D+3%0A%0A%23+python+lines+can+be+several+physical+lines+long+if+inside+brackets%0Aprint(compareValues(hitpointsStinky,+attackStinky,+defenseStinky,%0A++++++++++++++++++++hitpointsGrunty,+attackGrunty,+defenseGrunty))%0A&mode=display&cumulative=true&heapPrimitives=true&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&curInstr=14|{{:slowgoblins008comparedemo.png?300|click me}}]]
 === output === === output ===
  
en/secret/goblins/step008.1588531484.txt.gz · Last modified: 2020/05/03 20:44 by horst