Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from getpass import getuser
- from os.path import exists
- import time
- FILENAME = 'pontuacao.huebr'
- class Highscore(object):
- def __init__(self):
- self.clock = time.strftime('%H:%M:%S')
- self.date = time.strftime('%d/%m/%Y')
- self.user = getuser()
- self.__check()
- def __repr__(self, score):
- return 'Usuário {} pontuou {} às {} em {}'.format(self.user, score, self.clock, self.date)
- @staticmethod
- def __create():
- """
- Create the file
- """
- bits_init = '{}'.format(map(ord, 'RENI')).strip('[]').replace(',', '').replace(' ', '')
- with open(FILENAME, 'wb') as f:
- f.write(bits_init)
- return True if exists('scores.huebr') else False
- def __check(self):
- """
- Check if exists on the current path
- """
- if exists(FILENAME):
- if not self.__check_header():
- quit(-1)
- else:
- self.__create()
- def __check_header(self):
- """
- Check if header is valid, if wasn't exit with code error -1
- """
- buffer = open(FILENAME, 'rb').read(8)
- buffer = ' '.join([buffer[i:i + 2] for i in range(0, len(buffer), 2)]).split(' ')
- buffer = ''.join([chr(int(c)) for c in buffer])
- return 1 if buffer == 'RENI' else 0
- def check_score(self, score):
- pass
- def evaluate(self, score):
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement