示例#1
0
文件: zork.py 项目: rubyja/343-zork
class main:
    neighborhood = Neighborhood.Neighborhood(10, 50, False)
    house = Neighborhood.Neighborhood(0, 0, True)
    neighborhood.printGrid(neighborhood.makeGrid())
    house.printGrid(house.makeGrid())
    you = Person.Player(getRand(100, 125), getRand(10, 25))
    hp = you.hp
    atk = you.atk
    print(hp)
    print(atk)
示例#2
0
	def __init__(self):	
		
		# Neighborhood class instantiation
		self.hood = Neighborhood()
		# Get neighborhood grid, where house objects are located
		self.grid = self.hood.getGrid()
		# Instance of class player, which is the current player
		self.player1 = Player()
		# The variables turn and state are used to keep track of the player's 
		# current state
		self.turn = 0
		self.state = 0
示例#3
0
 def __init__(self):
     self.neighborhood = Neighborhood.Neighborhood()
     self.neighborhood.add_observer(self)
     self.player = Player.Player()
     self.player.add_observer(self)
     self.currenthome = 0
     self.gameover = False
示例#4
0
    def __init__(self):
        self.player = Player.Player()
        self.neighborhood = Neighborhood.Neighborhood(self)
        self.currentCol = 0
        self.currentRow = 0
        self.currentHome = self.neighborhood.getGrid()[self.currentRow][
            self.currentCol]
        self.totalMonsters = 0

        # Loop through every Monster in every Home and count all non Person Monsters
        for x in range(len(self.neighborhood.getGrid())):
            for y in range(len(self.neighborhood.getGrid()[x])):
                for z in range(len(
                        self.neighborhood.getGrid()[x][y].getList())):
                    if self.neighborhood.getGrid()[x][y].getList()[z].getType(
                    ) != 'Person':
                        self.totalMonsters += 1
示例#5
0
 def __init__(self):
     self.player = Player.Player()
     self.nbHood = Neighborhood.Neighborhood(randint(2, 5))
     self.turn = True  # player = true monster = false once anyone attacks you switch to what is itsnt now
     self.over = False
示例#6
0
    plb.imshow(dapi)
    plb.show()
#==============================================================================
#     Segmentation
#==============================================================================
    small = nd.zoom(dapi, 0.5)
    labelDAPI, n= nd.label(ex.LowResSegmentation(small))
    obj = ex.extractParticles(small,labelDAPI)
    ex.makeMosaic(obj,20,10000)
    print n
    #broken = pymorph.sedisk()
    pixel_distance = 1
    #se = np.array([[1,1,1],[1,1,1],[1,1,1]])
    se = np.uint(pymorph.sedisk(pixel_distance)) #2+1+2=5
    print se
    print 'find neighbours at ',pixel_distance, 'from particles'
    g = ng.findneighborhoods(labelDAPI, se)
    print 'converting to networkx'
    G = ng.convertToGraph(g, noBack=True)
#==============================================================================
#     Graphic display
#==============================================================================
    plb.subplot(121, frameon = False, xticks = [], yticks = [])
    plb.imshow(small)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    plb.subplot(122, frameon = False, xticks = [], yticks = [])
    plb.imshow(labelDAPI)
    plb.show()
    #plb.subplot(133)
    nx.draw_networkx(G)
    plb.show()
示例#7
0
 def construct_neighbor(self):
     print "Begin constructing neighborhood graph:"
     nb = Neighborhood()
     dm = scipy.misc.imread("density.png").astype(np.float)
     #dm=plt.imread("density.png")
     nb.set_density(0.5)
     nb.set_densitymap(dm)
     nb.sample()
     self.strokelist = [[] for i in range(len(nb.samplelist))]
     im = scipy.misc.imread("edge.png").astype(np.float)
     #im=plt.imread("edge.png")
     nb.set_image(im)
     nb.set_iternum(50)
     nb.set_orientation()
     nb.construct_gragh()
     self.neighborhood_graph = nb
     print 50 * "-"
     penality = 0
     
 weights = Markets.getWeights(sk)
 if(intensification >= Util.INTENSIFICATION):
     # Per l'intensificazione si cerca di rifornire quelli che si riforniscono più spesso
     # Si selezionano quindi quelli riforniti di meno
     weights = sorted(weights, key = itemgetter(2), reverse=True)
     weights = sorted(weights, key = itemgetter(0))
     print "Intensification!"
     
     i = 0
     w, h, t0 = weights[i]
     while(len(neighborhood) == 0):
         
         if(sk[h].x[t0] > 0):
             returned = Neighborhood.new(neighborhood, bestsolution, bestsolutioncost, sk, skcost, h, t0, tabulist, cycles_dictionary, penality)
         
         i = i + 1
         w, h, t0 = weights[i]
         
 else:
     if(diversification >= Util.DIVERSIFICATION):
         weights = sorted(weights, key = itemgetter(2), reverse=True)
         weights = sorted(weights, key = itemgetter(0), reverse=True)
         print "Diversifcation!"            
         
         i = 0
         w, h, t0 = weights[i]
         while(len(neighborhood) == 0):
         
             if(sk[h].x[t0] > 0):
