Monster.zip

  • PUDN用户
    了解作者
  • Python
    开发工具
  • 2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2014-12-21 05:35
    上传日期
This a simple python based game. In this game you can move by W A S D keys. You should b careful not to be eaten by monster.
Monster.zip
  • Monster.py
    9.9KB
内容介绍
import sys import random #Definition the Main class class Main: max_width = 5 max_height = 5 character_alive = True character_won = False monster_awake = False monster_awakened = False monster_move_per_turn = 2 def __init__(self): self.display_menu() self.reset_current_game() def reset_current_game(self): self.character_position = [0,0] self.monster_position = [1,1] self.trap_position = [1,0] self.flask_position = [0,1] def reset_all_settings(self): self.character_alive = True self.character_won = False self.monster_awake = False self.monster_awakened = False def place_character(self): self.character_position = [0,0] def place_monster(self): self.monster_position = [random.randint(0,self.max_width -1),random.randint(0,self.max_height -1)] if(self.coordinate_collisions('monster','player')): self.place_monster() elif(self.coordinate_collisions('monster','flask')): self.place_monster() elif(self.coordinate_collisions('monster','trap')): self.place_monster() else: return True return True def place_trap(self): self.trap_position = [random.randint(0,self.max_width -1),random.randint(0,self.max_height -1)] if(self.coordinate_collisions('trap','player')): self.place_trap() elif(self.coordinate_collisions('trap','flask')): self.place_trap() elif(self.coordinate_collisions('trap','monster')): self.place_trap() else: return True return True def place_flask(self): self.flask_position = [random.randint(0,self.max_width -1),random.randint(0,self.max_height -1)] if(self.coordinate_collisions('flask','player')): self.place_flask() elif(self.coordinate_collisions('flask','monster')): self.place_flask() elif(self.coordinate_collisions('flask','trap')): self.place_flask() else: return True return True def display_menu(self): menu_list = ['Start New Game', '[Save Game]', '[Load Game]', 'Customize Setup', 'Exit'] print('Type the number of your choice') print() for i in range(1,len(menu_list)+1): print(str(i)+ '. ' + menu_list[i-1]) choice = input('Your Choice: ') self.menu_choice(choice) def coordinate_collisions(self, coord1,coord2): if(coord1 == 'monster'): first = self.monster_position elif(coord1 == 'flask'): first = self.flask_position elif(coord1 == 'trap'): first = self.trap_position elif(coord1 == 'player'): first = self.character_position else: return None if(coord2 == 'monster'): second = self.monster_position elif(coord2 == 'flask'): second = self.flask_position elif(coord2 == 'trap'): second = self.trap_position elif(coord2 == 'player'): second = self.character_position else: return None if(coord1 == coord2): return None if(first[0] == second[0] and first[1] == second[1]): return True else: return False def start_new_game(self): self.reset_all_settings() self.reset_current_game() self.setup_game() def setup_game(self): self.place_character() self.place_monster() self.place_trap() self.place_flask() self.draw_grid() def create_setup(self): self.reset_all_settings() print('This option lets you set the settings for monster!') width_choice = input('How wide do you want the game board to be? (Default: 5) ') try: width_choice = int(width_choice) except ValueError: width_choice = 5 self.max_width = width_choice height_choice = input('How high do you want the game board to be? (Default: 5) ') try: height_choice = int(height_choice) except ValueError: height_choice = 5 self.height_choice = height_choice monster_move_count_choice = input('How many moves should the monster get for each of your move (Default: 2) ') try: monster_move_count_choice = int(monster_move_count_choice) except ValueError: monster_move_count_choice = 2 self.monster_move_per_turn = monster_move_count_choice self.setup_game() def menu_choice(self,choice): try: choice = int(choice) except ValueError: choice = 0 if(choice == 1): self.start_new_game() elif(choice == 2): pass elif(choice == 3): pass elif(choice == 4): self.create_setup() elif(choice == 5): sys.exit(0) else: print('That wasn\'t a valid option. Try again\n') self.display_menu() def collision_check(self): if(self.coordinate_collisions('player','monster')): self.character_alive = False return True elif(self.coordinate_collisions('player','flask')): self.character_won = True return True elif(self.coordinate_collisions('player','trap')): self.monster_awakened = True self.trap_position = [-1,-1] return True return False def check_boundary(self, new_x, new_y): min_width = 0 min_height = 0 if(new_x < min_width or new_x == self.max_width or new_y < min_height or new_y == self.max_height): return False else: return True def player_move(self,choice): current_x = self.character_position[0] current_y = self.character_position[1] if(choice == 'W' or choice == 'w'): if(self.check_boundary(current_x, current_y - 1) == False): return False else: self.character_position = [current_x, current_y - 1] return True elif(choice == 'A' or choice == 'a'): if(self.check_boundary(current_x - 1, current_y) == False ): return False else: self.character_position = [current_x - 1, current_y] return True elif(choice == 'S' or choice == 's'): if(self.check_boundary(current_x, current_y + 1) == False ): return False else: self.character_position = [current_x, current_y + 1] return True elif(choice == 'D' or choice == 'd'): if(self.check_boundary(current_x + 1, current_y) == False ): return False else: self.character_position = [current_x + 1, current_y] return True else: return False def move_monster(self): moves_left = self.monster_move_per_turn while(moves_left > 0): mon_x = self.monster_position[0] mon_y = self.monster_position[0] player_x = self.character_position[0] player_y = self.character_position[1] if(player_x - mon_x != 0): if(player_x - mon_x < 0): self.monster_position = [mon_x - 1, mon_y] else: self.monster_position = [mon_x + 1, mon_y] else: if(player_y - mon_y < 0): self.monster_positi
评论
    相关推荐
    • VRS51L3074_Keil.rar
      this a c program,be careful
    • Exiled_Bot_Beta_v0.24h.zip
      BE CAREFUL !! Botting more than 10h per day will most probably get you banned.
    • pos.rar
      Many terminals can t move the cursor when in standout mode. We must be careful, however, because HP s and cookie terminals will drop a cookie when we do this.
    • x87trigOOR.rar
      Tests out of range handling for FSIN, FCOS, FSINCOS and FPTAN. Be careful with the inline assembly this program is compiled as both a 32-bit and 64-bit test.
    • Xpoll.rar
      we have to pay the price of having an array here, unlike with bitmasks calling twice FD_SET with the same fd is not transparent, so be careful.
    • lpar.rar
      Enables debugging of low-level hash table routines - careful.
    • posix_types_32.rar
      This file is generally used by user-level software, so you need to be a little careful about namespace pollution etc. Also, we cannot assume GCC is being used.
    • genex.rar
      Be careful when changing this, it has to be at most 128 bytes to fit into space reserved for the exception handler.
    • Lecture3.rar
      Very good, but you have to use with careful
    • qpopper2.53.tar.Z
      pop3 server