Newer
Older
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 custom_text(text,fontName,fontSize,color,coord,surface):
font = pygame.font.Font(fontName,fontSize)
text = font.render(text,True,color)
surface.blit(text,coord)
lightR = [220,128,128]
lightB = [29,85,145]
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Snake 2.o")
Themes.custom_text('Choose Your Theme',"Roboto-Light.ttf",45,[96,96,96],(70,50),theme)
Themes.custom_text('Regular',"Roboto-Light.ttf", 30,white_green,(95,180),theme)
if (75 <= mousepos[0] <= 75+150 and 150 <= mousepos[1] <= 150+100 ):
Gameplay.game(speed, lightB,lightR, white)
Themes.custom_text('Dark',"Roboto-Light.ttf", 30,white,(325,180),theme)
if (280 <= mousepos[0] <= 280+150 and 150 <= mousepos[1] <= 150+100 ):
Themes.button(theme,[255,255,255], [175,300,160,100], 0)
Themes.custom_text('Random',"Roboto-Light.ttf", 30,[0, 0, 0],(200,330),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,lightB,lightR,white)