Skip to content
Snippets Groups Projects
Commit b0ea8211 authored by 's avatar
Browse files

updating src

parent 607b2bc0
No related branches found
No related tags found
No related merge requests found
#importing necessary libraries
import pygame, sys
from tkinter import *
import tkinter as tk
#a function made to execute other files from the system
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
class GUI():
#a function made to execute other files from the system
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
def button(Surface, color,Rect,width):
pygame.draw.rect(Surface, color,Rect,width)
def button(Surface, color,Rect,width):
pygame.draw.rect(Surface, color,Rect,width)
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 text(text,fontStyle,fontSize,color,coord,surface):
font = pygame.font.SysFont(fontStyle,fontSize)
text = font.render(text,True,color)
surface.blit(text,coord)
pygame.init()
gray = [180,180,180]
darkgray = [100,100,100]
red = [255,0,0]
def main():
pygame.init()
gray = [180,180,180]
darkgray = [100,100,100]
red = [255,0,0]
#while loop required to always refresh the page
while True:
game = pygame.display.set_mode((800, 610))
game.fill([213, 219, 219])
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Lets Play")
GUI.text('SNAKE GAME',"monospace", 80,red,(150,80),game)
#Adding the play game button
if (270 <= mousepos[0] <= 270+250 and 450 <= mousepos[1] <= 450+55 ):
#checks if the mouse is hovering over the button
GUI.button(game,darkgray, [270,455,250,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
GUI.runfile('Snake_2.o_Demo.py')
else:
GUI.button(game,gray, [270,455,250,50], 0)
GUI.text('GAME TIME',"comicsansms", 40,[0, 0, 200],(275,450),game)
#while loop required to always refresh the page
while True:
game = pygame.display.set_mode((800, 610))
game.fill([213, 219, 219])
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Lets Play")
text('SNAKE GAME',"monospace", 80,red,(150,80),game)
#Adding the play game button
if (270 <= mousepos[0] <= 270+250 and 450 <= mousepos[1] <= 450+55 ):
#checks if the mouse is hovering over the button
button(game,darkgray, [270,455,250,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
runfile('Snake_2.o_Demo.py')
else:
button(game,gray, [270,455,250,50], 0)
text('GAME TIME',"comicsansms", 40,[0, 0, 200],(275,450),game)
## radioButton = Radiobutton(game, text = "option 1")
## radioButton.pack()
text('THEMES:',"comicsansms", 40,(0, 200, 0),(50,250),game)
text('SPEED',"comicsansms", 40,(0, 150, 0),(50,350),game)
GUI.text('THEMES:',"comicsansms", 40,(0, 200, 0),(50,250),game)
GUI.text('SPEED',"comicsansms", 40,(0, 150, 0),(50,350),game)
#Highest Score
if ( 10 <= mousepos[0] <= 310 and 550 <= mousepos[1] <= 550 +55):
button(game,[200,0,0],[10,550,300,55], 0)
if mouseclick[0] == 1:
runfile('highscore.py')
else:
button(game,[180,180,180], [10,550,300,55], 0)
text('HIGHEST SCORE',"comicsansms", 35,(0, 0, 0),(10,550),game)
#If user wants to quit
if ( 670 <= mousepos[0] <= 670+105 and 550 <= mousepos[1] <= 550 +55):
button(game,[200,0,0],[670,550,105,55], 0)
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
else:
button(game,[180,180,180], [670,550,105,55], 0)
text('QUIT',"comicsansms", 35,(0, 0, 0),(670,550),game)
pygame.display.update()
#Highest Score
if ( 10 <= mousepos[0] <= 310 and 550 <= mousepos[1] <= 550 +55):
GUI.button(game,[200,0,0],[10,550,300,55], 0)
if mouseclick[0] == 1:
GUI.runfile('highscore.py')
#highscore.main()
else:
GUI.button(game,[180,180,180], [10,550,300,55], 0)
GUI.text('HIGHEST SCORE',"comicsansms", 35,(0, 0, 0),(10,550),game)
#If user wants to quit
if ( 670 <= mousepos[0] <= 670+105 and 550 <= mousepos[1] <= 550 +55):
GUI.button(game,[200,0,0],[670,550,105,55], 0)
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
else:
GUI.button(game,[180,180,180], [670,550,105,55], 0)
GUI.text('QUIT',"comicsansms", 35,(0, 0, 0),(670,550),game)
pygame.display.update()
main()
import pygame, sys
from tkinter import *
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
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 button(Surface, color,Rect,width):
pygame.draw.rect(Surface, color,Rect,width)
def findHighscore():
infile = open("highscore.txt","r")
mylist = []
for line in infile:
a = line.strip()
mylist.append(a)
return max(mylist)
pygame.init()
red = [255,0,0]
while True:
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
highscore = pygame.display.set_mode((300, 150))
#highscore.fill([213, 219, 219])
pygame.display.set_caption("Highscore")
text('Highest Score: ' + str(findHighscore()),"comicsansms", 30,[0, 0, 200],(10,20),highscore)
button(highscore,[0,0,0], [90,70,120,26], 0)
text('Main Menu',"times", 25,red,(90,70),highscore)
if (90 <= mousepos[0] <= 90+120 and 70 <= mousepos[1] <= 70+27 ):
if mouseclick[0] == 1:
runfile('Snake_Game.py')
button(highscore,[0,0,0], [125,105,45,27], 0)
text('Quit',"times", 25,red,(125,105),highscore)
if (125 <= mousepos[0] <= 125+45 and 105 <= mousepos[1] <= 105+27 ):
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
pygame.display.update()
##MyButton1 = Button(highscore, text="BUTTON1")
##MyButton1.grid(row=0, column=0)
class HighScore():
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
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 button(Surface, color,Rect,width):
pygame.draw.rect(Surface, color,Rect,width)
def findHighscore():
infile = open("highscore.txt","r")
mylist = []
for line in infile:
a = line.strip()
mylist.append(a)
return max(mylist)
def main():
pygame.init()
red = [255,0,0]
while True:
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
highscore = pygame.display.set_mode((300, 150))
#highscore.fill([213, 219, 219])
pygame.display.set_caption("Highscore")
HighScore.text('Highest Score: ' + str(HighScore.findHighscore()),"comicsansms", 30,[0, 0, 200],(10,20),highscore)
HighScore.button(highscore,[0,0,0], [90,70,120,26], 0)
HighScore.text('Main Menu',"times", 25,red,(90,70),highscore)
if (90 <= mousepos[0] <= 90+120 and 70 <= mousepos[1] <= 70+27 ):
if mouseclick[0] == 1:
HighScore.runfile('Snake_Game.py')
HighScore.button(highscore,[0,0,0], [125,105,45,27], 0)
HighScore.text('Quit',"times", 25,red,(125,105),highscore)
if (125 <= mousepos[0] <= 125+45 and 105 <= mousepos[1] <= 105+27 ):
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
pygame.display.update()
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment