image_game.py

xristinak, xristinak, 13/07/2015 14:11

Μεταφόρτωση (2.723 KB)

 
1
#-*- coding: utf-8 -*-
2
import pygame,sys
3
from pygame.locals import *
4

    
5
pygame.init()
6
HORIZ = 800
7
VERT = 600
8
my_screen=pygame.display.set_mode((HORIZ,VERT),0,32)
9
pygame.display.set_caption('hello')
10

    
11
WHITE=(255,255,255)
12
PINK=(255,204,204)
13
color=WHITE
14
rec_col=PINK
15
my_screen.fill(color)
16

    
17
#image
18
img=pygame.image.load('city.jpg')
19
img=pygame.transform.scale(img,(650,450))
20
my_screen.blit(img,(50,50))
21
pygame.display.update()
22

    
23
#button
24
#btn=Button('btn1','Ready!',20,40,100,700)
25
#btn.draw(my_screen)
26
#pygame.display.update()
27

    
28
my_rect=pygame.Rect(110,530,300,40)
29
pygame.draw.rect(my_screen,rec_col,my_rect,0)
30
font = pygame.font.SysFont("monospace", 15)
31

    
32
label = font.render("Ready, give me the challenge!", 1, (0,0,0))
33
my_screen.blit(label,(114,533))
34
pygame.display.update()
35

    
36
while True:
37
        
38
        for ev in pygame.event.get():
39
                if ev.type==QUIT:
40
                        pygame.quit()
41
                        sys.exit()
42
                if ev.type == KEYDOWN:                
43
                        if ev.key == K_ESCAPE:
44
                                pygame.quit()
45
                                sys.exit()
46

    
47
                if ev.type==pygame.MOUSEBUTTONDOWN:
48
                        click=my_rect.collidepoint(pygame.mouse.get_pos())
49
                        if click==1:
50
                                my_screen=pygame.display.set_mode((HORIZ,VERT),0,32)
51
                                pygame.display.set_caption('question')
52
                                my_screen.fill(color)
53

    
54
                                font = pygame.font.SysFont("monospace", 15)
55
                                lbl = font.render("Whata  is the color of the second boat from left side?", 1, (0,0,0))
56
                                my_screen.blit(lbl,(50,50))
57

    
58
                                ans1=pygame.Rect(60,80,200,30)
59
                                pygame.draw.rect(my_screen,rec_col,ans1,0)
60
                                lbl1 = font.render("Green", 1, (0,0,0))
61
                                my_screen.blit(lbl1,(65,80))
62

    
63
                                ans2=pygame.Rect(60,150,200,30)
64
                                pygame.draw.rect(my_screen,rec_col,ans2,0)
65
                                lbl2 = font.render("Black", 1, (0,0,0))
66
                                my_screen.blit(lbl2,(65,155))
67

    
68
                                ans3=pygame.Rect(60,220,200,30)
69
                                pygame.draw.rect(my_screen,rec_col,ans3,0)
70
                                lbl3 = font.render("Orange", 1, (0,0,0))
71
                                my_screen.blit(lbl3,(65,225))
72

    
73
                                ans4=pygame.Rect(60,290,200,30)
74
                                pygame.draw.rect(my_screen,rec_col,ans4,0)
75
                                lbl4 = font.render("Blue", 1, (0,0,0))
76
                                my_screen.blit(lbl4,(65,295))
77

    
78

    
79
                                pygame.display.update()
80
                                
81
                        click1=ans1.collidepoint(pygame.mouse.get_pos())
82
                        click2=ans2.collidepoint(pygame.mouse.get_pos())
83
                        click3=ans3.collidepoint(pygame.mouse.get_pos())
84
                        click4=ans4.collidepoint(pygame.mouse.get_pos())
85
                        if click3==1:
86
                                right=pygame.image.load('r.jpeg')
87
                                my_screen.blit(right,(300,70))
88
                                pygame.display.update()
89
                        if click1==1:
90
                                wrong=pygame.image.load('w.jpeg')
91
                                my_screen.blit(wrong,(300,70))
92
                                pygame.display.update()
93
                                                        
94
                        if click2==1:
95
                                wrong=pygame.image.load('w.jpeg')
96
                                my_screen.blit(wrong,(300,70))
97
                                pygame.display.update()
98
                        if click4==1:
99
                                wrong=pygame.image.load('w.jpeg')
100
                                my_screen.blit(wrong,(300,70))
101
                                pygame.display.update()
102
                                
103
my_scree.fill(rec_col,my_rect)        
104
pygame.display.update()
105