Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/dev/pacmath.activity/question.py
blob: 7c3b6b0fc71fb9ba4a9121289d6abfc40fbcc273 (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
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
109
110
111
112
113
114
115
116
#! /usr/bin/env python
"""
Set up questions and answers with draw functions
@license: U{http://creativecommons.org/licenses/by-sa/3.0/us/}
"""
import pygame
import random

class question:
    """
    @var A: Properties of answer box [color, (left, top), center, ghost location]
    @var B: Properties of answer box [color, (left, top), center, ghost location]
    @var C: Properties of answer box [color, (left, top), center, ghost location]
    @var D: Properties of answer box [color, (left, top), center, ghost location]
    @var SIZE: Size of answer box
    """
    # Properties of rectangles: [color, (left, top), center, ghost location]
    A = [(0, 255, 255), (625, 0), (735, 15), "./images/ghost.gif"]
    B = [(255, 0, 0), (625, 79), (735, 94), "./images/ghost2.gif"]
    C = [(255, 168, 0), (625, 158), (735, 173), "./images/ghost3.gif"]
    D = [(255, 0, 255), (625, 237), (735, 250), "./images/ghost4.gif"]
    
    # Size of rectangles
    SIZE = (275, 75)
    
    QUESTION_COLOR = (94,246,0)
    
    # Default
    def __init__ (self, screen, quests):
        """
        Randomly selects which questions are goign to be used and draws teh answer
        @param screen: the screen in which we will draw
        @param quests: array a questions with answers
        """
        # Draw the answers and questions
        self.questions = quests
        self.question = self.questions[random.randint(0,3)][0]
            
        self.drawAnswers(screen)
        self.drawQuestion(screen)
        
        
    def drawAnswers(self, screen):
        self.drawAnswer(screen, self.questions[0][1], 1)
        self.drawAnswer(screen, self.questions[1][1], 2)
        self.drawAnswer(screen, self.questions[2][1], 3)
        self.drawAnswer(screen, self.questions[3][1], 4)

    # Draws the answer in a ghost colored rectangle
    def drawAnswer(self, screen, answer, choice):
        """
        Draws answers in a color coded box
        @param screen: the screen in which we will draw
        @param answer: answer to be drawn
        @param choice: which choice from 1-4
        """
        # Font used
        font = pygame.font.Font(None, 72)
        
        # Set properties of rectangle based on choice
        if choice == 1:
            color = self.A[0]
            pos = self.A[1]
            center = self.A[2]
            ghost = self.A[3]
        elif choice == 2:
            color = self.B[0]
            pos = self.B[1]
            center = self.B[2]
            ghost = self.B[3]
        elif choice == 3:
            color = self.C[0]
            pos = self.C[1]
            center = self.C[2]
            ghost = self.C[3]
        elif choice == 4:
            color = self.D[0]
            pos = self.D[1]
            center = self.D[2]
            ghost = self.D[3]
        
        # Create and draw rectangle, answer and ghost right of maze
        ans = font.render(answer, 1, color)
        rect = (pos, self.SIZE)
        pygame.draw.rect(screen, color, rect, 3)
        g = pygame.image.load(ghost).convert()
        screen.blit(ans, center)
        screen.blit(g, (pos[0] + 4, pos[1] + 4))
        
    # Draws the question
    def drawQuestion(self, screen):
        """
        Draws the question
        @param screen: the screen in which we will draw
        @param question: question to be drawn
        """
        # Font used
        font = pygame.font.Font(None, 72)
        
        # Draws the question under maze
        q = font.render(self.question, 1, self.QUESTION_COLOR)
        self.clearBottom(screen)
        screen.blit(q, (0, 640))
        pygame.display.flip()
    def drawPaused(self, screen):
        # Font used
        font = pygame.font.Font(None, 72)
        
        q = font.render("Paused", 1, self.QUESTION_COLOR)
        self.clearBottom(screen)
        screen.blit(q, (0, 640))
        pygame.display.flip()
    def clearBottom(self, screen):
        blackBox = pygame.Surface((900,60))
        blackBox.fill((0,0,0))
        screen.blit(blackBox, (0,640))