Skip to content
Snippets Groups Projects
screen_class.py 7.06 KiB
Newer Older
s2032074's avatar
s2032074 committed
'''Class defining the screens'''
import pygame #library is used for drawing

class Screens:
    '''this class contains the implementation of all screens'''
    
    def __init__(self):
        self.name = 'NoName'

        #defining the size of the screen
        self.width = 1000
        self.height = 800
        self.screen_size = (1000, 800)
        #defining the background color
        self.backgroundcolor = (255, 255, 255)

    #x -- the x-coordinate of the center of the text block
    #y -- the y-coordinate of the center of the text block
    #size -- the size of the font (in points)
    #color -- color of the text (RGB)
    #screen -- the screen on which to draw
    def text(self, x, y, size, text, color, screen):
        '''this function is used to draw a block of text'''
        font = pygame.font.Font(None, size)
        text = font.render(text, True, color, self.backgroundcolor)
        text_rectangle = text.get_rect()
        text_rectangle.center = (x, y)
        screen.blit(text, text_rectangle)

    #parnr -- participant number
    #screen -- the screen on which to draw
    def screen_welcome(self, parnr, screen):
        '''function draws the welcome screen'''
        #redrawing the screen
        screen.fill((255,255,255))

        parnr_text = "Your participant number is: " + str(parnr)
        #here the function is actually used, followed by a screen update
        self.text(500, 200, 80, "Welcome", (0, 0, 0,), screen)
        self.text(500, 250, 40, "to the Corsi Block-Tapping Test!", (0, 0, 0), screen)
        self.text(500, 350, 40, parnr_text, (0, 0, 0), screen)
        self.text(500, 580, 40, "Press SPACE to continue", (0, 0, 0), screen)        
        pygame.display.flip() #updates the display

    #screen -- the screen on which to draw
    def screen_description(self, screen):
        '''function draws the screen with description'''
        #redrawing the screen
        screen.fill((255,255,255))
        
        #executing the functions that draw the text
        self.text(500, 200, 40, "In the test, you will see multiple blocks.", (0, 0, 0,), screen)
        self.text(500, 250, 40, "These blocks will light up gray in succession.", (0, 0, 0,), screen)
        self.text(500, 300, 40, "Afterwards, they turn black again.", (0, 0, 0,), screen)
        self.text(500, 350, 40, "When they do, tap the blocks in the same sequence.", (0, 0, 0,), screen)
        self.text(500, 580, 40, "Press SPACE to continue", (0, 0, 0,), screen)
        pygame.display.flip() #updates the display

    #screen -- the screen on which to draw
    def screen_rules(self, screen):
        '''function draws the screen with rules of use'''
        #redrawing the screen
        screen.fill((255,255,255))
        
        #executing the functions that draw the text
        self.text(500, 200, 40, "There will be 4 trials.", (0, 0, 0,), screen)
        self.text(500, 250, 40, "After each test, you will be shown your results.", (0, 0, 0,), screen)
        self.text(500, 300, 40, "You will see an intermediate screen between each trial.", (0, 0, 0,), screen)
        self.text(500, 350, 40, "After all 4 tests, you will be shown your total results.", (0, 0, 0,), screen)
        self.text(500, 420, 40, "Please do not tap blocks that have been tapped already.", (0, 0, 0,), screen)
        self.text(500, 470, 40, "Do not start clicking blocks before all blocks have turned black.", (0, 0, 0,), screen)
        self.text(500, 580, 40, "Press SPACE to start the task.", (0, 0, 0,), screen)
        pygame.display.flip() #updates the display

    #testnr -- the number of the tests that are already finished
    #time -- time spent by the participant on the test
    #correctseq -- number of blocks repeated correctly from the beginning
    #errornr -- number of errors made in repeating the sequence
    #screen -- the screen on which to draw
    def screen_intermediate(self, testnr, time, correctseq, errornr, screen):
        '''function draws the screen with intermediate results'''
        #redrawing the screen
        screen.fill((255,255,255))
        
        #variables for converting parameters into text
        testnr_text = "This was test: " + str(testnr)
        time_text = "Time spent: " + str(time)
        correctseq_text = "Number of correct blocks from the beginning: " + str(correctseq)
        errornr_text = "Number of errors made: " + str(errornr)

        #executing the functions that draw the text
        self.text(500, 200, 80, "Intermediate results", (0, 0, 0,), screen)
        self.text(500, 300, 40, testnr_text, (0, 0, 0,), screen)
        self.text(500, 350, 40, time_text, (0, 0, 0,), screen)
        self.text(500, 400, 40, correctseq_text, (0, 0, 0,), screen)
        self.text(500, 450, 40, errornr_text, (0, 0, 0,), screen)
        self.text(500, 580, 40, "Press SPACE to start the next trial.", (0, 0, 0,), screen)
        pygame.display.flip() #updates the display

    #time1 -- time spent on sequence 1
    #time2 -- time spent on sequence 2
    #time3 -- time spent on sequence 3
    #time4 -- time spent on sequence 4
    #correctseqmax -- the maximum length of the correct sequence
    #finalscore -- final score of the participant
    #screen -- the screen on which to draw
    def screen_final(self, time1, time2, time3, time4, correctseqmax, finalscore, screen):
        '''draws the final screen, summarizing all the results'''
        #redrawing the screen
        screen.fill((255,255,255))
        
        #variables for converting parameters into text
        time_text1 = "Your time on trial 1: " + str(time1) + " seconds"
        time_text2 = "Your time on trial 2: " + str(time2) + " seconds"
        time_text3 = "Your time on trial 3: " + str(time3) + " seconds"
        time_text4 = "Your time on trial 4: " + str(time4) + " seconds"
        correctseq_text = "Maximum of correct blocks from the start: " + str(correctseqmax)
        finalscore_text = "Your final score is: " + str(finalscore)

        #executing the functions that draw the text
        self.text(500, 180, 80, "Final results", (0, 0, 0,), screen)
        self.text(500, 250, 40, time_text1, (0, 0, 0,), screen)
        self.text(500, 300, 40, time_text2, (0, 0, 0,), screen)
        self.text(500, 350, 40, time_text3, (0, 0, 0,), screen)
        self.text(500, 400, 40, time_text4, (0, 0, 0,), screen)
        self.text(500, 450, 40, correctseq_text, (0, 0, 0,), screen)
        self.text(500, 500, 40, finalscore_text, (0, 0, 0,), screen)
        self.text(500, 580, 40, "Press SPACE to continue.", (0, 0, 0,), screen)
        pygame.display.flip() #updates the display

    #screen -- the screen on which to draw
    def screen_goodbye(self, screen):
        '''draws the final screen, summarizing all the results'''
        #redrawing the screen
        screen.fill((255,255,255))
        
        #executing the functions that draw the text
        self.text(500, 200, 80, "Thank you for participating!", (0, 0, 0,), screen)
        self.text(500, 350, 40, "Press SPACE to send your results to the researcher.", (0, 0, 0,), screen)
        self.text(500, 400, 40, "Have a nice day!", (0, 0, 0,), screen)
        pygame.display.flip() #updates the display