else: # Player.move_player('z',game_state,Fireball,1) x,y,d=Player.move_player('z',game_state,Fireball,1,Player,Donkey) # print str(x)+" " + str(y) if Player.markk!=1: if self.count < len(self.fireballpos): self.fireballpos[self.count]=((x,y),d) self.count=self.count+1 # remove_fireball function eliminates all the fireballs after the player dies in order to generate a new board for replay def remove_fireball(self,game_state,Player,Fireball): count=0 for (((px,py),d)) in self.fireballpos: self.px=px self.py=py self.d=d if px%4!=0: if py == game_state.place[(px)/4][1] or py == game_state.place[(px)/4][2]: game_state.layout[px][py]='H' else: game_state.layout[self.px][self.py]=' ' else: if py == game_state.place[(px)/4-1][1] or py == game_state.place[(px)/4-1][2]: game_state.layout[px][py]='H' else: game_state.layout[self.px][self.py]=' ' game_state=board1.game() Fireball=fireball(game_state) Player=layout.player(game_state)
def main(): validlist=['a','d','w','s',' ','q'] game_state=board1.game() # a player can play a game thrice i.e. player has three lives lives=3 levell=1 freq=10 os.system("clear") while lives>0 : freq=freq-2 print "level" + " " + str(levell) Donkey=donkey(game_state) Donkey.donkeypos(game_state) game_state.remove_coins() game_state.regenerate_board() game_state.generate_coins() Player=player(game_state) Fireball=fireball1.fireball(game_state) count=0 game_state.trial() game_state.checkpl() game_state.print_board() # continue the game untill the player dies or the player wins # generate a new fireball after every 11 moves while game_state.gameover==False and Player.won!=1: if count%freq==0: Fireball.generate_fireball(game_state,Player,Donkey) print "Enter Move: " key_input=read_in.getchar() count=count+1 Donkey.move_donkey(game_state,1) Fireball.move_fireball(game_state,Player,Fireball,Donkey) ff=0 if key_input in validlist: if key_input==" ": print "Enter Move:" key_input=read_in.getchar() if key_input=='a': key_input='g' elif key_input=='d': key_input='h' else: ff=1 if ff!=1: x,y,d=Player.move_player(key_input,game_state,Fireball,0,Player,Donkey) os.system("clear") game_state.trial() game_state.print_board() Player.printscore(game_state) Player.getposition() # if the player dies anf he/she has lives left , then restart the game with same layout but different position of fireballs and donkey and coins # also player gets penalised by 25 points if game_state.gameover==True: game_state.layout[Donkey.xdonkey][Donkey.ydonkey]=' ' Player.getposition() game_state.layout[Player.xplayer][Player.yplayer]=' ' Fireball.remove_fireball(game_state,Player,Fireball) os.system("clear") game_state.cyan("Try Again") lives=lives-1 game_state.score=game_state.score-25 Donkey.remove_donkey(game_state) game_state.gameover=False # if the player wins then regenerate the game with a new layout representing a new level if Player.won==1: os.system("clear") game_state.cyan("Queen Rescued") game_state.yellow("New Game") # os.system("clear") game_state=board1.game() levell=levell+1 if lives==0: os.system("clear") game_state.red("GAME OVER") Player.printscore(game_state)