Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/highScores.py
blob: 61fc0342e42150bff6ec9b95ebfd9804353a7e09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os,sys
import pygame, runEsquiador
import txtlib
from pygame.locals import *
from runEsquiador import *
from constants import *

class HighScore():

	def loadscores(self):
		items = []
		file = open('score.dat','r')
	       
		for line in file.readlines():
			temp = line.split('\t')
			items.append((int(temp[1].strip()), (temp[0])))
		file.close()
	       
		return items
		
	def numeric_compare(self, x, y):
		if x[0]>y[0]:
		    return 1
		elif x[0]==y[0]:
		    if x[2]<y[2]:
			return 1
		    elif x[2]==y[2]:
			return 0;
		    else:
			return -1;
		else: # x<y
		    return -1

	def savescores(self, items):
		items.sort(self.numeric_compare)
		items.reverse()
		file = open('score.dat', 'w')
		for score, name  in items[:5]:
		    output = name + "\t" + str(score) + "\n"
		    file.write(output)
		file.close()

	def MoveCharUp(self, char):
		newstuffs = ord(char) + 1
		if newstuffs > 90:
		    newstuffs = 65
		return chr(newstuffs)
		
	def MoveCharDown(self, char):
		newstuffs = ord(char) - 1
		if newstuffs < 65:
		    newstuffs = 90
		return chr(newstuffs)

	def __init__(self):
		self.thefont = pygame.font.Font(os.path.join('fonts', 'ice_sticks.ttf'), 18)
		self.titlefont = pygame.font.Font(os.path.join('fonts', 'ice_sticks.ttf'), 35)
		self.scores = self.loadscores()

	def mainHighScores(self):
		screen = pygame.display.set_mode(screen_size)
		items = self.loadscores()
		self.savescores(items)
		sal = ""
		for score, name in items[:5]:
			sal += name + "\t" + str(score) + "\n"
		print sal

		text = txtlib.Text((screen_size[0]-200,screen_size[1]-200), './fonts/ice_sticks.ttf')
		text.text = '''Esquiador
		\nPuntajes mas altos:\n''' + sal 

		text.add_style(0, 600, txtlib.SIZE, (screen_size[0]*25)/800)
		text.update()

		screen.blit(text.area, (100, 100))
		pygame.display.flip()
	
		while True:

			for event in pygame.event.get():
				if event.type == pygame.QUIT:
					exit(0)
				if event.type == KEYDOWN:
				        if event.key == K_ESCAPE:
				        	return