示例#9
0
class Game:
    _sizeCol = 4
    _sizeRow = 4
    _neighborhood = None
    _player = None
    _gameover = False
    _gamewon = False

    def __init__(self):
        self._player = Player(self)
        self._neighborhood = Neighborhood(self._sizeCol, self._sizeRow, self, self._player)

    # Checks if the player has won
    def checkwin(self):
        pop = self._neighborhood.getmonsterpopulation()
        if pop <= 0:
            self.gamewon()

    # Declares that the game has been won
    def gamewon(self):
        self._gameover = True
        self._gamewon = True

    # Declares that the game has been lost
    def gamelost(self):
        self._gameover = True

    # Returns the status of the game
    def gamestatus(self):
        return self._gameover

    # Displays the map, H = Home, C = Completed Home, _ is empty and P is for the player
    def displaymap(self):
        grid = self._neighborhood.getgrid()
        playerlocation = self._player.getlocation()
        for row in range(self._sizeCol):
            line = ""
            for col in range(self._sizeRow):
                currentlocation = (col, row)
                if playerlocation == currentlocation:
                    line += "P "
                elif isinstance(grid[col][row], Home):
                    if grid[col][row].getmonsterpopulation() > 0:
                        line += "H "
                    else:
                        line += "C "
                else:
                    line += "_ "
            print(line)

    # This function checks the condition of whether the player is currently at a house
    def checkplayerathouse(self):
        playerlocation = self._player.getlocation()
        if isinstance(self._neighborhood.getgrid()[playerlocation[0]][playerlocation[1]], Home):
            if self._neighborhood.getgrid()[playerlocation[0]][playerlocation[1]].getmonsterpopulation() > 0:
                return True
            else:
                return False
        else:
            return False

    # This is the battle function for the game
    def startbattle(self):
        inbattle = True
        while inbattle:
            print("\n\n\n\n\n\n\n\n\n\n\n\n\n")
            hp = self._player.gethealth()
            print("Your health is: " + str(hp))
            home = self._neighborhood.getgrid()[self._player.getlocation()[0]][self._player.getlocation()[1]]
            personcount = 0
            zombiecount = 0
            vampirecount = 0
            ghoulcount = 0
            werewolfcount = 0
            for monster in home.getmonsters():
                if isinstance(monster, Person):
                    personcount += 1
                elif isinstance(monster, Zombie):
                    zombiecount += 1
                elif isinstance(monster, Vampire):
                    vampirecount += 1
                elif isinstance(monster, Ghoul):
                    ghoulcount += 1
                else:
                    werewolfcount += 1

            print("There is " + str(personcount) +
                " people, " + str(zombiecount) +
                " zombies " + str(vampirecount) +
                " vampires " + str(werewolfcount) +
                " werewolfs and " + str(ghoulcount) +
                " ghouls.")

            print("Pick your weapon (0-10): ")

            count = 0
            for weapon in self._player.getinventory():
                print(str(count) + ": " + weapon.getname() + " durability: " + str(weapon.getdurability()))
                count += 1

            validchoice = False
            userChoice = 0
            while validchoice == False:
                ui = input("Select Attack: ")
                try:
                    userChoice = int(ui)
                    if len(self._player.getinventory()) > userChoice >= 0:
                        validchoice = True
                    else:
                        print("Not valid input")
                except:
                    print("Not valid input")

            weapon = self._player.getinventory()[int(userChoice)]
            weapon.use()
            for monster in home.getmonsters():
                monster.receiveattack(self._player.getdamage(), weapon)
                self._player.receivedamage(monster.attack())

            if home.getmonsterpopulation() <= 0:
                inbattle = False
            elif self._player.gethealth() <= 0:
                inbattle = False

    # Moves and handles errors regarding player movement on the map
    def moveplayer(self, ui):
        if ui is "u":
            if self._player.getlocation()[1] > 0:
                self._player.moveup()
        elif ui is "d":
            if self._player.getlocation()[1] < (self._sizeCol-1):
                self._player.movedown()
        elif ui is "l":
            if self._player.getlocation()[0] > 0:
                self._player.moveleft()
        elif ui is "r":
            if self._player.getlocation()[0] < (self._sizeRow-1):
                self._player.moveright()
示例#10
0
 def __init__(self):
     self._player = Player(self)
     self._neighborhood = Neighborhood(self._sizeCol, self._sizeRow, self, self._player)
