def die(self, killer): #Remove our character from the current tile's character attribute. selfTile = self.getTile() selfTile.character = NullCharacter() #put ourselves out of the way #self.xPos = -1 #self.yPos = -1 #print out to the screen what happened log(killer.name +" killed a " +self.name) #remove ourselves from the level we're on's character array self.level.characters.remove(self) #if the player killed us, give them some experience. if killer.isPlayer: killer.xp += self.xpValue #If we're the player, the game is over if self.isPlayer: #Revert the terminal to normal. kcurses.cursesCleanup() #let the player know what happened print "sorry you were killed by a " + killer.name #don't print a traceback, this isn't a bug #exit program exit(0)
def main(): # # # BASIC INITIALIZATION # # # #The height of our game window (In squares) levelHeight = 18 #The with (ingame squares, not curses coordinates) levelWidth = 36 #Initialize our screen mapScreen = kcurses.initCurses() # # # DUNGEON GENERATION # # # #Set up an empty array that will hold the levels of our dungeon. dungeon = [] #initialize our first level with the function from levelGenerator. #The boolean at the end of the function call #tells the generator to put the player on the level. s = levelGenerator.generateLevel(levelHeight, levelWidth, True) dungeon.append(mapObjects.Level(s)) #Generate three more levels for our dungeon. for i in range(4): s = levelGenerator.generateLevel(levelHeight, levelWidth, False) dungeon.append(mapObjects.Level(s)) #ship the dungeon into the characters file #(weird I know, might find a better way to do this later) characters.updateDungeon(dungeon) # # # INITIALIZE PLAYER # # # #Find our player in the first level of the dungeon, #and make them easier to find in the future. for character in dungeon[0].characters: if character.symbol == '@': player = character #Initialize certain player variables player.name = "foobar" player.currentLevel = 0 # # # BEGIN DRAW-INPUT LOOP # # # #initialize our input character variable c = 0 #while we don't recieve the quit character we keep executing the draw-getcharacter loop while chr(c) != 'q' and player.currentHp > 0: dungeon[player.currentLevel].clearTileValues() #draw our map and handle relevant input processTurn(c, dungeon[player.currentLevel], player) display.drawMap(mapScreen, player, dungeon[player.currentLevel].levelMap, levelHeight, levelWidth) #wait for a new keystroke c = mapScreen.getch() # # # FINISH RUNNING # # # #Return the terminal to working order. kcurses.cursesCleanup()
player.currentLevel = 0 # # # BEGIN DRAW-INPUT LOOP # # # #initialize our input character variable c = 0 #while we don't recieve the quit character we keep executing the draw-getcharacter loop while chr(c) != 'q' and player.currentHp > 0: dungeon[player.currentLevel].clearTileValues() #draw our map and handle relevant input processTurn(c, dungeon[player.currentLevel], player) display.drawMap(mapScreen, player, dungeon[player.currentLevel].levelMap, levelHeight, levelWidth) #wait for a new keystroke c = mapScreen.getch() # # # FINISH RUNNING # # # #Return the terminal to working order. kcurses.cursesCleanup() try: main() except: #If we catch an error it's important to restore the terminal #to it's original state or else it will be unusable. kcurses.cursesCleanup() #Provide a traceback if trace: traceback.print_exc() #Print a debug message if one is present if debug: print debug