blob: 7afe105f4fc96c356e8049d5bf65b2e217a7fa44 (
plain)
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
|
# -*- coding: utf-8 -*-
import random
import os
import datetime
from puzzle import *
class Session:
def __init__(self, topic, difficulty):
self.topic = topic
self.difficulty = difficulty
#obtener puzzles
self.list_puzzles = []
if self.topic=='Todas':
list_topics=os.listdir('./puzzles/' + str(self.difficulty))
for topic_tmp in list_topics:
list_files = os.listdir('./puzzles/' + str(self.difficulty) + '/' + topic_tmp)
for item in list_files:
self.list_puzzles.append(Puzzle('./puzzles/' + str(self.difficulty) + '/' + topic_tmp + '/' + item))
else:
list_files = os.listdir('./puzzles/' + str(self.difficulty) + '/' + self.topic)
for item in list_files:
self.list_puzzles.append(Puzzle('./puzzles/' + str(self.difficulty) + '/' + self.topic + '/' + item))
self.time = datetime.datetime.now()
self.old_puzzles = []
self.score=0
def nextPuzzle(self):
l=len(self.list_puzzles)
if l>0:
i = random.randrange(0, l)
self.old_puzzles.append(self.list_puzzles[i])
self.current=self.list_puzzles.pop(i)
self.answered=False
else:
self.current.question='Juego Terminado\nPuntaje='+str(self.score)
self.answered=True
def currentPuzzle(self):
return self.current
def evaluateAnswer(self,answer):
if not self.isAnswered():
self.answered=True
test=self.currentPuzzle().evaluateAnswer(answer)
if test:
self.score+=self.currentPuzzle().getScore()
return test
def end(self):
self.list_puzzles=[]
def isAnswered(self):
return self.answered
def __str__(self):
return 'SesiĆ³n de topico = ' + str(self.topic) + ' y dificultad = ' + str(self.difficulty)
|