示例#11
0
class Game:

    def __init__(self):
        self.game_over = False
        self.in_house = False

    #create the board
    def init_board(self):
        self.neighborhood = Neighborhood(10, 10)
        self.grid = self.neighborhood.make_grid(self.neighborhood.height, self.neighborhood.width)
        self.grid = self.neighborhood.fill_neighborhood(self.grid)

    #spawn and put player on random space in the grid
    def spawn_player(self, player):
        rand_width = randint(0, self.neighborhood.width - 1)
        rand_height = randint(0, self.neighborhood.height - 1)
        self.grid[rand_width][rand_height].append(player)
        self.current_width = rand_width
        self.current_height = rand_height

    #some instructions for the user
    def instructions(self):
        print("This is the simulation for how to save the world from the candy monsters.")
        print()
        print("You win when all of the houses inhabitants are converted from monsters to people")
        print()
        print("You've got some work to do...you currently have a %dx%d grid of houses full of monsters."  %(self.neighborhood.width, self.neighborhood.height))
        print()
        print("Some monsters in the houses might already be people...they want to help you.")
        print("The rest of the monsters are assholes who do NOT want to help. Sorry.")
        print()
        print("What you're allowed to do outside of houses:")
        print("W: Move North    A: Move West    S: Move South   D: Move East    E: Enter House")
        print()
        print("What you're allowed to do inside of houses:")
        print("Q: Leave House   F: Fight Monsters   0-9: Choose Weapon")
        print()
        print("Best of luck!")
        print()

    #gets and validates the user input for a move
    def get_user_move(self, player):
        possible_moves = {'w': 'North', 's': 'South', 'd': 'East', 'a': 'West', 
                            'W': 'North', 'S': 'South', 'D': 'East', 'A': 'West',
                            'e': 'Enter', 'E': 'Enter', 'q': 'Exit', 'Q': 'Exit',
                            'f': 'Fight', 'F': 'Fight'}
        if self.in_house:
            self.see_contents(player, self.current_width, self.current_height)
        move = input("What would you like to do?")
        if move in possible_moves:
            the_move = possible_moves[move]
            self.movement(player, the_move)
        else:
            print()
            print("Can't do that right now!")
            print()

    #all of the options that the player can do
    def movement(self, player, the_move):
        if the_move == 'North' and not self.in_house:
            self.move_north(player, self.current_width, self.current_height)
        elif the_move == 'South' and not self.in_house:
            self.move_south(player, self.current_width, self.current_height)
        elif the_move == 'East' and not self.in_house:
            self.move_east(player, self.current_width, self.current_height)
        elif the_move == 'West' and not self.in_house:
            self.move_west(player, self.current_width, self.current_height)
        elif the_move == 'Enter' and not self.in_house:
            self.enter_house(player, self.current_width, self.current_height)
        elif the_move == 'Exit' and self.in_house:
            self.exit_house(player)
        elif the_move == 'Fight' and self.in_house:
            self.fight(player, self.current_width, self.current_height)
        else:
            print("Invalid move")

    #moves the player up one spot in the grid
    def move_north(self, player, current_width, current_height):
        if current_height - 1 >= 0:
            self.grid[current_width][current_height].pop(len(self.grid[current_width][current_height]) - 1)
            current_height = current_height - 1
            self.grid[current_width][current_height].append(player)
            self.current_width = current_width
            self.current_height = current_height
            current_location = (self.current_width, self.current_height)
            print("Where you are: (%s, %s)" %current_location)
        else: 
            print("Stay in the neighborhood to save the world!")

    #moves the player down one spot in the grid
    def move_south(self, player, current_width, current_height):
        if current_height + 1 < self.neighborhood.height:
            self.grid[current_width][current_height].pop(len(self.grid[current_width][current_height]) - 1)
            current_height = current_height + 1
            self.grid[current_width][current_height].append(player)
            self.current_width = current_width
            self.current_height = current_height
            current_location = (self.current_width, self.current_height)
            print("Where you are: (%s, %s)" %current_location)
        else: 
            print("Stay in the neighborhood to save the world!")
    
    #moves the player right one spot in the grid
    def move_east(self, player, current_width, current_height):
        if current_width + 1 < self.neighborhood.width:
            self.grid[current_width][current_height].pop(len(self.grid[current_width][current_height]) - 1)
            current_width = current_width + 1
            self.grid[current_width][current_height].append(player)
            self.current_width = current_width
            self.current_height = current_height
            current_location = (self.current_width, self.current_height)
            print("Where you are: (%s, %s)" %current_location)
        else: 
            print("Stay in the neighborhood to save the world!")
    
    #moves the player left one spot in the grid
    def move_west(self, player, current_width, current_height):
        if current_width - 1 >= 0:
            self.grid[current_width][current_height].pop(len(self.grid[current_width][current_height]) - 1)
            current_width = current_width - 1
            self.grid[current_width][current_height].append(player)
            self.current_width = current_width
            self.current_height = current_height
            current_location = (self.current_width, self.current_height)
            print("Where you are: (%s, %s)" %current_location)
        else: 
            print("Stay in the neighborhood to save the world!")
    
    #allow the player to see the contents of the house
    def enter_house(self, player, current_width, current_height):
        self.in_house = True
        self.see_contents(player, current_width, current_height)
        print("You can either fight or leave the house")
    
    #remove the user from the house and allow for movement again
    def exit_house(self, player):
        self.in_house = False

    #handles the fight interaction between the player and the monsters
    def fight(self, player, current_width, current_height):
        current_weapons = self.see_weapons(player)
        self.choose_weapon()
        try:
            user_input = int(input("Enter which weapon:")) - 1
            if user_input > 9 or user_input < -1:
                self.enter_valid_value()
            else: 
                if user_input == -1:
                    user_input = 9
                if current_weapons[user_input].weapon_name == 'Hershey Kisses':
                    self.attack_hershey_kisses(player, current_width, current_height)
                elif current_weapons[user_input].weapon_name == 'Nerd Bombs':
                    if current_weapons[user_input].use_value > 0:
                        self.attack_nerd_bombs(player, current_width, current_height, current_weapons[user_input].attack)
                        current_weapons[user_input].use_value = current_weapons[user_input].use_value - 1
                    else:
                        self.choose_new_weapon() 
                elif current_weapons[user_input].weapon_name == 'Chocolate Bars':
                    if current_weapons[user_input].use_value > 0:
                        self.attack_chocolate_bars(player, current_width, current_height, current_weapons[user_input].attack)
                        current_weapons[user_input].use_value = current_weapons[user_input].use_value - 1
                    else:
                        self.choose_new_weapon() 
                elif current_weapons[user_input].weapon_name == 'Sour Straws':
                    if current_weapons[user_input].use_value > 0:
                        self.attack_sour_straws(player, current_width, current_height, current_weapons[user_input].attack)
                        current_weapons[user_input].use_value = current_weapons[user_input].use_value - 1
                    else:
                       self.choose_new_weapon() 
        except ValueError:
            self.enter_valid_value()
    
    #message to choose weapon, was written for readability
    def choose_weapon(self):
        print()
        print("Choose which weapon to fight with.")
        print()

    #message to choose new weapon, was written for readability
    def choose_new_weapon(self):
        print()
        print("Choose a different weapon")
        print()
    
    #message to user to enter a valid input, was written for readability
    def enter_valid_value(self):
        print()
        print("Enter a valid value from 0-9")
        print()

    #handles monster attack to the user
    def monster_attack(self, monster, player):
        player.hp = player.hp - monster.attack

    #specific attack for when the user selects to use hershey kisses        
    def attack_hershey_kisses(self, player, current_width, current_height):
        monsters_in_house = self.grid[current_width][current_height]
        for i, monster in enumerate(monsters_in_house):
            if type(monster) is not Person and type(monster) is not Player:
                monsters_in_house[i].health = monsters_in_house[i].health - player.base_attack
                if monsters_in_house[i].health <= 0:
                    monsters_in_house[i] = Person()
                else:    
                    self.monster_attack(monster, player)
            elif type(monster) is Person:
                player.hp = player.hp + 1
            else:
                print()
        if player.hp <= 0 :
            self.end_game()

    #specific attack for when the user selects to use nerd bombs           
    def attack_nerd_bombs(self, player, current_width, current_height, modifier):
        monsters_in_house = self.grid[current_width][current_height]
        for i, monster in enumerate(monsters_in_house):
            if type(monster) is not Person and type(monster) is not Player:
                if type(monster) is Ghoul:
                    monsters_in_house[i].health = monsters_in_house[i].health -  (5 * player.base_attack)
                else:
                    monsters_in_house[i].health = monsters_in_house[i].health - (modifier * player.base_attack)
                if monsters_in_house[i].health <= 0:
                    monsters_in_house[i] = Person()
                else:    
                    self.monster_attack(monster, player)
            elif type(monster) is Person:
                player.hp = player.hp + 1
            else:
                print("")
        if player.hp <= 0 :
            self.end_game()
    
    #specific attack for when the user selects to use chocolate bars
    def attack_chocolate_bars(self, player, current_width, current_height, modifier):
        print(modifier)
        monsters_in_house = self.grid[current_width][current_height]
        for i, monster in enumerate(monsters_in_house):
            if type(monster) is not Person and type(monster) is not Player:
                if type(monster) is Vampire or Werewolf:
                    monsters_in_house[i].health = monsters_in_house[i].health - player.base_attack
                else:
                    monsters_in_house[i].health = monsters_in_house[i].health - (modifier * player.base_attack)
                if monsters_in_house[i].health <= 0:
                    monsters_in_house[i] = Person()
                else:    
                    self.monster_attack(monster, player)
            elif type(monster) is Person:
                player.hp = player.hp + 1
            else:
                print("")
        if player.hp <= 0 :
            self.end_game()

    #specific attack for when the user selects to use sour straws 
    def attack_sour_straws(self, player, current_width, current_height, modifier):
        monsters_in_house = self.grid[current_width][current_height]
        for i, monster in enumerate(monsters_in_house):
            if type(monster) is not Person and type(monster) is not Player:
                if type(monster) is Zombie:
                    monsters_in_house[i].health = monsters_in_house[i].health -  (2 * (modifier * player.base_attack))
                elif type(Monster) is Werewolf:
                    monsters_in_house[i].health = monsters_in_house[i].health - player.base_attack
                else:
                    monsters_in_house[i].health = monsters_in_house[i].health - (modifier * player.base_attack)
                if monsters_in_house[i].health <= 0:
                    monsters_in_house[i] = Person()
                else:    
                    self.monster_attack(monster, player)
            elif type(monster) is Person:
                player.hp = player.hp + 1
            else:
                print("")
        if player.hp <= 0 :
            self.end_game()
    
    def end_game(self):
        self.game_over = True;
        print("You died!")

    #shows monsters in the house
    def see_contents(self, player, current_width, current_height):
        print("Contents of the house: ")
        for monster in self.grid[current_width][current_height]:
            if type(monster) is Ghoul:
                monster.attack = randint(15,30)
                attributes = (monster.health, monster.attack)
                print("Ghoul         Health: %d      Attack: %d" %attributes)    
            elif type(monster) is Vampire:
                monster.attack = randint(10,20)
                attributes = (monster.health, monster.attack)
                print("Vampire       Health: %d     Attack: %d" %attributes)
            elif type(monster) is Werewolf:
                monster.attack = randint(0,40)
                attributes = (monster.health, monster.attack)
                print("Werewolf      Health: %d     Attack: %d" %attributes)
            elif type(monster) is Zombie:
                monster.attack = randint(0,10)
                attributes = (monster.health, monster.attack)
                print("Zombie        Health: %d      Attack: %d" %attributes)
            elif type(monster) is Person:
                attack_this_turn = -1
                attributes = (monster.health, attack_this_turn)
                print("Person        Health: %d     Attack: %d" %attributes)
            else:
                player.base_attack = randint(10,20)
                attributes = (player.hp, player.base_attack)
                print()
                print("Yourself      Health: %d    Attack: %d" %attributes)
                print()
        return self.grid[current_width][current_height]

    #shows the current weapons the user has available
    def see_weapons(self, player):
        print("Current weapons: ")
        i = 1
        for weapon in player.weapons:
            if i == 10:
                i = 0
            attributes = (i, weapon.attack, weapon.use_value)
            if weapon.weapon_name == "Sour Straws":
                print("%d) Sour Straw          Modifier:%d        Uses Left:%d" %attributes) 
            elif weapon.weapon_name == "Chocolate Bars":
                print("%d) Chocolate Bar       Modifier:%d        Uses Left:%d" %attributes)
            elif weapon.weapon_name == "Nerd Bombs":
                print("%d) Nerd Bomb           Modifier:%d        Uses Left:%d" %attributes) 
            elif weapon.weapon_name == "Hershey Kisses":
                print("%d) Hershey Kiss        Modifier:%d        Uses Left:%d" %attributes)
            i = i + 1
        return player.weapons
