-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgame.py
More file actions
44 lines (42 loc) · 1.46 KB
/
game.py
File metadata and controls
44 lines (42 loc) · 1.46 KB
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
import psycopg2
class Game:
def __init__(self,level,language='english'):
self.level=level
self.language=language
self.known_words = 0
self.total_words = 0
self.begin()
def begin(self):
self.connect()
self.cur.execute("select dutch,english from words where word_level='{}'".format(self.level))
self.level_words=self.cur.fetchall()
def flashcard(self):
return self.level_words[0]
def progress(self, choice):
if choice:
self.true_button_()
else:
self.false_button_()
return [self.known_words,self.total_words]
def true_button_(self):
self.known_words+=1
self.total_words+=1
self.level_words.pop(0)
def false_button_(self):
self.total_words+=1
self.level_words.append(self.level_words[0])
self.level_words.pop(0)
def success_percentage(self):
if self.known_words==0:
return 0
else:
return (self.known_words/self.total_words)*100
def connect(self):
self.conn = psycopg2.connect(database = "flashcard",user = "postgres",host = "localhost",password = "1903")
self.cur = self.conn.cursor()
def close(self):
self.conn.close()
def words_count(self):
self.cur.execute("select count(*) from words where word_level='{}'".format(self.level))
self.count_words=self.cur.fetchone()[0]
return self.count_words