Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/session.py
blob: 1214ee8687a554c15640538be42bd546a7f95cca (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
58
59
# -*- coding: utf-8 -*-
import random
import os
import time
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 = time.time()
        self.old_puzzles = []
        self.score=0
        self.continues=True

    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)+'\nTiempo='+str(time.time()-self.time)+' segundos'
            self.answered=True
            self.continues=False

    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)