[Tutor] Help with Dice game
coryloghry at yahoo.com
coryloghry at yahoo.com
Mon Nov 10 21:57:27 CET 2014
Hello, I can not for the life of me figure out where I have gone wrong. I wrote the following code as a simulation for the table top game x-wing. It basically simulates dice rolls but the issue is the fact that every time I choose a number of dice to roll, they all hit. None of them ever miss. Thank You.
import random
print("X-wing dice simulator")
x = int(input("How many dice will the offensive player be rolling?\n"))
y = int(input("How many dice will the defensive player be rolling?\n"))
hits = 0
crits = 0
dodges = 0
offense = 0
defense = 0
while offense < x:
odie = random.randint(1,8)
if odie <= 4:
hits = hits + 1
offense = offense + 1
if odie == 4:
crits = crits + 1
offense = offense + 1
else:
continue
while defense < y:
ddie = random.randint(1,8)
if ddie <= 3:
dodges = dodges + 1
defense = defense + 1
else:
continue
print("The offensive player lands", hits,"hits and", crits,"crits\n")
print("The defensive player dodges", dodges, "hits\n")
print("The offensive player deals", int((hits + crits) - dodges), "to the defensive player")
Sent from Windows Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141110/a320211f/attachment.html>
More information about the Tutor
mailing list