Permalink
Browse files

added --player_name and finished highscore menu interface

  • Loading branch information...
1 parent 7e86d90 commit 6e4e97659db9718d0b5cc73b93f313ac2a684442 Joseph Bleau committed May 20, 2011
Showing with 38 additions and 5 deletions.
  1. +4 −0 README.txt
  2. +25 −3 game.py
  3. +9 −2 run_game.py
View
4 README.txt
@@ -2,6 +2,10 @@ Vanessa's Mahjong is a Mahjong-esque game written in Python (2.7) using PyGame (
To run the game simply point python at run_game.py or run_game.pyw.
+Currently, there is support for high-scores but no way to enter your name through the interface. At the time being use --player_name [name] at the command line to specify who will be playing.
+
+Currently, there is support for toggling music on/off but no way to do this in game. To disable music use --nosound at the command line.
+
To run the level editor type python --editor [filename]. If the filename does not exist it will be created in levels/.
While in the editor, you can press 's' to save and 'u' to remove your previously placed tile. Left click to place tiles. Tiles should stack pretty intuitively and will snap to a grid. Lastly, while in the editor you may use keys 1-9 to change your cursor and tile placed. Currently, this does not affect the tile in the game (which are random), but can be used to help you keep track of z-levels while in the editor.
View
28 game.py
@@ -58,7 +58,7 @@ def load_level(filename, rnd=False, enforceTwo=False):
return []
class Game:
- def __init__(self, editor=False, sound=True, filename=None):
+ def __init__(self, player_name='Player', editor=False, sound=True, filename=None):
# If true, editor is running, if not then
# we begin in the menu like normal.
@@ -76,7 +76,8 @@ def __init__(self, editor=False, sound=True, filename=None):
self.m_selector = 0 # Menu Selector
self.sound_on = sound # If sound is on
self.editor = editor # If the editor is running
- self.viewing_highscores_for = None
+ self.viewing_highscores_for = None # Used in highscore view screen
+ self.player_name = player_name # Current player's name
# State-based render handling
self.render_func = { 'playing' : self.render_playing, \
@@ -114,7 +115,7 @@ def write_score(self):
except IOError:
print "Score file doesn't yet exist, creating..."
- scores.append(('player',(pygame.time.get_ticks() - self.time_started)/1000))
+ scores.append((self.player_name,(pygame.time.get_ticks() - self.time_started)/1000))
if scores:
scores = sorted(scores, key=lambda s: int(s[01]))
@@ -288,6 +289,27 @@ def handle_highscores_input(self, event):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.state = 'menu'
+
+ if event.key == pygame.K_LEFT or \
+ event.key == pygame.K_RIGHT:
+
+ levels = os.listdir(os.path.abspath('levels/scores'))
+ max = len(levels)
+ if self.viewing_highscores_for:
+ selected = levels.index(self.viewing_highscores_for)
+ if not selected == None:
+ if event.key == pygame.K_LEFT:
+ if selected == 0:
+ selected = max-1
+ else:
+ selected -= 1
+ elif event.key == pygame.K_RIGHT:
+ if selected == max-1:
+ selected = 0
+ else:
+ selected += 1
+
+ self.viewing_highscores_for = levels[selected]
def render_highscores(self, screen):
pygame.draw.rect(screen,(0,0,0), (0,0,800,80))
View
11 run_game.py
@@ -16,20 +16,27 @@ def main():
editor = False
sound_on = True
+ player_name = 'Player'
if len(sys.argv) > 2 and '--editor' in sys.argv:
editor = True
pygame.mouse.set_visible(False)
-
i = sys.argv.index('--editor')
+
+
+ if len(sys.argv) > 2 and '--player_name' in sys.argv:
+ pi = sys.argv.index('--player_name')+1
+ player_name = sys.argv[pi]
+
if '--nosound' in sys.argv:
sound_on = False
+
if editor:
level_arg = sys.argv[i+1]
game = Editor(sound=sound_on, filename = level_arg)
else:
- game = Game(sound=sound_on)
+ game = Game(sound=sound_on, player_name=player_name)
while True:
for event in pygame.event.get():

0 comments on commit 6e4e976

Please sign in to comment.