Login Register






Challenge (4) Simulate Simon (the game) filter_list
Author
Message
RE: Challenge (4) Simulate Simon (the game) #11
(12-31-2015, 05:31 AM)ねこまっしぐら Wrote: Is this supposed to be Simon Says?
Yeah, except virtual. Here's an example:

http://www.primarygames.com/puzzles/simon/color/
[Image: pBD38Xq.png]
Email: insidious@protonmail.ch

Reply

RE: Challenge (4) Simulate Simon (the game) #12
(12-31-2015, 05:31 AM)ねこまっしぐら Wrote: Is this supposed to be Simon Says?

No, go to the link I provided:
https://en.wikipedia.org/wiki/Simon_%28game%29

Reply

RE: Challenge (4) Simulate Simon (the game) #13
I want to add sounds and a game start / game over screen but the actual mechanics are down,for the most part

Code:
import random, sys, time, pygame from pygame.locals import * fps = 30 height = 500 width = 500 buttonsize = 200 buttongap = 20 xmargin = int((width - (2*buttonsize) - buttongap) /2) ymargin = int((height - (2*buttonsize) - buttongap) /2) flashDelay = 200 WHITE = (255, 255, 255) BLACK = ( 0, 0, 0) BRIGHTRED = (255, 0, 0) RED = (155, 0, 0) BRIGHTGREEN = ( 0, 255, 0) GREEN = ( 0, 155, 0) BRIGHTBLUE = ( 0, 0, 255) BLUE = ( 0, 0, 155) BRIGHTYELLOW = (255, 255, 0) YELLOW = (155, 155, 0) DARKGRAY = ( 40, 40, 40) bgColor = BLACK # Rect objects for each of the four buttons yellowrect = pygame.Rect(xmargin, ymargin, buttonsize, buttonsize) bluerect = pygame.Rect(xmargin + buttonsize + buttongap, ymargin, buttonsize, buttonsize) redrect = pygame.Rect(xmargin, ymargin + buttonsize + buttongap, buttonsize, buttonsize) greenrect = pygame.Rect(xmargin + buttonsize + buttongap, ymargin + buttonsize +buttongap, buttonsize, buttonsize) def main(): global clock, gameDisplay, basicfont clock = pygame.time.Clock() gameDisplay = pygame.display.set_mode((height, width)) pygame.display.set_caption('Simon Says') crashed = False pygame.init() step = 0 waitingForInput = False orderList = [] #main loop while not crashed: clicked = None drawButtons() for event in pygame.event.get(): if event.type == pygame.QUIT: print('God Fucking Dammit Leeroy') crashed = True print(event) #for the plebs who use mice if event.type == pygame.MOUSEBUTTONUP: mousex, mousey = event.pos clicked = getButtonClicked(mousex, mousey) print('this works?') #for them classy folks who like the keyboard elif event.type == KEYDOWN: if event.key == K_z: clicked = YELLOW print('yellow') elif event.key == K_x: clicked = BLUE print('blue') elif event.key == K_c: clicked = RED print('red') elif event.key == K_v: clicked = GREEN print('green') pygame.display.update() clock.tick(fps) if not waitingForInput: orderList.append(random.choice((YELLOW,BLUE,RED,GREEN))) for item in orderList: clickedAnimation(item, 50) pygame.time.wait(flashDelay) waitingForInput = True else: print('got after else') print("order length is: %d" % len(orderList)) #print('order 0 is: %s' % orderList[0]) if clicked and orderList[step] == clicked: step += 1 waitingForInput = True if step == len(orderList): waitingForInput = False step = 0 elif clicked and orderList[step] != step: crashed = True else: waitingForInput = True def getButtonClicked(x, y): if yellowrect.collidepoint((x,y)): print('yellow') return YELLOW elif bluerect.collidepoint((x,y)): print('blue') return BLUE elif redrect.collidepoint((x,y)): print('red') return RED elif greenrect.collidepoint((x,y)): print('green') return GREEN return None def drawButtons(): pygame.draw.rect(gameDisplay, YELLOW, yellowrect) pygame.draw.rect(gameDisplay, RED, redrect) pygame.draw.rect(gameDisplay, BLUE, bluerect) pygame.draw.rect(gameDisplay, GREEN, greenrect) def clickedAnimation(color, speed=50): if color == YELLOW: flash = BRIGHTYELLOW rectangle = yellowrect elif color == BLUE: flash = BRIGHTBLUE rectangle = bluerect elif color == RED: flash = BRIGHTRED rectangle = redrect elif color == GREEN: flash = BRIGHTGREEN rectangle = greenrect originalSurface = gameDisplay.copy() flashSurface = pygame.Surface((buttonsize, buttonsize)) flashSurface = flashSurface.convert_alpha() r, g, b = flash for start, end, step in ((0, 255, 1), (255, 0, -1)): # animation loop for alpha in range(start, end, speed * step): gameDisplay.blit(originalSurface, (0, 0)) flashSurface.fill((r, g, b, alpha)) gameDisplay.blit(flashSurface, rectangle.topleft) pygame.display.update() clock.tick(fps) gameDisplay.blit(originalSurface, (0, 0)) if __name__=='__main__': main()
[Image: pBD38Xq.png]
Email: insidious@protonmail.ch

