Question

I am writing a slot machine game for my intro to programming class. I can make the game procure 5 random images from a file containing 6, arrange them on a blank canvas and compare the pictures to see if there are 3-in-a-row. It will tell you if you win or not and ask you to play again. I need to loop the game so that it runs again after the user selects "y/n". here is my code so far.

from random import *

def main():




  pictureList = setMediaPath("F:\Class Stuff\INF 120\Project X\gamepics")

  s = 1 # requestInteger("Slot machine image numbering begins at:")
  e = 6 # requestInteger("Slot maching image numbering ends at:")
  ext = "jpg" #requestString("Enter the extension ofthe slot machine image files   (without a dot):")
  mypic = []
  for num in range(s, e+1):
    mypic = mypic + [(makePicture("smImage" + str(num) + "." + ext))]

#set up the "game board" in a blank window  
  w = getWidth(mypic[0])
  h = getHeight(mypic[0])

  ePic = makeEmptyPicture(w*5, h)
  show(ePic)
# start the actual game
  win = False
  inRow = 1
  last = -1

#loop through all five slots and set pic for each one a new, random picture. Form list  of pictures.
#make a loop to run through the game until win = true.
  for i in range(0,5):
    imgIndex = randrange(0,len(mypic))  
    copyInto(mypic[imgIndex], ePic, i*w, 0)
    repaint(ePic)  

    if imgIndex == last:
      inRow = inRow + 1
    else:
      inRow = 1
    last = imgIndex

    if inRow >= 3:
      win = true

  if win == true:
    showInformation("YOU WIN!!")
    rePlay = requestString("Would you like to play again? (y/n)")
  else:
    showInformation("You Lose...")
    requestString("Play again? (y/n)")

the media path is set to the directory on my machine with the images. here is a link to my google drive with the images. https://drive.google.com/folderview?id=0B_ZDD1CZGQYlYjFQWEpjR0NzMGs&usp=sharing .If you are going to run this, you need to change the media path in my code to correspond with where you have the pictures.

I appreciate any and all help with this. Thanks!

Was it helpful?

Solution

I dont know any jython but the pseudo code should be

var continue = true
while(continue) {
    [[play game, set continue based on user input]]
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top