Forked from
asghar / se3xa3
119 commits ahead of the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
theme.py 3.39 KiB
import pygame, sys
from random import randint
import Gameplay
import init
class Themes():
## @brief A function for running other files
# @details Executes another python file when this is selected, Given that the file is in same folder.
# @param runfilename The name of the file to be executed
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
## @brief A method to create a button
# @details This method will make a box on the interface
# @param surface The background (surface) the box should be made on
# @param color The color of the button to be made
# @param Rect The coordinate of the button with the length and width
# @param width The width of the sides of button
def button(Surface, color,Rect,width):
pygame.draw.rect(Surface, color,Rect,width)
## @brief A method to display text
# @details This function will print the text on the interface
# @param text The text to be printed
# @param fontStyle The font Style of the text to be displayed
# @param fontSize The size of the text written
# @param color The color of the text
# @param coord The coordinate at which the text should start displaying
# @param surface The background (surface) the text should be printed on
def text(text,fontStyle,fontSize,color,coord,surface):
font = pygame.font.SysFont(fontStyle,fontSize)
text = font.render(text,True,color)
surface.blit(text,coord)
def themes(speed):
lightBlue = (89,131,146)
black1 = (1,22,30)
white_green = (239,246,224)
white = (255,255,255)
pygame.init()
run = True
while run:
theme = pygame.display.set_mode((500, 500))
theme.fill(white_green)
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Choose Theme")
Themes.text('Choose Your Theme',"maiandragd",45,[96,96,96],(70,50),theme)
Themes.button(theme,lightBlue, [75,150,150,100], 0)
Themes.text('Regular',"maiandragd", 40,white_green,(80,170),theme)
if (75 <= mousepos[0] <= 75+150 and 150 <= mousepos[1] <= 150+100 ):
if mouseclick[0] == 1:
Gameplay.game(speed,[255,0,0],[0,255,0],[255,255,255])
Themes.button(theme,black1, [280,150,150,100], 0)
Themes.text('Dark',"maiandragd", 40,white,(305,170),theme)
if (280 <= mousepos[0] <= 280+150 and 150 <= mousepos[1] <= 150+100 ):
if mouseclick[0] == 1:
Gameplay.game(speed,white,[255,255,0],[10,10,10])
Themes.button(theme,lightBlue, [175,300,80,50], 0)
Themes.button(theme,[200,200,200], [175,350,80,50], 0)
Themes.button(theme,[200,200,200], [255,300,80,50], 0)
Themes.button(theme,[0,0,0], [255,350,80,50], 0)
Themes.text('Random',"maiandragd", 40,[150,0,0],(180,315),theme)
if (180 <= mousepos[0] <= 180+160 and 315 <= mousepos[1] <= 315+100 ):
if mouseclick[0] == 1:
x = randint(0, 1)
if(x == 1): Gameplay.game(speed,[255,0,0],[0,255,0],[255,255,255])
else: Gameplay.game(speed,white,[255,255,0],[10,10,10])
pygame.display.update()
#Themes.themes()