From 1a425e4324c526beffd2c6e7ce5440b1317e6731 Mon Sep 17 00:00:00 2001 From: Dpk3062 Date: Wed, 02 Sep 2009 17:19:53 +0000 Subject: * Level Options menu has input handling * Filled in missing function comments * Removed path hard-coding * Added readme.txt with running instructions * Still having Git problems... --- diff --git a/docs/Readme.txt b/docs/Readme.txt new file mode 100644 index 0000000..0e19eee --- /dev/null +++ b/docs/Readme.txt @@ -0,0 +1,12 @@ +Muthris + +Required Software +* Python 2.6 +* lxml for Python XML processing (for Ubuntu: sudo apt-get install python-lxml) + +Running Muthris +0) Install the required software (see above) +1) Download the complete source code +2) Optional: Edit 'LoggingFile' in 'Muthris/src/utils/strs.py' to change the destination of the debug output +3) Change the working directory to Muthris' folder +4) Run: python ./src/setup/main.py diff --git a/docs/examples/config.xml b/docs/examples/config.xml index 8178cd6..f2b8a12 100644 --- a/docs/examples/config.xml +++ b/docs/examples/config.xml @@ -3,12 +3,12 @@ - + - + diff --git a/docs/examples/lvl-1.mlvl b/docs/examples/lvl-1.mlvl index 51eed41..f0788f6 100644 --- a/docs/examples/lvl-1.mlvl +++ b/docs/examples/lvl-1.mlvl @@ -45,12 +45,14 @@ + diff --git a/docs/examples/readme.txt b/docs/examples/readme.txt index 7bef7fa..b7da0f1 100644 --- a/docs/examples/readme.txt +++ b/docs/examples/readme.txt @@ -1,5 +1,5 @@ The Examples folder contains: * config.xml - An example Muthris configuration file * lvl-1.mlvl - An example level descriptor file -* profile.xml - An example player profile file +* profile.mpro - An example player profile file diff --git a/src/game/__init__.py b/src/game/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/game/__init__.py diff --git a/src/game/start.py b/src/game/start.py new file mode 100644 index 0000000..7b0b3f2 --- /dev/null +++ b/src/game/start.py @@ -0,0 +1,25 @@ +''' + +''' + +import curses +import config +from utils import strs + +# setup logging +import logging +logging.basicConfig(filename=strs.LoggingFile,level=logging.DEBUG) +log = logging.getLogger('game.start') + + + + +def startGame(data): + '''Called to start the level. The given data is the same data structure used by the menu system''' + #TODO Load the level scripts + #TODO Start the server + #TODO Start the client + #TODO Connect the client to the server + print('Wasn\'t that fun?') #TODO remove this line + pass + diff --git a/src/setup/config.py b/src/setup/config.py index e394665..c844781 100644 --- a/src/setup/config.py +++ b/src/setup/config.py @@ -46,7 +46,7 @@ def getProfiles(): return profiles def getProfile(name): - ''' ''' + '''Returns the player profile with the given name. If such a profile doesn't exist, one is created''' # search through the know profiles for the one with the given name profiles = getProfiles() @@ -85,8 +85,11 @@ def findFiles(folders, extension): '''Returns a list of all files with the given extension directly inside the given folders''' files = [] + #for each given folder, for dir in folders: contents = os.listdir(dir) + + #for each directory in the folder, for item in contents: item = dir + '/' + item # must convert the file/folder name into its complete path @@ -104,7 +107,7 @@ def findFiles(folders, extension): # ----------------------------------------------------------------------------- def createProfile(profileName): - ''' ''' + '''Creates and returns a new profile with the given profileName. This profile has not yet been saved to the disk''' log.debug('Creating a Profile with the name: ' + profileName) return Profile(name=profileName) @@ -131,7 +134,7 @@ def findProfileFolders(): # ----------------------------------------------------------------------------- def find(xpath): - ''' Returns the result of applying the given xpath onto the config file''' + '''Returns the result of applying the given xpath onto the config file''' config = utils.getXMLRoot(strs.ConfigFile) return config.xpath(xpath) @@ -140,6 +143,6 @@ def find(xpath): # ----------------------------------------------------------------------------- def setLastProfileName(name): - ''' ''' + '''Stores the name of the last used profile. This is so on next startup, the last used profile can start as the default player''' # TODO fill in this stub pass diff --git a/src/setup/main.py b/src/setup/main.py index c88cb46..eaa23af 100644 --- a/src/setup/main.py +++ b/src/setup/main.py @@ -6,9 +6,8 @@ if __name__ == '__main__': pass - import sys -sys.path.append('/home/doug/workspace/Muthris/src/') +sys.path.append('./src/') import menus from utils import strs @@ -18,9 +17,7 @@ import logging logging.basicConfig(filename=strs.LoggingFile,level=logging.DEBUG) log = logging.getLogger('setup.main') - # start the menus - menus.begin() print( 'done' ) diff --git a/src/setup/menus.py b/src/setup/menus.py index 2ac048d..471b545 100644 --- a/src/setup/menus.py +++ b/src/setup/menus.py @@ -5,6 +5,7 @@ import curses import config from utils import strs +from game import start # setup logging import logging @@ -37,7 +38,7 @@ class MenuData(object): # TODO: improve the menu system so it doesn't use recursion def mainMenu(data): - ''' ''' + '''Displays the 'Main Menu' and handles its input''' # we use the current profile, so make sure there is one if (data.profile == None) | (data.profile == ''): @@ -91,7 +92,7 @@ def mainMenu(data): mainMenu(data) def changePlayerMenu(data): - ''' ''' + '''Displays the 'Change Player Profile' menu and handles its input''' # create a list of players profiles = config.getProfiles() @@ -131,7 +132,7 @@ def changePlayerMenu(data): mainMenu(data) def playGameMenu(data): - ''' ''' + '''Displays the 'Play Game' menu and handles its input''' # create a list of levels if (data.levels == None) | (data.levels == []): @@ -177,7 +178,7 @@ def playGameMenu(data): levelOptionsMenu(data) def levelOptionsMenu(data): - ''' ''' + '''Displays the level options menu and handles its input''' # make sure there is a level if (data.level == None) | (data.level == ''): @@ -194,9 +195,9 @@ def levelOptionsMenu(data): # get the max score, max duration, and last time played profile = config.getProfile(data.profile) - stats.append('Max Score - ' + str(profile.getMaxScore(data.level))) + stats.append('Max Score - ' + str(profile.getMaxScore(data.level))) stats.append('Max Duration - ' + str(profile.getMaxDuration(data.level))) - stats.append('Last Played - ' + profile.getLastTimePlayed(data.level)) + stats.append('Last Played - ' + str(profile.getLastTimePlayed(data.level))) stats.append('') # configure the screen for our needs @@ -229,28 +230,34 @@ def levelOptionsMenu(data): # refresh and wait for valid user input data.screen.refresh() - c = data.screen.getstr() + c = data.screen.getch() # process input - if c == ord('1'): playGameMenu(data) - elif c == ord('c'): changePlayerMenu(data) - elif c == ord('e'): pass + if c == ord('p'): start.startGame(data) # TODO remove the recursiveness of the menu system + elif c == ord('m'): mainMenu(data) else: levelOptionsMenu(data) def skillLevelMenu(data): - ''' ''' - # check for required vars - - # clear the screen and display the title - # display the menu - # refresh the screen - # wait for input - # process input + '''Displays the 'Skill Level' menu and handles its input''' + # TODO: + # check for required vars + # clear the screen and display the title + # display the menu + # refresh the screen + # wait for input + # process input pass def numberOfPlayersMenu(data): - ''' ''' + '''Displays the 'Number of Players' menu and handles its input''' + # TODO: + # check for required vars + # clear the screen and display the title + # display the menu + # refresh the screen + # wait for input + # process input pass # ----------------------------------------------------------------------------- @@ -276,7 +283,7 @@ def displayPrompt(screen, lines, offset=0): # ----------------------------------------------------------------------------- def init(stdscr): - ''' ''' + '''Enters the menu system''' # create the menu's data data = MenuData() @@ -288,6 +295,6 @@ def init(stdscr): mainMenu(data) def begin(): - ''' ''' + '''Configures Curses''' curses.wrapper(init) diff --git a/src/setup/profile.py b/src/setup/profile.py index 3d45e9a..96b4caf 100644 --- a/src/setup/profile.py +++ b/src/setup/profile.py @@ -29,6 +29,7 @@ class Profile(object): else: # there is no XML representation of this Profile, so just store its name self.name = name + self.path = None pass def getName(self): @@ -36,7 +37,7 @@ class Profile(object): return self.name def getMaxScore(self, level=None, skill=None): - ''' ''' + '''Returns the player's max score corresponding to the given filters''' # if no path, then no XML to read for the max score if self.path == None: @@ -47,7 +48,7 @@ class Profile(object): return 1 def getMaxDuration(self, level=None, skill=None): - ''' ''' + '''Returns the player's max playing duration corresponding to the given filters''' # if no path, then no XML to read for the max duration if self.path == None: @@ -58,7 +59,7 @@ class Profile(object): return 1 def getLastTimePlayed(self, level=None, skill=None): - ''' ''' + '''Returns the player's max last time played corresponding to the given filters''' # if no path, then no XML to read for the last time played if self.path == None: return 0 diff --git a/src/setup/profiles.py b/src/setup/profiles.py index 3282a62..6320e01 100644 --- a/src/setup/profiles.py +++ b/src/setup/profiles.py @@ -1,5 +1,5 @@ ''' - +I don't think this class is used any more as its functions have been moved into config.py ''' import os # file path support @@ -15,15 +15,18 @@ log = logging.getLogger('setup.profiles') def findAllProfiles(): - ''' ''' + '''Returns a listing of all profiles''' + #TODO pass def getLastUsedProfile(): - ''' ''' + '''Returns the last used player profile''' + #TODO pass def createNewProfile(): - ''' ''' + '''Creates a new player profile''' + #TODO pass diff --git a/src/utils/strs.py b/src/utils/strs.py index 4059bbf..2a25db3 100644 --- a/src/utils/strs.py +++ b/src/utils/strs.py @@ -4,15 +4,15 @@ Created on Jul 5, 2009 @author: doug ''' -# files -ConfigFile = '/home/doug/workspace/Muthris/docs/examples/config.xml' -LoggingFile = '/tmp/muthris-dev.log' +# files and folders +ConfigFile = './docs/examples/config.xml' +LoggingFile = '/tmp/muthris-dev.log' #TODO move this into the ConfigFile? # file extensions Ext_Level = '.mlvl' Ext_Profile = '.mpro' -# XML locations +# XML locations (XPaths) XP_LevelFolderLocation = '/muthris/config/level-folders/folder/@location' XP_ProfileFolderLocation = '/muthris/config/profile-folders/folder/@location' XP_LastProfileName = '/muthris/config/last/profile/@name' -- cgit v0.9.1