def __init__(self, text=None, part2=False): # 1. Set the initial values self.part2 = part2 self.text = text self.lift = elevator.Elevator(part2=part2) self.floors = [] self.items = [] # 2. Process text (if any) if text is not None and len(text) > 0: # 3. Loop for all the text for line in self.text: # 4. Process elevator of floor if line.startswith("The elevator"): self.lift = elevator.Elevator(text=line, part2=self.part2) else: flr = floor.Floor(text=line, part2=self.part2) self.floors.append(flr) self.items.extend(flr.items) # 5. put the items in alphabetic order self.items.sort()
def test_many_floor(self): "Test the Floor object creation from text with many items" # 1. Create Solver object from text myobj = floor.Floor(text=MANY_TEXT) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 128) self.assertEqual(myobj.number, 2) self.assertEqual(myobj.ordinal, "second") self.assertEqual(len(myobj.items), 4) # 3. Check Methods self.assertEqual( str(myobj), "The second floor contains a plutonium generator," " a strontium generator, a thulium generator," " and a thulium-compatible microchip.") self.assertEqual(myobj.has(HYG), False) self.assertEqual(myobj.has(HYM), False) self.assertEqual(myobj.elements(), set(["plutonium", "strontium", "thulium"])) self.assertEqual(len(myobj.generators()), 3) self.assertEqual(len(myobj.microchips()), 1) self.assertEqual(myobj.has_pair(THM), True) self.assertEqual(myobj.has_pair(HYG), False) self.assertEqual(myobj.is_safe(), True) self.assertEqual(len(myobj.element_items("plutonium")), 1) self.assertEqual(len(myobj.element_items("thulium")), 2) self.assertEqual(len(myobj.element_items("kryptonium")), 0)
def test_text_init(self): "Test the Floor object creation from text" # 1. Create Solver object from text myobj = floor.Floor(text=EXAMPLE_TEXT) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 92) self.assertEqual(myobj.number, 1) self.assertEqual(myobj.ordinal, "first") self.assertEqual(len(myobj.items), 2) # 3. Check Methods self.assertEqual(str(myobj), EXAMPLE_TEXT) self.assertEqual(myobj.has(HYG), False) self.assertEqual(myobj.has(HYM), True) self.assertEqual(myobj.elements(), set(["hydrogen", "lithium"])) self.assertEqual(len(myobj.generators()), 0) self.assertEqual(len(myobj.microchips()), 2) self.assertEqual(myobj.trace(None, TRACE), "F1 . ... HyM ... LiM") self.assertEqual(myobj.is_safe(), True) self.assertEqual(myobj.is_empty(), False) self.assertEqual(myobj.has_pair(HYG), True) other = myobj.clone() self.assertEqual(myobj, other) myobj.remove(HYM) self.assertEqual(myobj.has_pair(HYG), False) self.assertEqual(myobj.trace(None, TRACE), "F1 . ... ... ... LiM") self.assertEqual(myobj.is_safe(), True) self.assertEqual(myobj.is_empty(), False) self.assertNotEqual(myobj, other) myobj.add(LIG) self.assertEqual(myobj.trace(None, TRACE), "F1 . ... ... LiG LiM") self.assertEqual(myobj.is_safe(), True) self.assertEqual(myobj.is_empty(), False) self.assertTrue(myobj.is_safe_with([HYG])) self.assertFalse(myobj.is_safe_with([HYM])) self.assertTrue(myobj.is_safe_with([HYM, HYG])) self.assertTrue(myobj.is_safe_without([LIG])) self.assertTrue(myobj.is_safe_without([LIM])) self.assertTrue(myobj.is_safe_without([LIG, LIM]))
def test_empty_floor(self): "Test the Floor object creation from text with no items" # 1. Create Solver object from text myobj = floor.Floor(text=EMPTY_TEXT) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 43) self.assertEqual(myobj.number, 4) self.assertEqual(myobj.ordinal, "fourth") self.assertEqual(len(myobj.items), 0) # 3. Check Methods self.assertEqual(str(myobj), EMPTY_TEXT) self.assertEqual(myobj.has(HYG), False) self.assertEqual(myobj.has(HYM), False) self.assertEqual(myobj.elements(), set()) self.assertEqual(len(myobj.generators()), 0) self.assertEqual(len(myobj.microchips()), 0) self.assertEqual(myobj.safely_removable(), []) lift = elevator.Elevator() lift.floor = 4 self.assertEqual(myobj.trace(lift, TRACE), "F4 E ... ... ... ...") self.assertEqual(myobj.is_safe(), True) self.assertEqual(myobj.is_empty(), True) myobj.add(HYG) self.assertEqual(myobj.trace(lift, TRACE), "F4 E HyG ... ... ...") self.assertEqual(myobj.is_safe(), True) self.assertEqual(myobj.is_empty(), False) items = myobj.safely_removable() self.assertEqual(len(items), 1) self.assertEqual(len(items[0]), 1) self.assertEqual(items[0][0], HYG) myobj.add(LIM) self.assertEqual(myobj.is_safe(), False) self.assertEqual(myobj.is_empty(), False) lift.load([LIG]) lift.move_down() self.assertEqual(myobj.trace(lift, TRACE), "F4 v HyG ... ... LiM") self.assertEqual(myobj.is_safe(), False) self.assertEqual(len(myobj.safely_removable()), 2)
def _init_terrain(self): floor_width = 19 floor_height = 19 x_room = 1 y_room = 1 w_room = 5 h_room = 5 for x in range(0, floor_width): for y in range(0, floor_height): position = map_position.MapPosition(x, y) new_terrain = wall.Wall(self.level.terrain_map, position) for x in range(0, floor_width): for y in range(0, floor_height): position = map_position.MapPosition(x, y) if x >= x_room and x < x_room + w_room and y >= y_room and y < y_room + h_room: new_terrain = floor.Floor(self.level.terrain_map, position) position = self._drop_stairs() new_terrain = stairs_down.StairsDown(self.level.terrain_map, position)
def update(self): # Check if chars created if self.party_menu: self.party_menu.update() if self.party_menu.finished: self.party = self.party_menu.party self.party_menu = None self.floor = floor.Floor(20, 20, self.party) self.floor.generate_rooms() elif self.floor: self.floor.update() if self.floor.game_over: self.floor = None self.event = Event2.Event(self.background_image, self.gametext['lose'], ['The End?'], [self.toMenu]) elif self.floor.win: self.floor = None self.event = Event2.Event(self.background_image, self.gametext['win'], ['To be continued...'], [self.toMenu])
def test_empty_init(self): "Test the default Floor creation" # 1. Create default Floor object myobj = floor.Floor() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.number, 0) self.assertEqual(myobj.ordinal, "UNKNOWN") self.assertEqual(len(myobj.items), 0) # 3. Check Methods self.assertEqual(str(myobj), "The UNKNOWN floor contains nothing relevant.") self.assertEqual(myobj.has(HYG), False) self.assertEqual(myobj.has(HYM), False) self.assertEqual(myobj.elements(), set()) self.assertEqual(len(myobj.generators()), 0) self.assertEqual(len(myobj.microchips()), 0) self.assertEqual(myobj.trace(None, TRACE), "F0 . ... ... ... ...") self.assertEqual(myobj.is_safe(), True) self.assertEqual(myobj.is_empty(), True)
from pygame import * import os from dino import * import time import floor import cactus import pter import random pygame.init() screen = display.set_mode( (1080, 720) ) obj_group = sprite.Group() objects = [] di = dino(100, 60, '', 200, 600, 10 ) objects.append( di ) fl = floor.Floor() enemies = [] print(fl.rect.x) obj_group.add( di ) obj_group.add( fl ) background = image.load('textures/background.png') f = font.SysFont('Arial', 60) end_text = f.render('Game over', True, (255,0, 0) ) score_f = font.SysFont('Arial', 32) v_text = f.render('Вы победили!', True, (255,0, 0) ) score = 0 scorepoint = 1000 stone_speed = 15 pter_speed = 20 op = 0
def continue_game(self, junk=None): if self.party and self.floor_data: self.party_menu = None self.floor = floor.Floor(20, 20, self.party) self.floor.generate_rooms(self.floor_data)
def calculate_floors_position(self): logging.debug( 'START Class FloorStructure, method calculate_floors_position') points_base_node = [ list(p.position()) for p in self.get_base_node().geometry().points() ] lowest_point = list( self.get_base_node().geometry().boundingBox().minvec()) # Now we stract the points of the floor from the building structure_of_floor = [] for point in points_base_node: # If the point has the same y position than the lowest point, the # point will be a floor point # We cant do that beacuse the points returned from geometry of houdini # node are ordered, and the points can be the structure of the floor # just as it is if (point[1] == lowest_point[1]): # Mapping to y=0 structure_of_floor.append(list(point)) logging.debug("Structure of floor " + str(structure_of_floor)) #====================================================================== # Now we want to found the lowest virtual plant with a crack primitive # touching it. Also we want the previous of this floor, because this # floor will be visible trough the hole of the next floor #====================================================================== # Initialize position of the first virtual floor in the center point of the base virtual_floor = floor.Floor(self.get_floor_params(), structure_of_floor) previous_virtual_floor = virtual_floor connected_prims_with_crack = virtual_floor.intersections_with_crack( self.get_crack().patternCrack, self.get_path()) floor_inside = virtual_floor.inside(self.get_base_node()) # MAYFIX: structure points are the same for each floor, we assume that # the building have the same boundary for each floor increment = GeoMath.vecScalarProduct( [0, 1, 0], self.extract_parm_from_user_restrictions( 'floor_default_put_each_y')) logging.debug("Increment " + str(increment)) acumulated_increment = [0, 0, 0] while (not connected_prims_with_crack and floor_inside): logging.debug("Acumulated increment " + str(acumulated_increment)) acumulated_increment = GeoMath.vecPlus(acumulated_increment, increment) new_structure_of_floor = [ GeoMath.vecPlus(position, acumulated_increment) for position in structure_of_floor ] previous_virtual_floor = virtual_floor virtual_floor = floor.Floor(self.get_floor_params(), new_structure_of_floor) connected_prims_with_crack = ( virtual_floor.intersections_with_crack( self.get_crack().patternCrack, self.get_path())) floor_inside = virtual_floor.inside(self.get_base_node()) # If not inside, delete it if (not floor_inside): logging.debug("Floor_outside") virtual_floor = None #======================================================================= # #======================================================================= # # once we found the first virtual floor, we check if is it the same # # than the previous virtual floor. If it is the same will assign the # # next virtual floor possible. Then we check if this floor is outside # # the building. If the virtual floor reside outside building we delete it # # and not continue working with floors # #======================================================================= # if(previous_virtual_floor == virtual_floor): # #Check if it is inside building # floor_inside = virtual_floor.inside(points_base_node) # #If not inside, delete it # if(not floor_inside): # virtual_floor = None #======================================================================= # The first floor is untouched destroyed_virtual_floors = [previous_virtual_floor] #======================================================================= # Now we have to create the other floors until we reached the first floor # outside building or not connected with crack prims #======================================================================= if (virtual_floor): connected_prims_with_crack = True floor_inside_building = True while (connected_prims_with_crack and floor_inside_building): destroyed_virtual_floors.append(virtual_floor) logging.debug("Acumulated increment " + str(acumulated_increment)) acumulated_increment = GeoMath.vecPlus(acumulated_increment, increment) new_structure_of_floor = [ GeoMath.vecPlus(position, acumulated_increment) for position in structure_of_floor ] previous_virtual_floor = virtual_floor virtual_floor = floor.Floor(self.get_floor_params(), new_structure_of_floor) connected_prims_with_crack = ( virtual_floor.intersections_with_crack( self.get_crack().patternCrack, self.get_path())) floor_inside = virtual_floor.inside(self.get_base_node()) # Now add the last floor if needed if (virtual_floor.inside(self.get_base_node())): destroyed_virtual_floors.append(virtual_floor) else: # Only one floor destroyed_virtual_floors.append(previous_virtual_floor) # Display floors in houdini as a cubes #createfloors.CreateFloors(destroyed_virtual_floors, self.get_geo()) self.floors = destroyed_virtual_floors logging.debug( 'END Class FloorStructure, method calculate_floors_position')