示例#12
0
 def init_board(self):
     self.neighborhood = Neighborhood(10, 10)
     self.grid = self.neighborhood.make_grid(self.neighborhood.height, self.neighborhood.width)
     self.grid = self.neighborhood.fill_neighborhood(self.grid)
示例#13
0
    plb.imshow(dapi)
    plb.show()
    #==============================================================================
    #     Segmentation
    #==============================================================================
    small = nd.zoom(dapi, 0.5)
    labelDAPI, n = nd.label(ex.LowResSegmentation(small))
    obj = ex.extractParticles(small, labelDAPI)
    ex.makeMosaic(obj, 20, 10000)
    print n
    #broken = pymorph.sedisk()
    pixel_distance = 1
    #se = np.array([[1,1,1],[1,1,1],[1,1,1]])
    se = np.uint(pymorph.sedisk(pixel_distance))  #2+1+2=5
    print se
    print 'find neighbours at ', pixel_distance, 'from particles'
    g = ng.findneighborhoods(labelDAPI, se)
    print 'converting to networkx'
    G = ng.convertToGraph(g, noBack=True)
    #==============================================================================
    #     Graphic display
    #==============================================================================
    plb.subplot(121, frameon=False, xticks=[], yticks=[])
    plb.imshow(small)
    plb.subplot(122, frameon=False, xticks=[], yticks=[])
    plb.imshow(labelDAPI)
    plb.show()
    #plb.subplot(133)
    nx.draw_networkx(G)
    plb.show()
