From 0558ede4a14d040ce93160233dbffe4c1a60e433 Mon Sep 17 00:00:00 2001 From: <vc2310@LAPTOP-FCB0H0KM.localdomain> Date: Thu, 8 Nov 2018 02:36:37 -0500 Subject: [PATCH] updating src --- BlankProjectTemplate/src/Snake_Game.py | 68 ++++++++++++++------------ BlankProjectTemplate/src/highscore.py | 52 ++++++++++++++++++++ BlankProjectTemplate/src/highscore.txt | 9 ++++ 3 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 BlankProjectTemplate/src/highscore.py create mode 100644 BlankProjectTemplate/src/highscore.txt diff --git a/BlankProjectTemplate/src/Snake_Game.py b/BlankProjectTemplate/src/Snake_Game.py index fbc084e..09d9d64 100644 --- a/BlankProjectTemplate/src/Snake_Game.py +++ b/BlankProjectTemplate/src/Snake_Game.py @@ -1,12 +1,25 @@ #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()) +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) + pygame.init() +gray = [180,180,180] +darkgray = [100,100,100] +red = [255,0,0] #while loop required to always refresh the page while True: @@ -15,51 +28,42 @@ while True: mousepos = pygame.mouse.get_pos() #checking mouse position mouseclick = pygame.mouse.get_pressed()#checking mouse pressed pygame.display.set_caption("Lets Play") - title_font = pygame.font.SysFont("monospace", 80) - - #Adding the title - gamename = title_font.render('SNAKE GAME', True, (255, 0, 0)) - game.blit(gamename,(150,80)) + text('SNAKE GAME',"monospace", 80,red,(150,80),game) #Adding the play game button - if (270 <= mousepos[0] <= 270+250 and 505 <= mousepos[1] <= 555 ): + if (270 <= mousepos[0] <= 270+250 and 450 <= mousepos[1] <= 450+55 ): #checks if the mouse is hovering over the button - pygame.draw.rect(game,[100,100,100], [270,505,250,50], 0) + button(game,darkgray, [270,455,250,50], 0) #checking if the button is clicked if mouseclick[0] == 1: - runfile('Snake_2.o_Demo.py') - + runfile('Snake_2.o_Demo.py') else: - pygame.draw.rect(game,[180,180,180], [270,505,250,50], 0) - - playgame_font = pygame.font.SysFont("comicsansms", 40) - gamebutton = playgame_font.render('GAME TIME', True, (0, 0, 200)) - game.blit(gamebutton,(275,500)) - - #Taking user name - UserName = playgame_font.render('NAME:', True, (0, 250, 0)) - game.blit(UserName,(50,200)) + button(game,gray, [270,455,250,50], 0) + text('GAME TIME',"comicsansms", 40,[0, 0, 200],(275,450),game) - #Asking user for theme - ThemeOption = playgame_font.render('THEMES:', True, (0, 200, 0)) - game.blit(ThemeOption,(50,300)) - - #Asking user for speed - SpeedOption = playgame_font.render('SPEED:', True, (0, 150, 0)) - game.blit(SpeedOption,(50,400)) +## 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) + #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 ( 650 <= mousepos[0] <= 650+130 and 550 <= mousepos[1] <= 550 +55): - #checks if the mouse is hovering over the button - pygame.draw.rect(game,[200,0,0],[650,550,130,55], 0) - #checking if the button is clicked + 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: - pygame.draw.rect(game,[180,180,180], [650,550,130,55], 0) - Quit = playgame_font.render('QUIT', True, (0, 0, 0)) - game.blit(Quit,(650,550)) + button(game,[180,180,180], [670,550,105,55], 0) + text('QUIT',"comicsansms", 35,(0, 0, 0),(670,550),game) pygame.display.update() diff --git a/BlankProjectTemplate/src/highscore.py b/BlankProjectTemplate/src/highscore.py new file mode 100644 index 0000000..caf915e --- /dev/null +++ b/BlankProjectTemplate/src/highscore.py @@ -0,0 +1,52 @@ +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) diff --git a/BlankProjectTemplate/src/highscore.txt b/BlankProjectTemplate/src/highscore.txt new file mode 100644 index 0000000..4b3506c --- /dev/null +++ b/BlankProjectTemplate/src/highscore.txt @@ -0,0 +1,9 @@ +10 +20 +45 +3 +47 +10 +48 +48 +49 \ No newline at end of file -- GitLab