-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.py
108 lines (86 loc) · 2.64 KB
/
11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pygame
import time
import sqlite3
import random
from threading import Thread
# colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
def check_score(name):
global score
global a
if (name == 1 and clicked):
score += 1
if (name != 1 and clicked):
score -= 1
def draw_score(screen, x, y, score):
font = pygame.font.SysFont('Arial', 36) # Choose the font for the text
text = font.render("Score = " + str(score), 3, BLACK) # Create the text
screen.blit(text, (x, y)) # Draw the text on the screen
# Displays Name of animal
def show_name(animal_name):
font = pygame.font.SysFont('Arial', 72) # Choose the font for the text
dis_name = font.render(str(animal_name), 3, BLACK)
screen.blit(dis_name, (160, 200))
# As the Function name suggests
def fetch_data():
conn = sqlite3.connect("chidiya.db")
c = conn.cursor()
c.execute("select * from animals order by RANDOM() Limit 1")
for a in c.fetchall():
show_name(a[1])
check_score(a[2])
conn.commit()
conn.close()
# Game Setup
pygame.init()
screen_size = (500, 500)
screen = pygame.display.set_mode(screen_size)
pygame.display.set_caption("Chidiya Udd")
# run until user clicks close button
done = False
# score
score = 0
clicked = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
screen.fill(WHITE)
t1 = Thread(target=fetch_data)
t1.start()
draw_score(screen, 160, 450, score)
#-----Main Program-----#
millis = int(round(time.time() * 1000))
while not done:
# pygame.time.wait(200)
if int(round(time.time() * 1000)) - millis >= 2000:
millis = int(round(time.time() * 1000))
screen.fill(WHITE)
fetch_data()
draw_score(screen, 160, 450, score)
clicked = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
clicked = True
# check_score()
screen.fill(WHITE)
draw_score(screen, 160, 450, score)
show_name(a[i])
# clicked = False
# Game GUI
# must be at start or it will fill white on other objects
# Show Name of animals
# data_no = random.randint(0, 2)
# fetch_data()
# screen.fill(WHITE)
# Show the score on the screen
# clock.tick(60)
pygame.display.flip()
# pygame.time.wait(500)
# clicked = False
# pygame.time.wait(500)