Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SKUNK Dice Game
#1
Good Morning Everyone!

Feel free to jump right down to the code, but a little bit about me:

So I decided to pick up coding at the beginning of April with all the COVID stuff keeping me home. I’ve always been interested in it since a teenager but just dabbled with it back then(in the 90s). I was briefly a computer programming major in Jr College but ended up with a marketing degree. I found myself in the teaching profession (Jr. High math for almost 7 years now). I also have a masters in Learning and Technology, so coding is fitting right in. I’m hoping to be able to use coding in my own math lessons by creating games to help students engage with the material. Also a possibility for a career change as I am really liking it so far.

The code here is after one week of learning Python. I’ve been using the Sololearn app, watching YouTube videos, read through Part I and the “Alien Invasion” section of Eric Matthes’ “Python Crash Course, 2nd Ed.”, and about halfway through the modules from snakify.com. I find I learn best by just diving into the code with a project goal. Hoping to improve upon the code with a GUI and fix some minor bugs, and refactor some of the code as since I made this, Ive learned some style conventions.

What the game does:
-You have five rounds (SKUNK)
-Each round you roll two dice and roll as many times as you want to rack up points.
-You can move to the next round at any point and bank the points for that round.
-You will lose points for that round if you roll exactly one “1”.
-You will lose ALL of your points for the game if you roll snake-eyes.

Potential improvements:
-GUI
-Win conditions
-Sound
-Multiplayer

Looking forward to participating in the community! Enjoy!

 #SKUNK-Text Based Dice Game

from random import randint as rand

#opening
S_pts = 0 #Declaring initial scores for each round
K_pts = 0
U_pts = 0
N_pts = 0
KK_pts = 0
p = 0 #Helps with indexing the points for each round
t = 0 #Helps with indexing the current round
pts_list = [S_pts, K_pts, U_pts, N_pts, KK_pts]
cur_pts = pts_list[p]
round_list = ('S', 'K', 'U', 'N', 'K')
cur_round = round_list[t]

print('Press Return to roll the dice and test your luck!')
start = input()

#The roll() function is the heart of the game and has three outcomes
def roll():
    global t, p, round_list, cur_round, pts_list, cur_pts, S_pts, K_pts, U_pts, N_pts, KK_pts
    dice1 = rand(1,6) #If you wanted an 8-sided dice, you would use (1,8), 20-sided (1,20), etc...
    dice2 = rand(1,6)
    dice_t = dice1 + dice2

    if dice1 == 1 and dice2 == 1: #The double = tests for values. The code below will execute if both Boolean values are true
        print('You rolled a '+ str(dice1) + ' and ' + str(dice2) + ' for a total of ' + str(dice1 + dice2)+' points.')
        print('SNAKE-EYES! You lost all of your points!')
        for x in range(0,5): #This for loop will reset all the points to 0.
            pts_list[x] = 0
        movetonextround() #This takes us to the next round

    elif dice1 == 1 or dice2 == 1:
        print('You rolled a ' + str(dice1) + ' and ' + str(dice2) + ' for a total of ' + str(dice1 + dice2) + ' points.')
        print('AWE SHUCKS! At least one of your rolls was a 1 --> You lost your points for the [' + str(cur_round) + '] round.')
        cur_pts = 0 #This changes the current round's points to 0.
        movetonextround()
    else:
        print('You rolled a ' + str(dice1) + ' and ' + str(dice2) + ' for a total of ' + str(dice1 + dice2) + ' points.')
        cur_pts = int(cur_pts) + int(dice_t)
        nextmove()

def movetonextround():
    global t, p, round_list, cur_round, pts_list, cur_pts, S_pts, K_pts, U_pts, N_pts, KK_pts
    print('You have a total of ' + str(pts_list[0] + pts_list[1] + pts_list[2] + pts_list[3] + pts_list[4]) + ' points across all rounds.')
    t += 1 #This is important as in order to get the correct round reference in text, you need to index the next value in the list
    if t >= 5: #Since you only have 0, 1, 2, 3, 4 as indeces, once you hit 5, there are no more rounds and the game is over.
        print('Congrats! Your final score is ' + str(pts_list[0] + pts_list[1] + pts_list[2] + pts_list[3] + pts_list[4]) + '.')
        print('Thanks for playing!')
    else:
        p += 1 #Like the round list, we need to make sure our points list advances.
        cur_pts = pts_list[p]
        round_list = ('S', 'K', 'U', 'N', 'K')
        cur_round = round_list[t]
        print('Next up is the [' + str(cur_round) + '] round. Hit Return to roll. Good luck!')
        choice = input()
        roll()

def nextmove():
    global pts_list, p, cur_pts
    print('You have ' + str(cur_pts) +' points so far in the [' + str(cur_round) + '] round. What is your next move?')
    print('1. Roll again   2. Stop for this round')
    choice = input()
    if choice == '1':
        roll() #This calls back the meat of the program
    elif choice == '2':
        print('Great Job this round! You scored a total of ' + str(cur_pts) + ' points in the [' + str(cur_round) + '] round.')
        pts_list[p] = cur_pts
        movetonextround()
    else:
        print('Did not get that?')

roll()
Reply


Messages In This Thread
SKUNK Dice Game - by ProntName - Apr-16-2020, 02:29 PM
RE: SKUNK Dice Game - by eXcalibur432 - Apr-16-2020, 02:54 PM
RE: SKUNK Dice Game - by ProntName - Apr-17-2020, 04:04 AM
RE: SKUNK Dice Game - by Larz60+ - Apr-16-2020, 08:12 PM
RE: SKUNK Dice Game - by Larz60+ - Apr-17-2020, 04:09 AM
RE: SKUNK Dice Game - by ProntName - Apr-17-2020, 04:30 AM
RE: SKUNK Dice Game - by Larz60+ - Apr-17-2020, 10:28 AM
RE: SKUNK Dice Game - by eXcalibur432 - Apr-17-2020, 11:32 AM
RE: SKUNK Dice Game - by Larz60+ - Apr-17-2020, 03:43 PM
RE: SKUNK Dice Game - by eXcalibur432 - Apr-19-2020, 12:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the dice roll mini-game tawnnx 6 7,359 May-22-2018, 02:12 PM
Last Post: malonn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020