0% found this document useful (0 votes)
46 views3 pages

Code

This document contains a Python script using Pygame to create a dice game where a computer randomly generates dice rolls. The game allows a player to select options and reset the game while displaying graphics for the dice and background. The script includes event handling for user interactions and updates the game state based on the player's choices and the computer's rolls.

Uploaded by

thanhfast3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

Code

This document contains a Python script using Pygame to create a dice game where a computer randomly generates dice rolls. The game allows a player to select options and reset the game while displaying graphics for the dice and background. The script includes event handling for user interactions and updates the game state based on the player's choices and the computer's rolls.

Uploaded by

thanhfast3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import pygame

from random import randint


def computer(computer1, computer2, computer3):
if computer1 == 1:
[Link]([Link]("[Link]"), (0,0))
if computer1 == 2:
[Link]([Link]("[Link]"), (0,0))
if computer1 == 3:
[Link]([Link]("[Link]"), (0,0))
if computer1 == 4:
[Link]([Link]("[Link]"), (0,0))
if computer1 == 5:
[Link]([Link]("[Link]"), (0,0))
if computer1 == 6:
[Link]([Link]("[Link]"), (0,0))

if computer2 == 1:
[Link]([Link]("[Link]"), (0,0))
if computer2 == 2:
[Link]([Link]("[Link]"), (0,0))
if computer2 == 3:
[Link]([Link]("[Link]"), (0,0))
if computer2 == 4:
[Link]([Link]("[Link]"), (0,0))
if computer2 == 5:
[Link]([Link]("[Link]"), (0,0))
if computer2 == 6:
[Link]([Link]("[Link]"), (0,0))

if computer3 == 1:
[Link]([Link]("[Link]"), (0,0))
if computer3 == 2:
[Link]([Link]("[Link]"), (0,0))
if computer3 == 3:
[Link]([Link]("[Link]"), (0,0))
if computer3 == 4:
[Link]([Link]("[Link]"), (0,0))
if computer3 == 5:
[Link]([Link]("[Link]"), (0,0))
if computer3 == 6:
[Link]([Link]("[Link]"), (0,0))

[Link].pre_init(frequency = 44100, size = -16, channels = 2, buffer = 512)


[Link]()

screen = [Link].set_mode((1200,700))

BLACK = (0,0,0)
GREY = (120,120,120)

running = True
reset = True

floor = [Link]("[Link]")
floor_pos = 0
player = 0
secs = 120
tong = computer1 + computer2 + computer3
xucxac1 = [Link]("[Link]")
xucxac1_rect = (150,450)
xucxac2 = [Link]("[Link]")
xucxac2_rect = (435,450)
xucxac3 = [Link]("[Link]")
xucxac3_rect = (720,450)
secs_over_sound = [Link]("[Link]")

while running:
[Link](GREY)
mouse_x, mouse_y = [Link].get_rect()

for event in [Link]():


if [Link] == [Link]:
running = False
if [Link] == [Link]:
if [Link] == 1:
if 1050 < mouse_x < 1200 and 0 < mouse_y < 90 and reset ==
False:
reset = True
secs = 120

if secs == 0:
secs_over_sound.play()
if floor_pos <= -1200:
floor_pos = 0

[Link](screen, BLACK, (1050,0,150,90))


[Link](screen, BLACK, (150,100,250,200))
[Link](screen, BLACK, (600,100,250,200))

[Link]([Link]("[Link]"), (0,0))
[Link]([Link]("[Link]"), (1050,0))
[Link]([Link]("[Link]"), (150,100))
[Link]([Link]("[Link]"), (600,100))

if reset:
for event in [Link]():
if [Link] == [Link]:
if [Link] == 1:
if 1050 < mouse_x < 1200 and 0 < mouse_y < 90:
reset = False
if 150 < mouse_x < 400 and 100 < mouse_y < 300:
[Link]([Link]("[Link]"),
(150,100))
player = 1
if 600 < mouse_x < 400 and 100 < mouse_y < 300:
[Link]([Link]("[Link]"),
(600,100))
player = 2
if 150 < mouse_x < 280 and 450 < mouse_y < 580:
xucxac1_rect = (mouse_x, mouse_y)
if 435 < mouse_x < 565 and 450 < mouse_y < 580:
xucxac2_rect = (mouse_x, mouse_y)
if 720 < mouse_x < 850 and 450 < mouse_y < 580:
xucxac2_rect = (mouse_x, mouse_y)
if secs == 0:
computer1 = randint(1,6)
computer2 = randint(1,6)
computer3 = randint(1,6)
if
if tong > 10:
computer = 1
else:
computer = 2
if player == computer:
[Link]
else:
[Link]
[Link](xucxac1, xucxac1_rect)
[Link](xucxac2, xucxac2_rect)
[Link](xucxac3, xucxac3_rect)

computer()
secs -= 1
floor_pos -= 3
[Link](floor, (floor_pos,620))
[Link](floor, (floor_pos + 1200,620))

[Link]()

[Link]()

You might also like