Facebook
From Algo, 1 Month ago, written in Python for S60.
Embed
Download Paste or View Raw
Hits: 146
  1. #Connect the required modules
  2. import pygame
  3. from random import randint
  4. pygame.init()
  5.  
  6.  
  7. #create a game window
  8. clock = pygame.time.Clock()
  9. back = (255, 255, 255) #background color
  10. mw = pygame.display.set_mode((500, 500)) #main window
  11. mw.fill(back)
  12.  
  13.  
  14. #colors
  15. BLACK = (0, 0, 0)
  16. LIGHT_BLUE = (200, 200, 255)
  17.  
  18.  
  19. class TextArea():
  20.    def __init__(self, x=0, y=0, width=10, height=10, color=None):
  21.        """ area: a rectangle in the right place and the right color """
  22.        #memorize the rectangle:
  23.        self.rect = pygame.Rect(x, y, width, height)
  24.        #fill color - either the passed parameter or the overall background color
  25.        self.fill_color = color
  26.  
  27.  
  28.    #place text
  29.    def set_text(self, text, fsize=12, text_color=BLACK):
  30.        self.text = text
  31.        self.image = pygame.font.Font(None, fsize).render(text, True, text_color)
  32.      
  33.    #draw a rectangle with text
  34.    def draw(self, shift_x=0, shift_y=0):
  35.        pygame.draw.rect(mw, self.fill_color, self.rect)
  36.        mw.blit(self.image, (self.rect.x + shift_x, self.rect.y + shift_y))  
  37.  
  38.  
  39. #create cards
  40. quest_card = TextArea(120, 100, 290, 70, LIGHT_BLUE)
  41. quest_card.set_text("Question", 75)
  42.  
  43.  
  44. ans_card = TextArea(120, 240, 290, 70, LIGHT_BLUE)
  45. ans_card.set_text("Answer", 75)
  46.  
  47.  
  48. #main game loop
  49. while 1:
  50.    quest_card.draw(10,10)
  51.    ans_card.draw(10,10)
  52.  
  53.    pygame.display.update()
  54.    clock.tick(40)          
  55.  
  56.