[+] 1 user Likes insidious's post
Reply

RE: Challenge (4) Simulate Simon (the game) #14
(01-04-2016, 04:51 AM)insidious15 Wrote: I want to add sounds and a game start / game over screen but the actual mechanics are down,for the most part

Code:
import random, sys, time, pygame from pygame.locals import * fps = 30 height = 500 width = 500 buttonsize = 200 buttongap = 20 xmargin = int((width - (2*buttonsize) - buttongap) /2) ymargin = int((height - (2*buttonsize) - buttongap) /2) flashDelay = 200 WHITE = (255, 255, 255) BLACK = ( 0, 0, 0) BRIGHTRED = (255, 0, 0) RED = (155, 0, 0) BRIGHTGREEN = ( 0, 255, 0) GREEN = ( 0, 155, 0) BRIGHTBLUE = ( 0, 0, 255) BLUE = ( 0, 0, 155) BRIGHTYELLOW = (255, 255, 0) YELLOW = (155, 155, 0) DARKGRAY = ( 40, 40, 40) bgColor = BLACK # Rect objects for each of the four buttons yellowrect = pygame.Rect(xmargin, ymargin, buttonsize, buttonsize) bluerect = pygame.Rect(xmargin + buttonsize + buttongap, ymargin, buttonsize, buttonsize) redrect = pygame.Rect(xmargin, ymargin + buttonsize + buttongap, buttonsize, buttonsize) greenrect = pygame.Rect(xmargin + buttonsize + buttongap, ymargin + buttonsize +buttongap, buttonsize, buttonsize) def main(): global clock, gameDisplay, basicfont clock = pygame.time.Clock() gameDisplay = pygame.display.set_mode((height, width)) pygame.display.set_caption('Simon Says') crashed = False pygame.init() step = 0 waitingForInput = False orderList = [] #main loop while not crashed: clicked = None drawButtons() for event in pygame.event.get(): if event.type == pygame.QUIT: print('God Fucking Dammit Leeroy') crashed = True print(event) #for the plebs who use mice if event.type == pygame.MOUSEBUTTONUP: mousex, mousey = event.pos clicked = getButtonClicked(mousex, mousey) print('this works?') #for them classy folks who like the keyboard elif event.type == KEYDOWN: if event.key == K_z: clicked = YELLOW print('yellow') elif event.key == K_x: clicked = BLUE print('blue') elif event.key == K_c: clicked = RED print('red') elif event.key == K_v: clicked = GREEN print('green') pygame.display.update() clock.tick(fps) if not waitingForInput: orderList.append(random.choice((YELLOW,BLUE,RED,GREEN))) for item in orderList: clickedAnimation(item, 50) pygame.time.wait(flashDelay) waitingForInput = True else: print('got after else') print("order length is: %d" % len(orderList)) #print('order 0 is: %s' % orderList[0]) if clicked and orderList[step] == clicked: step += 1 waitingForInput = True if step == len(orderList): waitingForInput = False step = 0 elif clicked and orderList[step] != step: crashed = True else: waitingForInput = True def getButtonClicked(x, y): if yellowrect.collidepoint((x,y)): print('yellow') return YELLOW elif bluerect.collidepoint((x,y)): print('blue') return BLUE elif redrect.collidepoint((x,y)): print('red') return RED elif greenrect.collidepoint((x,y)): print('green') return GREEN return None def drawButtons(): pygame.draw.rect(gameDisplay, YELLOW, yellowrect) pygame.draw.rect(gameDisplay, RED, redrect) pygame.draw.rect(gameDisplay, BLUE, bluerect) pygame.draw.rect(gameDisplay, GREEN, greenrect) def clickedAnimation(color, speed=50): if color == YELLOW: flash = BRIGHTYELLOW rectangle = yellowrect elif color == BLUE: flash = BRIGHTBLUE rectangle = bluerect elif color == RED: flash = BRIGHTRED rectangle = redrect elif color == GREEN: flash = BRIGHTGREEN rectangle = greenrect originalSurface = gameDisplay.copy() flashSurface = pygame.Surface((buttonsize, buttonsize)) flashSurface = flashSurface.convert_alpha() r, g, b = flash for start, end, step in ((0, 255, 1), (255, 0, -1)): # animation loop for alpha in range(start, end, speed * step): gameDisplay.blit(originalSurface, (0, 0)) flashSurface.fill((r, g, b, alpha)) gameDisplay.blit(flashSurface, rectangle.topleft) pygame.display.update() clock.tick(fps) gameDisplay.blit(originalSurface, (0, 0)) if __name__=='__main__': main()

Nice! I like it! Smile
That is one big main function. xD

Reply

RE: Challenge (4) Simulate Simon (the game) #15
(01-04-2016, 05:14 AM)m0dem Wrote: Nice! I like it! Smile
That is one big main function. xD

Yeahh, I didn't feel like splitting it up Tongue
[Image: pBD38Xq.png]
Email: insidious@protonmail.ch

[+] 1 user Likes insidious's post
Reply