Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = '1011923269'
- import pygame, sys, random, time
- from pygame.locals import *
- pygame.init()
- clear = False
- clicked = False
- box_is_blue = True
- hidden = False
- endgame = False
- FPS = 60
- fpsClock = pygame.time.Clock()
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- dice3 = random.randint(1,6)
- dice4 = random.randint(1,6)
- dice5 = random.randint(1,6)
- comp1 = random.randint(1,6)
- comp2 = random.randint(1,6)
- comp3 = random.randint(1,6)
- comp4 = random.randint(1,6)
- comp5 = random.randint(1,6)
- _screen = pygame.display.set_mode((550, 400))
- _blue = (0, 100, 255)
- _yellow = (255, 255, 0)
- _red = (255, 0, 0)
- _screen.fill((0, 0, 0))
- _white = (255, 255, 255)
- _black = (0, 0, 0)
- fontObj = pygame.font.Font('freesansbold.ttf', 32)
- endFont = pygame.font.Font('freesansbold.ttf', 72)
- ######################################
- # Dice nr. 1
- _dice1SurfaceObj = fontObj.render(str(dice1), True, _yellow, _blue)
- _dice1RectObj = _dice1SurfaceObj.get_rect()
- _dice1RectObj.center = (60,95)
- # Dice nr. 2
- _dice2SurfaceObj = fontObj.render(str(dice2), True, _yellow, _blue)
- _dice2RectObj = _dice2SurfaceObj.get_rect()
- _dice2RectObj.center = (160,95)
- # Dice nr. 3
- _dice3SurfaceObj = fontObj.render(str(dice3), True, _yellow, _blue)
- _dice3RectObj = _dice3SurfaceObj.get_rect()
- _dice3RectObj.center = (260,95)
- # Dice nr. 4
- _dice4SurfaceObj = fontObj.render(str(dice4), True, _yellow, _blue)
- _dice4RectObj = _dice4SurfaceObj.get_rect()
- _dice4RectObj.center = (360,95)
- # Dice nr. 5
- _dice5SurfaceObj = fontObj.render(str(dice5), True, _yellow, _blue)
- _dice5RectObj = _dice5SurfaceObj.get_rect()
- _dice5RectObj.center = (460,95)
- ##################
- # Comp Dice nr. 1
- _comp1SurfaceObj = fontObj.render(str(comp1), True, _yellow, _red)
- _comp1RectObj = _comp1SurfaceObj.get_rect()
- _comp1RectObj.center = (60,195)
- # Comp Dice nr. 2
- _comp2SurfaceObj = fontObj.render(str(comp2), True, _yellow, _red)
- _comp2RectObj = _comp2SurfaceObj.get_rect()
- _comp2RectObj.center = (160,195)
- # Comp Dice nr. 3
- _comp3SurfaceObj = fontObj.render(str(comp3), True, _yellow, _red)
- _comp3RectObj = _comp3SurfaceObj.get_rect()
- _comp3RectObj.center = (260,195)
- # Comp Dice nr. 4
- _comp4SurfaceObj = fontObj.render(str(comp4), True, _yellow, _red)
- _comp4RectObj = _comp4SurfaceObj.get_rect()
- _comp4RectObj.center = (360,195)
- # Comp Dice nr. 5
- _comp5SurfaceObj = fontObj.render(str(comp5), True, _yellow, _red)
- _comp5RectObj = _comp5SurfaceObj.get_rect()
- _comp5RectObj.center = (460,195)
- ######################################
- # reroll all
- _rerollSurfaceObj = fontObj.render('Reroll all', True, _yellow, _blue)
- _rerollRectObj = _rerollSurfaceObj.get_rect()
- _rerollRectObj.center = (115,295)
- # Show hidden
- _hiddenSurfaceObj = fontObj.render('Show hidden', True, _yellow, _blue)
- _hiddenRectObj = _hiddenSurfaceObj.get_rect()
- _hiddenRectObj.center = (345,295)
- ######################################
- # Reroll all
- def reroll_all():
- global _dice1SurfaceObj
- global _dice2SurfaceObj
- global _dice3SurfaceObj
- global _dice4SurfaceObj
- global _dice5SurfaceObj
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- dice3 = random.randint(1,6)
- dice4 = random.randint(1,6)
- dice5 = random.randint(1,6)
- _dice1SurfaceObj = fontObj.render(str(dice1), True, _yellow, _blue)
- _dice2SurfaceObj = fontObj.render(str(dice2), True, _yellow, _blue)
- _dice3SurfaceObj = fontObj.render(str(dice3), True, _yellow, _blue)
- _dice4SurfaceObj = fontObj.render(str(dice4), True, _yellow, _blue)
- _dice5SurfaceObj = fontObj.render(str(dice5), True, _yellow, _blue)
- def show_hidden():
- global _hiddenSurfaceObj
- global _dice5SurfaceObj
- dice5 = random.randint(1,6)
- _dice5SurfaceObj = fontObj.render(str(dice5), True, _yellow, _blue)
- def _drawNumbers():
- _screen.blit(_dice1SurfaceObj, _dice1RectObj)
- _screen.blit(_dice2SurfaceObj, _dice2RectObj)
- _screen.blit(_dice3SurfaceObj, _dice3RectObj)
- _screen.blit(_dice4SurfaceObj, _dice4RectObj)
- if hidden == True:
- _screen.blit(_dice5SurfaceObj, _dice5RectObj)
- _screen.blit(_comp1SurfaceObj, _comp1RectObj)
- _screen.blit(_comp2SurfaceObj, _comp2RectObj)
- _screen.blit(_comp3SurfaceObj, _comp3RectObj)
- _screen.blit(_comp4SurfaceObj, _comp4RectObj)
- _screen.blit(_comp5SurfaceObj, _comp5RectObj)
- if clear == False:
- _screen.blit(_rerollSurfaceObj, _rerollRectObj)
- _screen.blit(_hiddenSurfaceObj, _hiddenRectObj)
- def _endGame():
- userSum = dice1+dice2+dice3+dice4+dice5
- compSum = comp1+comp2+comp3+comp4+comp5
- if userSum > compSum:
- _screen.fill((0,0,0))
- _text1 = endFont.render("You Win!!!", True, _white, _black)
- _text1RectObj = _text1.get_rect()
- _text1RectObj.center = (260,300)
- _screen.blit(_text1, _text1RectObj)
- if userSum == compSum:
- _screen.fill((0,0,0))
- _text2 = endFont.render("It's a tie", True, _white, _black)
- _text2RectObj = _text2.get_rect()
- _text2RectObj.center = (260,300)
- _screen.blit(_text2, _text2RectObj)
- if userSum < compSum:
- _screen.fill((0,0,0))
- _text3 = endFont.render("You Lose!!", True, _white, _black)
- _text3RectObj = _text3.get_rect()
- _text3RectObj.center = (260,300)
- _screen.blit(_text3, _text3RectObj)
- def _drawAll():
- pygame.draw.rect(_screen, _blue, pygame.Rect(35, 69, 50, 50))
- pygame.draw.rect(_screen, _blue, pygame.Rect(135, 69, 50, 50))
- pygame.draw.rect(_screen, _blue, pygame.Rect(235, 69, 50, 50))
- pygame.draw.rect(_screen, _blue, pygame.Rect(335, 69, 50, 50))
- pygame.draw.rect(_screen, _blue, pygame.Rect(435, 69, 50, 50))
- pygame.draw.rect(_screen, _red, pygame.Rect(35, 169, 50, 50))
- pygame.draw.rect(_screen, _red, pygame.Rect(135, 169, 50, 50))
- pygame.draw.rect(_screen, _red, pygame.Rect(235, 169, 50, 50))
- pygame.draw.rect(_screen, _red, pygame.Rect(335, 169, 50, 50))
- pygame.draw.rect(_screen, _red, pygame.Rect(435, 169, 50, 50))
- pygame.display.set_caption('Hello World!')
- while True: # main game loop
- _drawAll()
- if endgame == False:
- pygame.draw.rect(_screen, _blue, pygame.Rect(35, 269, 160, 50))
- pygame.draw.rect(_screen, _blue, pygame.Rect(235, 269, 220, 50))
- _rerollRect = pygame.Rect(35, 269, 160, 50)
- _hiddenRect = pygame.Rect(235, 269, 220, 50)
- _drawNumbers()
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit
- if event.type == pygame.MOUSEBUTTONUP and clicked == False:
- _mousePos = pygame.mouse.get_pos()
- if _rerollRect.collidepoint(_mousePos):
- hidden = True
- reroll_all()
- _endGame()
- clicked = True
- endgame = True
- clear = True
- break
- if _hiddenRect.collidepoint(_mousePos):
- hidden = True
- show_hidden()
- _endGame()
- clicked = True
- endgame = True
- clear = True
- break
- pygame.draw
- pygame.display.flip()
- fpsClock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement