Aug-06-2019, 06:17 PM
(This post was last modified: Aug-07-2019, 06:03 PM by jonstryder.)
Well I'm at a loss on this one now, and of course it doesn't help that I'm not that good at python. I got a lot of good help with the last assignment I posted on here, so I'm back again, doing something different.
This time around I'm trying to make a dice roller based off rules for a tabletop RPG called Hero System. In this game you roll 3d6 for your attack roll, and then between 1 or as many as you can hold other d6's, although for this lab, the array I set uses 12d6.
3d6 is three six sided dice, and 12d6 would of course be twelve six sided dice for those who are not familiar with the terminology.
So to get started, the parameters of the assignment are:
No Pseudocode is entered, I typically enter that after doing the functioning code since the pseudocode doesn't do anything to make the program work.
I'll break my code up to explain my thoughts.
So in this first function, it will roll 3 dice and display the results. This part works.
But now we come to the problem part.
The above section is meant to check with you to see if your attack hit. If you choose Yes then you move on to the next part, but if no then it should kick you backup to roll your 3 dice again. But it doesn't.
Now in this last part the Yes/No check is supposed move you onto selecting between 1 and 12 dice to roll if you choose yes. But instead I just get the usual error messages. I'm hoping that what I've set up will allow you to enter said number and output each die result.
Now I have tried to code this a few different ways, and I've attempted any number of combinations of calls in the main(), adding and removing elements, but I haven't managed to work out a way to get this to work.
I would like to add that my code cannot be too complex or move outside the boundaries of what we've been taught in class (sequence, input/output, modularity, decision structures, repetition, function, validation, and currently on arrays).
Once again, any help is appreciated.
This time around I'm trying to make a dice roller based off rules for a tabletop RPG called Hero System. In this game you roll 3d6 for your attack roll, and then between 1 or as many as you can hold other d6's, although for this lab, the array I set uses 12d6.
3d6 is three six sided dice, and 12d6 would of course be twelve six sided dice for those who are not familiar with the terminology.
So to get started, the parameters of the assignment are:
- Your name given as the author.
- Comments including a brief description of the program, Input List and Output List, and full pseudocode. Place the pseudocode for each module above the module's Python code.
- The program must have at least one input and at least one output.
- All user input must be validated. This means the user is not allowed to just enter any value. You must check the value, and ask the user to enter it again, and repeat this loop until the user enters a valid value.
- Your program must use at least two arrays in meaningful ways. These two arrays can contain any type of values, as long as they are both used meaningfully in your program.
- Your program must have at least one loop that accesses the data in the arrays. For example, you might have an input loop that asks the user to enter the data one element at a time (be sure to validate the data). Or, you might have an output loop that writes the data to the console. Or, you might have a calculation loop that calculates one or more values, such as minimum value, maximum value, averages, and so on. You can have all three of those types of loops, if you want (the Lab 5 walkthrough video shows an example of each).
- Your program should be organized into separate modules. Each module should be "cohesive" and should only do one thing.
- Use parameters and arguments to pass values into your modules (don't use global variables).
- The Python code should run correctly, and the logic should match your pseudocode.
No Pseudocode is entered, I typically enter that after doing the functioning code since the pseudocode doesn't do anything to make the program work.
I'll break my code up to explain my thoughts.
1 2 3 4 5 6 7 8 9 10 |
import random def attack_roll(): dice_roll = ( input ( "Press [ENTER] to make your attack roll." ) = = "") while True : dice = [ 0 , 0 , 0 ,] for x in range ( 3 ): dice[x] = random.randint( 1 , 6 ) print ( "Your attack roll total is:" , dice) break |
But now we come to the problem part.
1 2 3 4 5 6 7 |
def successful_attack(attack_hit): while True : success = input ( "Did your attack hit? (Y / N) " ) if success in [ 'Yes' , 'yes' , 'Y' , 'y' ]: return 'Y' elif success in [ 'No' , 'no' , 'N' , 'n' ]: return "N" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
def doing_damage(): while True : attack_hit = print ( "You may only roll a maximum of 12 dice." ) damage_dice = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] for y in range = = input ( "How many damage dice will you roll (1 to 12)? " , int ()): damage_dice[y] = random.randint( 1 , 6 ) print ( "Your damage dice roll is: " , damage_dice[y]) break def main(): while True : attack_roll() successful_attack(attack_hit) attack_hit = doing_damage() main() |
Now I have tried to code this a few different ways, and I've attempted any number of combinations of calls in the main(), adding and removing elements, but I haven't managed to work out a way to get this to work.
I would like to add that my code cannot be too complex or move outside the boundaries of what we've been taught in class (sequence, input/output, modularity, decision structures, repetition, function, validation, and currently on arrays).
Once again, any help is appreciated.