added test program for highscore entry
This commit is contained in:
parent
b701f3215c
commit
afa151126d
105
highscore-test.py
Normal file
105
highscore-test.py
Normal file
@ -0,0 +1,105 @@
|
||||
import pygame, signal, sys, time, os
|
||||
from pygame.locals import *
|
||||
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
||||
#colors
|
||||
redColor = pygame.Color(255, 0, 0)
|
||||
blackColor = pygame.Color(0, 0, 0)
|
||||
whiteColor = pygame.Color(255, 255, 255)
|
||||
grayColor = pygame.Color(128, 128, 128)
|
||||
mainFontColor = redColor
|
||||
|
||||
MAX_NAME_LENGTH = 10
|
||||
|
||||
#fonts
|
||||
font1 = pygame.font.Font('freesansbold.ttf', 16)
|
||||
|
||||
pygame.mouse.set_visible(True) # show mouse
|
||||
|
||||
screen = pygame.display.set_mode((640, 480), pygame.RESIZABLE)
|
||||
|
||||
def clearScreen():
|
||||
screen.fill(blackColor)
|
||||
return
|
||||
|
||||
def enterName():
|
||||
clearScreen()
|
||||
print('text entry started')
|
||||
name = ''
|
||||
while True:
|
||||
clearScreen()
|
||||
textbox_surface = font1.render('Enter name: ' + str(name), True, mainFontColor)
|
||||
textbox_rectangle = textbox_surface.get_rect()
|
||||
textbox_rectangle.topleft = (10, 30)
|
||||
screen.blit(textbox_surface, textbox_rectangle)
|
||||
pygame.display.flip()
|
||||
for event in pygame.event.get():
|
||||
if len(name) < MAX_NAME_LENGTH:
|
||||
if event.type == KEYDOWN:
|
||||
if event.key == pygame.K_BACKSPACE:
|
||||
name = name[:-1]
|
||||
else:
|
||||
name += event.unicode
|
||||
elif event.key == pygame.K_BACKSPACE:
|
||||
name = name[:-1]
|
||||
|
||||
elif event.type == KEYDOWN and event.key == pygame.K_RETURN:
|
||||
clearScreen()
|
||||
return name
|
||||
clearScreen()
|
||||
name = 'Error'
|
||||
return name
|
||||
|
||||
hs1_name = "Fritz"
|
||||
hs2_name = "Bernd"
|
||||
hs3_name = "Max"
|
||||
|
||||
hs1_time = "100"
|
||||
hs2_time = "200"
|
||||
hs3_time = "300"
|
||||
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
clearScreen()
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == KEYDOWN and event.key == K_ESCAPE:
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
if event.type == KEYDOWN and event.key == K_BACKSPACE:
|
||||
print ('bs')
|
||||
hs1_name = enterName()
|
||||
|
||||
header_surface = font1.render('Dr' + u'ü' + 'cken Sie Start!', True, mainFontColor)
|
||||
header_rectangle = header_surface.get_rect()
|
||||
header_rectangle.topleft = (10, 10)
|
||||
|
||||
screen.blit(header_surface, header_rectangle)
|
||||
|
||||
|
||||
score1_surface = font1.render(hs1_name + ": " + hs1_time + 's', True, mainFontColor)
|
||||
score1_rectangle = score1_surface.get_rect()
|
||||
score1_rectangle.topleft = (10, 30)
|
||||
|
||||
# score2_surface = font1.render(hs2_name + ": " + hs2_time + 's', True, mainFontColor)
|
||||
# score2_rectangle = score2_surface.get_rect()
|
||||
# score2_rectangle.topleft = (10, 50)
|
||||
|
||||
# score3_surface = font1.render(hs3_name + ": " + hs3_time + 's', True, mainFontColor)
|
||||
# score3_rectangle = score3_surface.get_rect()
|
||||
# score3_rectangle.topleft = (10, 70)
|
||||
|
||||
screen.blit(score1_surface, score1_rectangle)
|
||||
# screen.blit(score2_surface, score2_rectangle)
|
||||
# screen.blit(score3_surface, score3_rectangle)
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
time.sleep(1/60)
|
||||
|
Loading…
Reference in New Issue
Block a user