示例#14
0
class Game(object):

	# Class constructor
	# Initializes variables
	def __init__(self):	
		
		# Neighborhood class instantiation
		self.hood = Neighborhood()
		# Get neighborhood grid, where house objects are located
		self.grid = self.hood.getGrid()
		# Instance of class player, which is the current player
		self.player1 = Player()
		# The variables turn and state are used to keep track of the player's 
		# current state
		self.turn = 0
		self.state = 0
	
	# This function will run the game
	def run(self):

		print("\nWelcome to your monster infested neighborhood\n")		

		self.state = 1
	
		# Run the game until game is finished
		# The game will finish when there is no monsters or 
		# the player dies 
		while(self.state != 0):

			# Print the neighborhood dimensions and the number of houses
			print("The size of the neighborhood is: %d x %d\n" % (self.hood.getHeight(), self.hood.getWidth()))
			print("There are %d houses in it.\n" % (self.hood.getHeight() * self.hood.getWidth()))

			# Prints the neighborhood map
			self.printMap();
			# Attemp to gather correct house coordinates from user
			try:
				print("Type the x coordinate of the house you would like to enter!\n")
				xHouse = int(raw_input())
				# Error catching
				# If the x coordinate if less than 0 or bigger than the grid size
				if (xHouse > self.hood.getHeight() or xHouse < 1):
					# Then raise value error
					raise ValueError
				print("Type the y coordinate of the house you would like to enter!\n")
				yHouse = int(raw_input())
				# Error catching
				# If the y coordinate if less than 0 or bigger than the grid size
				if (yHouse > self.hood.getWidth() or yHouse < 1):
					# Then raise value error
					raise ValueError
				# If coordinates are correct, proceed to house
				print("\nEntering house with coordinates %d x %d!\n" % (xHouse, yHouse))
				# Call enterHouse() function to enter the house, providing the house
				# coordinates within the grid as parameters
				self.enterHouse(xHouse, yHouse)		
	 		
			# Error handling
			# If coordinates are incorrect, do not attempt to enter house
			# Instead, print error message
			except ValueError:
				print "\nPlease enter correct coordinates\n"

	# Helper function
	# Prints the house coordinates to the screen
	def printMap(self):

		print("These are the coordinates of the houses in the neighborhood:\n")
		# Loop through the grid 2D array and print the coordinates of every house
		for x in range(self.hood.getHeight()):
			print("| "),
			for y in range(self.hood.getWidth()):
				# We add 1 to the coordinates, just so we don't start on 0
				# This makes it more undestandable for the user
				print("%d x %d  |" % ((x+1),(y+1))),
			print "\n"

	# Game Logic when player is inside the house
	def enterHouse(self, xHouse, yHouse):
		# Declaration of local variables
		inTheHouse = True
		houseEntered = self.grid[xHouse - 1][yHouse - 1]
		numMonsters = houseEntered.getNumMonsters()
	
		# Check number of NPCs in the house, which could be 0
		# If there is no monsters and no people in the house,
		# then exit the house
		if (len(houseEntered.getNpcs()) == 0):		
			print "This house is empty! Exiting!!"
			return
		# If there are NPCs, then proceed
		else:
			# Execute until players exits house
			while(inTheHouse):
				try:
					# Checks for total number of monsters in the neighborhood
					# If there is none, then the game is over and we exit the house
					# and the game. User wins
					if (self.hood.getMonsterCount() == 0):
						print("There are no more monsters!\n")
						print("You've won!\n")
						inTheHouse = False
						self.state = 0
						return
					NPCNum = 1
					print "You have found some creatures in the house!\n\nThis is a list of them:\n"
					# Print to the screen the list of NPC's in the house, assigning each an index
					# which starts from 1 (again, not 0 for user friendliness) and will be used by
					# player to select who to approach
					for x in houseEntered.getNpcs():
						print("%s (%d)" % (x.getName(), NPCNum))
						NPCNum += 1
					print "\n"
					print "Who would you like to approach? (Enter NPC index to approach or 0 to leave the house)\n"
					
					NPCIndex = int(raw_input())
					# The player will input 0 to exit house
					if (NPCIndex == 0):
						return
					# Check user input for possible errors
					# If the input is less than 0 or greater than the number
					# of NPCs in the house, an error will be raised
					elif (NPCIndex > NPCNum - 1 or NPCIndex < 1):
						raise ValueError
					
					print "\n"
					# If user input is correct, then approach NPC
					print("You decided to approach %s\n" % houseEntered.getNpcs()[NPCIndex - 1].getName())
					
					# If the NPC approached is a person, then player gains +1 health
					if (houseEntered.getNpcs()[NPCIndex - 1].getName() == "Person"):
						self.player1.setHealth(self.player1.getHealth() + 1)
						# Player is notified
						print("+1 health! Your health: %d\n" %self.player1.getHealth())
						
					# If NPC is not a person, then its monster
					# Therefore, player must fight
					else:
						print "Get ready to fight!\n"
						fighting = 1
						
						# Fighting logic of the game
						while (fighting == 1):
						
							# Checks for total number of monsters in the neighborhood
							# If there is none, then the game is over and we exit the house
							# and the game. User wins
							if (self.hood.getMonsterCount() == 0):
								print("There are no more monsters!\n")
								print("You've won!\n")
								fighting = 0
								inTheHouse = False
								self.state = 0
								return
							
							# Prints a list of all the weapons that the users has, 
							# and it shows how many uses each has left
							print "It's your turn to attack. These are your weapons:\n"
							WeaponNum = 1
							for x in self.player1.getInventory():
								print("%s. Uses left: %d (%d)" % (x.getName(), x.getUses() ,WeaponNum))
								WeaponNum += 1
							print "\n"
							# Same principle as the NPC approach
							print "What weapon would you like to use? Press 0 to get out of the house.\n"
							weaponIndex = int(raw_input())
							print ""
							# If player enter 0, then it will exit the house
							if(weaponIndex == 0):
								print("Getting out of this house.\n")
								return;
							# Checking user input for erros
							# If the user entered a number lower than 1 or greater than
							# the number of weapons available, the raise error
							elif(weaponIndex > WeaponNum - 1 or weaponIndex < 1):
								raise ValueError 
							# If weapons has no uses, then player can't attack and loses their turn
							elif(self.player1.getInventory()[weaponIndex-1].getUses() == 0):
								print "That weapon has no uses left! Sorry, you lost your opportunity to attack\n"
						
							# Fight against a Zombie
							if (houseEntered.getNpcs()[NPCIndex - 1].getName() == "Zombie" and self.player1.getInventory()[weaponIndex-1].getUses() > 0):
								# Notify player of it's opponent's health 
								print("You're attacking Zombie using %s!\n" % self.player1.getInventory()[weaponIndex-1].getName())
								print("Zombie has %d healthpoints\n" % houseEntered.getNpcs()[NPCIndex - 1].getHealth())
								damageDealt = 0
			
								# Calculate damage for attack with sour straw
								# Sour straws do extra damage to zombies
								if (self.player1.getInventory()[weaponIndex-1].getName() == "SourStraw"):

									print "It's really effective!\n"
									
									damageDealt = self.player1.getAttackValue()*self.player1.getInventory()[weaponIndex-1].getMod()*2

									houseEntered.getNpcs()[NPCIndex - 1].setHealth(houseEntered.getNpcs()[NPCIndex - 1].getHealth() - damageDealt)
									
									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)
								
								# Calculate damage for any other weapon
								else:
					
									damageDealt = self.player1.getAttackValue()*self.player1.getInventory()[weaponIndex-1].getMod()

									houseEntered.getNpcs()[NPCIndex - 1].setHealth(houseEntered.getNpcs()[NPCIndex - 1].getHealth() - damageDealt)
									
									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)
							
								# Notify player of the damage dealt to the zombie
								print("You dealt %d points of damage to Zombie!\n" %damageDealt)
								print("Your %s has now %d use(s)\n" % (self.player1.getInventory()[weaponIndex-1].getName(), self.player1.getInventory()[weaponIndex-1].getUses()))
							
								# If the zombie has less than 1 heath, it's dead. Notify player and observer (house in which is in)
								# This turns the Zombie into a person, and updates the total number of monsters in the neighborhood
								if(houseEntered.getNpcs()[NPCIndex - 1].getHealth() < 1):
									print("You defeated Zombie! It will turn into a person now!\n")
									houseEntered.killedMonster(NPCIndex - 1)
									break;
								# If zombie was not killed by attack, notify player of its health
								else:
									print("Zombie has %d healthpoints\n" % houseEntered.getNpcs()[NPCIndex - 1].getHealth())
							# Fight against a Vampire
							elif (houseEntered.getNpcs()[NPCIndex - 1].getName() == "Vampire" and self.player1.getInventory()[weaponIndex-1].getUses() > 0):
								# Notify player of it's opponent's health 
								print("You're attacking Vampire using %s!\n" % self.player1.getInventory()[weaponIndex-1].getName())
								print("Vampire has %d healthpoints\n" % houseEntered.getNpcs()[NPCIndex - 1].getHealth())
								damageDealt = 0
					
								# Calculate damage for attack with chocolate bar
								# Chocolate bars do extra damage to vampires
								if (self.player1.getInventory()[weaponIndex-1].getName() == "ChocolateBar"):

									print "Vampire is not harmed by ChocolateBar!\n"

									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)
								
								# Calculate damage for any other weapon
								else:
					
									damageDealt = self.player1.getAttackValue()*self.player1.getInventory()[weaponIndex-1].getMod()

									houseEntered.getNpcs()[NPCIndex - 1].setHealth(houseEntered.getNpcs()[NPCIndex - 1].getHealth() - damageDealt)
									
									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)
							
								# Notify player of the damage dealt to vampire
								print("You dealt %d points of damage to Vampire!\n" %damageDealt)
								print("Your %s has now %d use(s)\n" % (self.player1.getInventory()[weaponIndex-1].getName(), self.player1.getInventory()[weaponIndex-1].getUses()))
							
								# If the vampire has less than 1 heath, it's dead. Notify player and observer (house in which is in)
								# This turns the vampire into a person, and updates the total number of monsters in the neighborhood
								if(houseEntered.getNpcs()[NPCIndex - 1].getHealth() < 1):
									print("You defeated Vampire! It will turn into a person now!\n")
									houseEntered.killedMonster(NPCIndex - 1)
									break;
								# If vampire was not killed by attack, notify player of its health
								else:
									print("Vampire has %d healthpoints\n" % houseEntered.getNpcs()[NPCIndex - 1].getHealth())

							# Fight against a Ghoul
							elif (houseEntered.getNpcs()[NPCIndex - 1].getName() == "Ghoul" and self.player1.getInventory()[weaponIndex-1].getUses() > 0):
								print("You're attacking Ghoul using %s!\n" % self.player1.getInventory()[weaponIndex-1].getName())
								print("Ghoul has %d healthpoints\n" % houseEntered.getNpcs()[NPCIndex - 1].getHealth())
								damageDealt = 0

								if (self.player1.getInventory()[weaponIndex-1].getName() == "NerdBomb"):

									print "It's SUPER effective!\n"
									
									damageDealt = self.player1.getAttackValue()*self.player1.getInventory()[weaponIndex-1].getMod()*5

									houseEntered.getNpcs()[NPCIndex - 1].setHealth(houseEntered.getNpcs()[NPCIndex - 1].getHealth() - damageDealt)
									
									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)

								else:
					
									damageDealt = self.player1.getAttackValue()*self.player1.getInventory()[weaponIndex-1].getMod()

									houseEntered.getNpcs()[NPCIndex - 1].setHealth(houseEntered.getNpcs()[NPCIndex - 1].getHealth() - damageDealt)
									
									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)
							
								print("You dealt %d points of damage to Ghoul!\n" %damageDealt)
								print("Your %s has now %d use(s)\n" % (self.player1.getInventory()[weaponIndex-1].getName(), self.player1.getInventory()[weaponIndex-1].getUses()))
							
								if(houseEntered.getNpcs()[NPCIndex - 1].getHealth() < 1):
									print("You defeated Ghoul! It will turn into a person now!\n")
									houseEntered.killedMonster(NPCIndex - 1)
									break;
								else:
									print("Ghoul has %d healthpoints\n" % houseEntered.getNpcs()[NPCIndex - 1].getHealth())

							# Fight against a Werewolf
							elif (houseEntered.getNpcs()[NPCIndex - 1].getName() == "Werewolf" and self.player1.getInventory()[weaponIndex-1].getUses() > 0):
								print("You're attacking Werewolf using %s!\n" % self.player1.getInventory()[weaponIndex-1].getName())
								print("Werewolf has %d healthpoints\n" % houseEntered.getNpcs()[NPCIndex - 1].getHealth())
								damageDealt = 0

								if (self.player1.getInventory()[weaponIndex-1].getName() == "ChocolateBar"):

									print "Werewolf is not harmed by ChocolateBar!\n"

									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)

								elif (self.player1.getInventory()[weaponIndex-1].getName() == "SourStraw"):
								
									print "Werewolf is not harmed by SourStraw!\n"

									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)
	
								else:
					
									damageDealt = self.player1.getAttackValue()*self.player1.getInventory()[weaponIndex-1].getMod()

									houseEntered.getNpcs()[NPCIndex - 1].setHealth(houseEntered.getNpcs()[NPCIndex - 1].getHealth() - damageDealt)
									
									self.player1.getInventory()[weaponIndex-1].setUses(self.player1.getInventory()[weaponIndex-1].getUses() -1)
							
								print("You dealt %d points of damage to Werewolf!\n" %damageDealt)
								print("Your %s has now %d use(s)\n" % (self.player1.getInventory()[weaponIndex-1].getName(), self.player1.getInventory()[weaponIndex-1].getUses()))
							
								if(houseEntered.getNpcs()[NPCIndex - 1].getHealth() < 1):
									print("You defeated Werewolf! It will turn into a person now!\n")
									houseEntered.killedMonster(NPCIndex - 1)
									break;
								else:
									print("Werewolf has %d healthpoints\n" % houseEntered.getNpcs()[NPCIndex - 1].getHealth())

							# After the player attacks, it's attacked
							# Notify the player about the attack
							print("You're under attack by %s! Watch out!\n" %houseEntered.getNpcs()[NPCIndex - 1].getName())
							damageReceived = houseEntered.getNpcs()[NPCIndex - 1].getAttack()
							print("%s has dealt %d points of damage!\n" %(houseEntered.getNpcs()[NPCIndex - 1].getName(), damageReceived))
			
							# Set players health after attack
							self.player1.setHealth(self.player1.getHealth() - damageReceived)
							
							# If player's health is under 1, then he/she has been defeated and the game is over
							if(self.player1.getHealth() < 1):
								print("Oh oh. The candy forces have defeated you! You weren't able to save your neighborhood.\n")
								print("There still are %d monsters in the neighborhood.\n" %self.hood.getMonsterCount())
								fighting = 0
								inTheHouse = False
								self.state = 0
								
							# If the player wasn't kiled by the attack, then show his/her health
							else:
								print("You have %d health points now!\n" %self.player1.getHealth())
				
				
				# Error handling for all possible user input errors catched above
				except ValueError:
					print("Incorrect input\n")