def layout_level3(screen): p3_width = 50 p_height = 50 p_width = 100 platforms = [] ar_x = 1.3 ar_y = 1.5 platforms.append(Block(50, 490, p_width, p_height, "block1.png")) platforms.append(Block(150, 490, p_width, p_height, "block1.png")) platforms.append(Block(250, 490, p_width, p_height, "block1.png")) platforms.append(Block(350, 490, p_width, p_height, "block1.png")) platforms.append(Block(450, 490, p_width, p_height, "block1.png")) platforms.append(Block(550, 490, p_width, p_height, "block1.png")) platforms.append(Block(650, 490, p_width, p_height, "block1.png")) platforms.append(Block(750, 490, p_width, p_height, "block1.png")) lampHeight = lampImage.get_height() lampList = [ Lamp((250, 490), lampImage, lightAlpha, 1), Lamp((650, 490), lampImage, lightAlpha, 5) ] doorList = [Door((50, 490), False), Door((750, 490), True)] return platforms, lampList, doorList
def restartFromDoorOne(self): self.__currentDoor = Door("Porte1") self.__thisPathHistory = [] self.__passwordHistory = [] self.__optionAneedToBePressed = False print("\nVous etes maintenant devant la porte 1 du labyrinthe.\n") return
def layout_level4(screen): p3_width = 50 p_height = 50 p_width = 100 p4_height = 105 p4_width = 15 platforms = [] platforms.append(Block(150, 70, p_width, p_height, "block1.png")) platforms.append(Block(550, 70, p_width, p_height, "block1.png")) platforms.append(Block(650, 175, p_width, p_height, "block1.png")) platforms.append(Block(250, 280, p_width, p_height, "block1.png")) platforms.append(Block(650, 280, p_width, p_height, "block1.png")) platforms.append(Block(50, 385, p_width, p_height, "block1.png")) platforms.append(Block(650, 385, p_width, p_height, "block1.png")) platforms.append(Block(50, 490, p_width, p_height, "block1.png")) platforms.append(Block(150, 490, p_width, p_height, "block1.png")) platforms.append(Block(450, 490, p_width, p_height, "block1.png")) platforms.append(Block(750, 490, p_width, p_height, "block1.png")) platforms.append(Block(250, 70, p_width, p_height, "block2.png")) platforms.append(Block(50, 175, p_width, p_height, "block2.png")) platforms.append(Block(250, 175, p_width, p_height, "block2.png")) platforms.append(Block(450, 175, p_width, p_height, "block2.png")) platforms.append(Block(550, 175, p_width, p_height, "block2.png")) platforms.append(Block(150, 280, p_width, p_height, "block2.png")) platforms.append(Block(550, 280, p_width, p_height, "block2.png")) platforms.append(Block(250, 385, p_width, p_height, "block2.png")) platforms.append(Block(650, 490, p_width, p_height, "block2.png")) platforms.append(Block(775, 70, p3_width, p_height, "block3.png")) platforms.append(Block(325, 385, p3_width, p_height, "block3.png")) platforms.append(Block(225, 490, p3_width, p_height, "block3.png")) #Floor platforms.append(Block(50, 590, p_width, p_height, "block1.png")) platforms.append(Block(150, 590, p_width, p_height, "block1.png")) platforms.append(Block(250, 590, p_width, p_height, "block1.png")) platforms.append(Block(350, 590, p_width, p_height, "block1.png")) platforms.append(Block(450, 590, p_width, p_height, "block1.png")) platforms.append(Block(550, 590, p_width, p_height, "block1.png")) platforms.append(Block(650, 590, p_width, p_height, "block1.png")) platforms.append(Block(750, 590, p_width, p_height, "block1.png")) lampHeight = lampImage.get_height() lampList = [ Lamp((150, 490), lampImage, lightAlpha, isLit=True), Lamp((250, 70), lampImage, lightAlpha, 10), Lamp((650, 385), lampImage, lightAlpha, 5) ] doorList = [Door((750, 490), False), Door((50, 490), True)] return platforms, lampList, doorList, None
def parameterize(occluder, outputPath, faceNumber, faceAngle, occlusionLevel): if occluder == 'Bars': Bars.barsScale(outputPath, faceNumber, faceAngle, occlusionLevel, 'None', 0, 1) if occluder == 'Door': Door.doorParameterization(outputPath, faceNumber, faceAngle, occlusionLevel, 'None', 0, 1) if occluder == 'Curtain': Curtain.curtainParameterization(outputPath, faceNumber, faceAngle, occlusionLevel, 'None', 0, 1) if occluder == 'Blinds': Blinds.blindsParameterization(outputPath, faceNumber, faceAngle, occlusionLevel, 'None', 0, 1) if occluder == 'Fence': Fence.fenceParameterization(outputPath, faceNumber, faceAngle, occlusionLevel, 'None', 0, 1)
def tcplink(sock, addr): print('Accept new connection from %s:%s...' % addr) while True: data = sock.recv(1024) time.sleep(0.1) echo = data.decode('utf-8') netcmd = echo.split(' ') if echo == '': break if not echo == 'keepAlive': print('<---' + addr.__str__() + '>' + echo) # 发送别忘了\n if netcmd[0] == 'keepAlive': sock.send('keepAlive\n'.encode('utf-8')) # print('--->' + addr.__str__() + '>' + 'keepAlive') elif netcmd[0] == 'verify': if Security.verify(netcmd[1]): sock.send('verify keycorrect\n'.encode('utf-8')) print('--->' + addr.__str__() + '>' + 'verify keycorrect') else: sock.send('verify keywrong\n'.encode('utf-8')) print('--->' + addr.__str__() + '>' + 'verify keywrong') elif netcmd[0] == 'isSmartLock': sock.send('SmartLock\n'.encode('utf-8')) print('--->' + addr.__str__() + '>' + 'SmartLock') elif netcmd[0] == 'setkey': if Security.isverify(): sock.send(Security.setkey(echo.split(' ')[1]).encode('utf-8')) elif netcmd[0] == 'state': if Security.isverify(): pass elif netcmd[0] == 'door_switch': if Security.isverify(): Door.door_switch(SmartHome.pinList['door']) sock.send(('door_switch ' + Door.lockstate + '\n').encode('utf-8')) print('--->' + addr.__str__() + '>' + 'door_switch ' + Door.lockstate) elif netcmd[0] == 'whiteLight_switch': if Security.isverify(): Furniture.whiteLight_switch(SmartHome.pinList['whiteLight']) sock.send(('whiteLight_switch ' + Furniture.whiteLightState + '\n').encode('utf-8')) print('--->' + addr.__str__() + '>' + 'whiteLight_switch ' + Furniture.whiteLightState) elif netcmd[0] == 'test': if Security.isverify(): pass elif echo == 'exit': break sock.close() print('Connection from %s:%s closed.' % addr)
def openCurrentDoor(self): if self.__optionAneedToBePressed == False: nextDoor = self.__currentDoor.ouvrirPorte( self.__thisPathHistory, self.__completeEventsHistory, self.__passwordHistory) self.__currentDoor = Door(nextDoor) if nextDoor == "PorteGouffre": self.__optionAneedToBePressed = True else: self.__optionAneedToBePressed = False else: print( "\nTant que l’option (a) n’a pas été choisie, l’option (b) ne peut pas être choisie.\n" )
def generate_doors(self): door_loc = {'direction': 'none', 'x': 0, 'y': 0} for room in self.neighboring_rooms: if not self.is_connected(room): if room.rect.x >= self.rect.x + self.rect.width: #right door_loc = Door.Door('vertical', room.rect.x/Room.grid_size, \ random.randint(max(room.rect.y, self.rect.y)/Room.grid_size, \ min(room.rect.y+room.rect.height, self.rect.y+self.rect.height)/Room.grid_size-1)) door_loc.rooms = [self, room] self.set_connected_door(room, door_loc) elif room.rect.y >= self.rect.y + self.rect.height: #top door_loc = Door.Door('horizontal', random.randint(max(room.rect.x, self.rect.x)/Room.grid_size, \ min(room.rect.x+room.rect.width, self.rect.x+self.rect.width)/Room.grid_size-1), \ (self.rect.y + self.rect.height)/Room.grid_size) door_loc.rooms = [self, room] self.set_connected_door(room, door_loc)
def addDoor(self, xy, variant, isOpen): x, y = xy side = [[6, 7], [13, 3], [6, -1], [-1, 3]].index([x, y]) self.doors.append( Door(self.floor, side, variant, isOpen, self.textures["doors"], self.sounds))
def __init__(self): SceneBase.__init__(self) playerimage = pygame.transform.scale(pygame.image.load("Images/player.png"), (30, 30)) # creates the Player character in the location 20, 20 self.player = Player.Player(30, 30, playerimage) blueParticle = pygame.image.load("Images/particle_blue.png") redParticle = pygame.image.load("Images/particle_red.png") # Defines the starting positions of the first two Particles for level 1 of the game self.particle1 = Particle.Particle(100, 100, False, None, redParticle, False) self.particle2 = Particle.Particle(100, 200, True, self.particle1, blueParticle, False) # Particle 2 is entangled to Particle one # Defines the position for the first goal for level 1 of the game self.goal = Goal.Goal(400, 400) # NOTE: Negative numbers in wall declarations ruin collision detection self.leftWall = Wall.Wall(0, 0, 20, 600) self.rightWall = Wall.Wall(780, 0, 20, 600) self.topWall = Wall.Wall(0, 0, 800, 20) self.bottomWall = Wall.Wall(0, 580, 800, 20) self.door = Door.Door(760, 300, 20, 100) self.walls=[self.leftWall,self.rightWall,self.bottomWall,self.topWall] # Defines the objects that the Player character cannot pass through self.entities = [self.player,self.particle1, self.particle2, self.leftWall, self.rightWall, self.topWall, self.bottomWall] self.particles=[self.particle1,self.particle2] self.startTime=int(round(time.time())) pygame.mixer.music.load('A Strange Charm.wav') pygame.mixer.music.play(-1)
def add_door(self, x, y, width, height, id): door = Door(x, y, width, height) self.doors.append(door) self.activatables.append(door) for ac in self.activators: if ac.id == id: ac.add_activatable(door)
def display(): twDisplayInit() myCamera() # set my own camera glShadeModel(GL_SMOOTH) glEnable(GL_LIGHTING) ## set a light from upper light lightPos0 = (-10,70,-10,0) twGrayLight(GL_LIGHT0,lightPos0,0.3,0.6,0.6) ## set karaoke's two flashlights which share the same position lightPos1 = (40,50,-35,1) twGraySpotlight(GL_LIGHT1,lightPos1,0.7,1,0.9, lightDirection0[directionId], 15, 5) twGraySpotlight(GL_LIGHT2,lightPos1,1,1,0.8, lightDirection1[directionId], 12, 5) if not Light1: glDisable(GL_LIGHT1) if not Light2: # if Light1 and Light2 are false, turn off the light glDisable(GL_LIGHT2) ## draw the ceiling and the floor floor = (0.18,0.31,0.31) #dark slate gray ceiling = (0.94,0.97,1) #alice blue quad(floor,(-10,0,-70),0,(1,0,0),100,80) #floor quad(ceiling,(0,50,-60),0,(1,0,0),80,50) #ceiling ## draw the walls. The front wall has the karaoke sign. ## Use wall texture walls() ## draw the door Door.draw(openDegree,textureIDs) ## place the furnitures furnitures() glFlush() glutSwapBuffers() if SaveFrames: saveFrame()
def connect(): global door doorPath = "" for f in os.listdir("/dev"): if "ttyACM" in f: doorPath = "/dev/" + f door = Door(doorPath)
def test_get_neigghbors(self): b = Cell(Coord(8, 14)) door = DoorModule.Door(self.a, EAST, b) self.a.add_door(EAST, door) b.add_door(WEST, door) neighbors = self.a.get_neighbors() self.assertEqual(neighbors, [b]) neighbors = b.get_neighbors() self.assertEqual(neighbors, [self.a])
def test_one_get_doors(self): b = Cell(Coord(8, 14)) door = DoorModule.Door(self.a, EAST, b) self.a.add_door(EAST, door) b.add_door(WEST, door) doors = self.a.get_doors() self.assertEqual(doors, [door]) doors = b.get_doors() self.assertEqual(doors, [door])
class MazeGame: def __init__(self): self.__name = "Labyrinthe" self.__isStarted = False self.__optionAneedToBePressed = True self.__currentDoor = "" self.__passwordHistory = "" self.__thisPathHistory = [] self.__completeEventsHistory = [] # Restarts the player position to door 1 and resets all data structures # except for the completeEventsHistory used before calling this method. def restartFromDoorOne(self): self.__currentDoor = Door("Porte1") self.__thisPathHistory = [] self.__passwordHistory = [] self.__optionAneedToBePressed = False print("\nVous etes maintenant devant la porte 1 du labyrinthe.\n") return # Reads a text file representing a door or the boss, creates the # automata accordingly and displays the information about the current event. # This method cannot be called before restartFromDoorOne. def openCurrentDoor(self): if self.__optionAneedToBePressed == False: nextDoor = self.__currentDoor.ouvrirPorte( self.__thisPathHistory, self.__completeEventsHistory, self.__passwordHistory) self.__currentDoor = Door(nextDoor) if nextDoor == "PorteGouffre": self.__optionAneedToBePressed = True else: self.__optionAneedToBePressed = False else: print( "\nTant que l’option (a) n’a pas été choisie, l’option (b) ne peut pas être choisie.\n" ) # Displays a recap of all the events that occured before calling # this method def afficherLeCheminParcouru(self): print("".join(self.__completeEventsHistory)) return def getName(self): return self.__name def start(self): self.__isStarted = True def end(self): self.__isStarted = False def isStarted(self): return self.__isStarted
def genEnvironment(difficulty, direction): objects = [] door = [] choices = [] if direction == "Up": door.append(Door(False, "Down", 0)) choices = ["Up", "Left", "Right"] elif direction == "Down": door.append(Door(False, "Up", 0)) choices = ["Down", "Left", "Right"] elif direction == "Left": door.append(Door(False, "Right", 0)) choices = ["Up", "Left", "Down"] elif direction == "Right": door.append(Door(False, "Left", 0)) choices = ["Up", "Down", "Right"] for x in range(0, 3): randDoorChance = random.randint(0, 99) isDoor = False if randDoorChance < 35: isDoor = True if isDoor == True: randDoor = random.randint(0, len(choices) - 1) lockedChance = random.randint(0, 100 / difficulty) lockedState = False if lockedChance <= 10: lockedState = True door.append( Door(lockedState, choices[randDoor], random.randint(0, NUMBER_OF_DOORS - 1))) choices.pop(randDoor) numObjects = random.randint(0, 2) for i in range(0, numObjects): objType = random.randint(0, 2) objects.append(genObject(objType, difficulty)) #Generate random room description Descriptions = Library.getDescriptionsList() Choice = random.randint(0, len(Descriptions) - 1) desc = "a " + Descriptions[Choice] + " room" retEnv = Environment(objects, desc, door) return retEnv
def create_doors(level, positions): door_pos = positions for x in range(level): a = Door.Door() a.set_image(door_image) a.get_pos(level) pos_list = [a.x_pos, a.y_pos] while pos_list in door_pos: a.get_pos(level) pos_list = [a.x_pos, a.y_pos] door_list.append(a) door_pos.append([a.x_pos, a.y_pos]) all_doors.append([a.x_pos, a.y_pos])
def __init__(self, player, clock): SceneBase.__init__(self) # creates the Player character in the location 20, 20 self.player = player player.x = 30 player.y = 30 # Defines the starting positions of the first two Particles for level 3 of the game self.particle1 = Particle.Particle(90, 360, False, None, greenParticle, False) self.particle2 = Particle.Particle( 90, 80, True, self.particle1, greenParticle, False) # Particle 2 is entangled to Particle one # Defines the position for the first goal for level 3 of the game self.goal = Goal.Goal(720, 530) self.door = Door.Door(760, 100, 20, 100) # NOTE: Negative numbers in wall declarations ruin collision detection self.leftWall = Wall.Wall(0, 0, 20, 600) self.rightWall = Wall.Wall(780, 0, 20, 600) self.topWall = Wall.Wall(0, 0, 800, 20) self.bottomWall = Wall.Wall(0, 580, 800, 20) self.centerWallObstacle = Wall.Wall(20, 290, 780, 30) self.lowerWallObstacle = Wall.Wall(20, 390, 280, 20) self.middleWallObstacle = Wall.Wall(380, 300, 20, 180) self.rightWallObstacleOne = Wall.Wall(500, 450, 20, 130) self.rightWallObstacleTwo = Wall.Wall(580, 360, 200, 20) self.walls = [ self.leftWall, self.rightWall, self.bottomWall, self.topWall, self.centerWallObstacle, self.lowerWallObstacle, self.middleWallObstacle, self.rightWallObstacleOne, self.rightWallObstacleTwo ] # Defines the objects that the Player character cannot pass through self.entities = [ self.player, self.particle1, self.particle2, self.leftWall, self.rightWall, self.topWall, self.bottomWall, self.centerWallObstacle, self.lowerWallObstacle, self.middleWallObstacle, self.rightWallObstacleOne, self.rightWallObstacleTwo ] self.particles = [self.particle1, self.particle2] self.startTime = clock
def putDoors(): global doors global lg global enemies doors = [] if (not len(enemies) == 0): if (lg.map[lg.tela[0] - 1][lg.tela[1]] != 0): doors.append( Door(int(size * 3 / 8), 0, int(size / 8), int(size / 80), "left")) doors.append( Door(int(size * 4 / 8), 0, int(size / 8), int(size / 80), "right")) if ((lg.map[lg.tela[0] + 1][lg.tela[1] + 1] != 0)): doors.append( Door(int(size * 3 / 8), int(size - size / 80), int(size / 8), int(size / 80), "left")) doors.append( Door(int(size * 4 / 8), int(size - size / 80), int(size / 8), int(size / 80), "right")) if ((lg.map[lg.tela[0]][lg.tela[1] - 1] != 0)): doors.append( Door(0, int(size * 3 / 8), int(size / 80), int(size / 8), "up")) doors.append( Door(0, int(size * 4 / 8), int(size / 80), int(size / 8), "down")) if ((lg.map[lg.tela[0]][lg.tela[1] + 1] != 0)): doors.append( Door(int(size - size / 80), int(size * 3 / 8), int(size / 80), int(size / 8), "up")) doors.append( Door(int(size - size / 80), int(size * 4 / 8), int(size / 80), int(size / 8), "down"))
def doortest1(): Door.door_test1(input('pin'), input('level'), input('freq'))
import Door import Gold import time #initialization pygame.init() name = input("Hello. What is your name? ") screen_w = 750 screen_h = 750 size = [screen_w, screen_h] screen = pygame.display.set_mode(size) h = Hero.Hero(name) d = Door.Door() s = Spike.Spike() g = Gold.Gold() door_image = pygame.image.load("door.png") door_rect = door_image.get_rect() d.set_image(door_image) spike_image = pygame.image.load("spike.png") spike_rect = spike_image.get_rect() s.set_image(spike_image) gold_image = pygame.image.load("gold.png") gold_rect = gold_image.get_rect() g.set_image(gold_image)
def __init__(self): pygame.init() #start up pygame self.window = pygame.display.set_mode( (640, 790)) #set window size to 512, 512 pygame.display.set_caption("Search") #title window pygame.key.set_repeat(1, 80) import objects self.all_sprites = pygame.sprite.Group() self.all_tiles = pygame.sprite.Group() self.active_tiles = pygame.sprite.Group() self.inventoryWindow = pygame.sprite.Group( ) #create a sprite group for the inventory window self.doors = pygame.sprite.Group() self.active_doors = pygame.sprite.Group( ) #make sprite group for this room's doors that Horace can walk through self.inactive_doors = pygame.sprite.Group( ) #make sprite group for this room's doors that are closed so that they will change appearance but still be drawn (removing them #from self.active_doors won't actually cause them to disappear) self.status_bar = pygame.sprite.Group() self.entities = pygame.sprite.Group() self.props = pygame.sprite.Group() self.active_props = pygame.sprite.Group() self.active_message_boxes = pygame.sprite.Group( ) #sprite group to hold active message boxes self.active_option_boxes = pygame.sprite.Group() self.active_enemies = pygame.sprite.Group() self.title_screen = pygame.sprite.Group() self.minimap_group = pygame.sprite.Group() self.active_ground_items = pygame.sprite.Group() self.message_box_active = False #check if there are active message boxes self.active_battle = pygame.sprite.Group() self.active_enemy_status_bar = pygame.sprite.Group() #for prop in objects.cave_plants: # self.props.add(prop) self.clock = pygame.time.Clock() apple = item( self, 91, 91, "img/items/misc/apple_2.png", 'Apple', 2, 'Here is an unnecessarily long description of an apple. It is entirely to test the function of the textWrapper class', True, 'common', 1) apple2 = item(self, 64, 64, "img/items/misc/apple_2.png", 'Apple', 2, 'Another apple', True, 'common', 1) apple3 = item(self, 64, 64, "img/items/misc/apple_2.png", 'Apple', 2, 'A third apple', True, 'common', 1) broken_gauntlets_statreq = {"STR": 1, "DEX": 0, "AGL": 0, "INT": 0} broken_cuirass_statreq = {"STR": 2, "DEX": 0, "AGL": 0, "INT": 0} broken_gauntlets_elembonus = { "LIGHT": 12, "DARK": 0, "FIRE": 0, "ICE": 0 } broken_cuirass_elembonus = {"LIGHT": 2, "DARK": 3, "FIRE": 0, "ICE": 0} broken_greaves_statreq = {"STR": 0, "DEX": 0, "AGL": 0, "INT": 0} broken_greaves_elembonus = {"LIGHT": 0, "DARK": 0, "FIRE": 0, "ICE": 0} cracked_helmet_elembonus = { "LIGHT": 12, "DARK": 0, "FIRE": 0, "ICE": 0 } cracked_helmet_statreq = {"STR": 0, "DEX": 0, "AGL": 0, "INT": 0} self.broken_gauntlets = Armor(self, "Broken gauntlets", 64, 64, 2, "Plate", broken_gauntlets_elembonus, broken_gauntlets_statreq, "arms", "broken", "gauntlets", 10, "A pair of broken gauntlets") self.broken_cuirass = Armor(self, "Broken cuirass", 64, 64, 3, "Plate", broken_cuirass_elembonus, broken_cuirass_statreq, "torso", "broken", "cuirass", 6, "A broken cuirass.") self.broken_greaves = Armor(self, "Broken greaves", 64, 64, 2, "Plate", broken_greaves_elembonus, broken_greaves_statreq, "legs", "broken", "greaves", 8, "A pair of broken greaves.") self.cracked_helmet = Armor(self, "Cracked helmet", 64, 64, 3, "Plate", cracked_helmet_elembonus, cracked_helmet_statreq, "head", "broken", "helmet", 8, "A cracked helmet.") broken_sword_statreq = {"STR": 2, "DEX": 0, "AGL": 0, "INT": 0} broken_sword_elembonus = {"LIGHT": 5} self.broken_sword = Weapon( self, "Broken sword", 64, 64, "Straight sword", "right", "medium", "piercing", 8, 8, broken_sword_elembonus, broken_sword_statreq, None, None, "broken_sword", 15, "Horace's guardsman's sword. Mostly ornamental, its blade is now broken in two by falling rubble." ) inventory = [ apple, apple2, apple3, self.broken_gauntlets, self.broken_cuirass, self.broken_greaves, self.cracked_helmet, self.broken_sword ] #create very basic inventory array self.player = Player(self, 64, 64, inventory, 50, 50, 20, 20, 3, 5, 5, 3, 5, None, None, None, None, None, None) goblin_targetable_areas = [ "Target: head", "Target: arms", "Target: legs", "Target: torso" ] self.goblin = Enemy(self, self.player, 384, 384, 2, "Goblin", 20, 20, 3, None, None, None, None, "Beast", "goblin", goblin_targetable_areas) self.goblin_2 = Enemy(self, self.player, 256, 384, 2, "Goblin", 20, 20, 3, None, None, None, None, "Beast", "goblin", goblin_targetable_areas) room_1_enemies = [self.goblin, self.goblin_2] self.rightDoor = Door( self, 9, 4, "right", True, "img/tile/chasm/chasm_door_right.png", "img/tile/chasm/chasm_wall_right.png" ) #initialize doors. There will be only four doors, each representing a cardinal direction. A room can have 1-4 doors. self.leftDoor = Door(self, 0, 4, "left", True, "img/tile/chasm/chasm_door_left.png", "img/tile/chasm/chasm_wall_left.png") self.forwardDoor = Door(self, 4, 0, "forward", True, "img/tile/chasm/chasm_door_top.png", "img/tile/chasm/chasm_wall_top.png") self.backwardDoor = Door(self, 4, 9, "backward", True, "img/tile/chasm/chasm_door_bottom.png", "img/tile/chasm/chasm_wall_top.png") self.display_inventory = False #flag to check whether the inventory window is open or not self.z1r1 = Room( self, "base", [self.backwardDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r1, room_1_enemies ) #initialize some basic rooms, each with a different background image to tell them apart. #enter a list of doors to represent the doors of the room. self.z2r2 = Room(self, "base", [self.backwardDoor, self.forwardDoor, self.rightDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r2, []) self.z3r3 = Room(self, "base", [self.forwardDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r3, []) self.z4r4 = Room(self, "base", [self.leftDoor], "img/tile/chasm/chasm_01.png", "img/tile/chasm/chasm_01_full.png", objects.props_z1r4, []) self.ZONE1 = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, self.z1r1, 0, 0, 0, 0], [0, self.z2r2, self.z4r4, 0, 0, 0], [0, self.z3r3, 0, 0, 0, 0]] self.battle = False self.titlescreen = TitleScreen(self, 0, 0) self.clock_group = pygame.sprite.Group() #create a 2D array of rooms to represent this zone. #self.currentLocation = #self.z1r1 = Room(self, "base", "door", "img/tile/chasm/chasm_01.png") #create a new Room object (see assets.py) #for x in range(0, 8): # for y in range(0, 8): # self.active_tiles.add(self.z1r1.tiles[x][y]) #fill the active_tiles sprite group with the tiles from the room object #create some random items #messages = ["Yes", "No", None, None] #dialogBox = optionBox(self, 64, 512, self.player, messages, "Will you accept the blessing?") #dialogBox.add(self.active_option_boxes) pygame.font.init() self.clock = pygame.time.Clock() self.prevKey = None self.minimap = Minimap(self, 500, 500, "minimap", self.player)
def layout_level9(screen): p3_width = 50 p_height = 50 p_width = 100 p4_height = 105 p4_width = 15 platforms = [] platforms.append(Block(450, 70, p_width, p_height, "block1.png")) platforms.append(Block(250, 175, p_width, p_height, "block1.png")) platforms.append(Block(450, 280, p_width, p_height, "block1.png")) platforms.append(Block(350, 385, p_width, p_height, "block1.png")) platforms.append(Block(50, 490, p_width, p_height, "block1.png")) platforms.append(Block(450, 490, p_width, p_height, "block1.png")) platforms.append(Block(250, 490, p_width, p_height, "block1.png")) platforms.append(Block(50, 175, p_width, p_height, "block2.png")) platforms.append(Block(150, 280, p_width, p_height, "block2.png")) platforms.append(Block(750, 280, p_width, p_height, "block2.png")) platforms.append(Block(550, 385, p_width, p_height, "block2.png")) platforms.append(Block(550, 490, p_width, p_height, "block2.png")) platforms.append(Block(125, 70, p3_width, p_height, "block3.png")) platforms.append(Block(625, 70, p3_width, p_height, "block3.png")) platforms.append(Block(775, 70, p3_width, p_height, "block3.png")) platforms.append(Block(375, 175, p3_width, p_height, "block3.png")) platforms.append(Block(425, 175, p3_width, p_height, "block3.png")) platforms.append(Block(25, 280, p3_width, p_height, "block3.png")) platforms.append(Block(75, 385, p3_width, p_height, "block3.png")) platforms.append(Block(175, 385, p3_width, p_height, "block3.png")) platforms.append(Block(725, 490, p3_width, p_height, "block3.png")) # Walls platforms.append(Block(200, 70, p4_width, p4_height, "block4.png")) platforms.append(Block(300, 70, p4_width, p4_height, "block4.png")) platforms.append(Block(700, 70, p4_width, p4_height, "block4.png")) platforms.append(Block(100, 175, p4_width, p4_height, "block4.png")) platforms.append(Block(200, 175, p4_width, p4_height, "block4.png")) platforms.append(Block(300, 280, p4_width, p4_height, "block4.png")) platforms.append(Block(500, 280, p4_width, p4_height, "block4.png")) platforms.append(Block(600, 280, p4_width, p4_height, "block4.png")) platforms.append(Block(700, 385, p4_width, p4_height, "block4.png")) platforms.append(Block(100, 385, p4_width, p4_height, "block4.png")) platforms.append(Block(300, 490, p4_width, p4_height, "block4.png")) platforms.append(Block(500, 490, p4_width, p4_height, "block4.png")) #Floor platforms.append(Block(50, 590, p_width, p_height, "block1.png")) platforms.append(Block(150, 590, p_width, p_height, "block1.png")) platforms.append(Block(250, 590, p_width, p_height, "block1.png")) platforms.append(Block(350, 590, p_width, p_height, "block1.png")) platforms.append(Block(450, 590, p_width, p_height, "block1.png")) platforms.append(Block(550, 590, p_width, p_height, "block1.png")) platforms.append(Block(650, 590, p_width, p_height, "block1.png")) platforms.append(Block(750, 590, p_width, p_height, "block1.png")) lampHeight = lampImage.get_height() lampList = [ Lamp((25, 280), lampImage, lightAlpha, 25), Lamp((50, 590), lampImage, lightAlpha, 20), Lamp((250, 175), lampImage, lightAlpha, 10), Lamp((600, 590), lampImage, lightAlpha, 5), Lamp((625, 70), lampImage, lightAlpha, 20) ] letter = Letter(pygame.image.load('Assets/Letters/letter5.png'), (450, 280)) doorList = [Door((350, 590), False), Door((550, 590), True)] return platforms, lampList, doorList, letter
def do_GET(self): # 发送空的响应头 self.send_response(200) self.end_headers() # 从地址中分割出若干参数 params = self.path.split('/') # 捕获所有错误,防止程序崩溃 try: # 因为有根目录,分割后params[0]必定是空字符串 # # camera指令: # # 如果前边初始化摄像头成功,则直接返回一帧图像 # # 否则反馈错误信息 # if params[1] == 'camera': # if cam != None: # __, img = cam.read() # cv2.imwrite('/tmp/camera.jpg', img) # with open('/tmp/camera.jpg', 'rb') as f: # self.wfile.write(f.read()) # else: # self.wfile.write("没有检测到摄像头,请插入usb摄像头后重启系统") # # virtkey指令: # # 如果参数为单字符,则模拟这个按键 # # 否则反馈错误信息 # elif params[1] == 'virtkey': # if len(params[2]) == 1: # ord_key = ord(params[2]) # v.press_keysym(ord_key) # v.release_keysym(ord_key) # else: # self.wfile.write("参数有误,virtkey指令仅支持单字符参数") # # cmd指令: # # 如果参数的python函数是合法的,则尝试执行这条指令 # # 如果途中出错,反馈错误信息 # elif params[1] == 'cmd': # for func in PCDUINO_FUNC: # if params[2].startswith(func): # try: # exec(params[2]) # except: # self.wfile.write(params[2] + '函数的参数有误') # break # else: # self.wfile.write(params[2] + '不是一个已知的函数') if params[1] == 'isSmartHome': self.wfile.write('SmartHome'.encode('utf-8')) elif params[1] == 'door-switch': self.wfile.write(str(Door.doorSwitch()).encode('utf-8')) elif params[1] == 'whiteLight-switch': self.wfile.write( str(Furniture.whiteLightSwitch()).encode('utf-8')) elif params[1] == 'bigLight-switch': self.wfile.write( str(Furniture.bigLightSwitch()).encode('utf-8')) elif params[1] == 'bigLight-set': self.wfile.write( str(Furniture.bigLightSet(params[2], params[3])).encode('utf-8')) elif params[1] == 'fan-switch': self.wfile.write(str(Furniture.fanSwitch()).encode('utf-8')) elif params[1] == 'debug': if params[2] == 'pwm': if params[3] == 'set': Furniture.setPWM(int(params[4]), int(params[5]), int(params[6])) self.wfile.write('ok'.encode('utf-8')) elif params[3] == 'en': Furniture.enPWM(int(params[4])) self.wfile.write(params[4].encode('utf-8')) elif params[3] == 'dis': Furniture.disPWM(int(params[4])) self.wfile.write(params[4].encode('utf-8')) elif params[3] == 'max': if (params[4] == 'all'): self.wfile.write( (Furniture.getMax(3) + Furniture.getMax(5) + Furniture.getMax(6) + Furniture.getMax(9) + Furniture.getMax(10) + Furniture.getMax(11)).encode('utf-8')) else: self.wfile.write( Furniture.getMax(int( params[4])).encode('utf-8')) elif params[3] == 'get': if (params[4] == 'all'): self.wfile.write( (Furniture.getNow(3) + Furniture.getNow(5) + Furniture.getNow(6) + Furniture.getNow(9) + Furniture.getNow(10) + Furniture.getNow(11)).encode('utf-8')) else: self.wfile.write( Furniture.getNow(int( params[4])).encode('utf-8')) elif params[2] == 'gpio': if (params[3] == 'set'): Furniture.setGPIO(int(params[4]), int(params[5])) self.wfile.write('ok'.encode('utf-8')) # 其他指令:无效 else: self.wfile.write('无效指令'.encode('utf-8')) except IndexError: self.wfile.write('http地址参数错误:IndexError'.encode('utf-8')) except: self.wfile.write('指令或参数存在未知错误'.encode('utf-8')) #self.wfile.write(sys.exc_info()[0]) raise
print("命令行参数:%s" % sys.argv) #TCPSocket.startServer() HttpServer.start() about() print("SmartHome已启动\n控制台帮助请输入help") # ---------------------------- # loop while True: cmd = input("wxx>") if cmd == "help": print("SmartHome控制台帮助") print("about或version-----显示版本信息") print("help-----显示此帮助") print("stop或exit-----退出程序") print("") elif cmd == "stop" or cmd == "exit": stop() elif cmd == "about" or cmd == "version": about() elif cmd == "doortest1": doortest1() elif cmd == 'doorswitch': Door.door_switch(pinList['door']) elif cmd == '': pass else: print("未知命令 输入help查看帮助") cmd = "" # --------------------------------------
os.environ['SDL_VIDEO_CENTERED'] = '1' #centers the application window in the middle of the screen on startup pygame.init() #initialize the screen to size 800 x 600 gameDisplay = pygame.display.set_mode((1000, 1000)) #creates the Player character in the location 20, 20 player = Player.Player(30, 30,playerimage) #Defines the starting positions of the first two Particles for level 1 of the game particle1 = Particle.Particle(100, 100, False, None,redParticle,False) particle2 = Particle.Particle(100, 200, True, particle1,blueParticle,False) #Particle 2 is entangled to Particle one #Defines the position for the first goal for level 1 of the game goal = Goal.Goal(400, 400) door=Door.Door(760,300,20,100) #NOTE: Negative numbers in wall declarations ruin collision detection leftWall = Wall.Wall(0, 0, 20, 600) rightWall = Wall.Wall(780, 0, 20, 600) topWall = Wall.Wall(0, 0, 800, 20) bottomWall = Wall.Wall(0, 580, 800, 20) walls=[topWall,bottomWall,rightWall,leftWall] #Defines the objects that the Player character cannot pass through entities = [player,particle1, particle2, leftWall, rightWall, topWall, bottomWall] particles=[particle1,particle2] #rank by what you want to appear on what reversed
input("Press Enter to Continue...") print( "This is your father's castle. Yet your adventure does not start in the throne room, or the dining room, or even your bedroom." ) input("Press Enter to Continue...") print( "You have awoken this morning locked in the jail cell in the cellar of the castle. Surrounded by rats and other undesirables." ) input("Press Enter to Continue...") print("Your memory slowly returns as you clear the sleep from your eyes...") print( "You remember the violent murder of your father at the hands of your uncle\nYou realize your uncle must have thrown you in the jail to keep you out of the way" ) print("until he can fully take over the kingdom!") input("Press Enter to Continue...") print( "You quickly escape the jail cell and decide to confront your uncle in the throne room!" ) input("Press Enter to Continue...") #Game Starts Here! #Predefined location, with one potion type random item. JailCell = Environment([EnvironmentGenerator.genObject(2, difficulty)], "smelly dark room outside your jail cell", [Door(False, "Up", 0)]) print(JailCell.toString()) #Testing RunCode while (1): input("Press Enter to Continue...") print(EnvironmentGenerator.genEnvironment(difficulty, "Up").toString())
enemies = [] shops = [] clockTick = 60 andar = 0 lg = levelGenerator(player, bullets, seed, 10, size) enemies = lg.getAtualMap().enemies obstaculo = lg.getAtualMap().obstaculos player.platforms = obstaculo shops = lg.getAtualMap().shops doors = [ Door(int(size * 3 / 8), 0, int(size / 8), int(size / 80), "left"), Door(int(size * 4 / 8), 0, int(size / 8), int(size / 80), "right"), Door(int(size * 3 / 8), int(size - size / 80), int(size / 8), int(size / 80), "left"), Door(int(size * 4 / 8), int(size - size / 80), int(size / 8), int(size / 80), "right"), Door(0, int(size * 3 / 8), int(size / 80), int(size / 8), "up"), Door(0, int(size * 4 / 8), 10, int(size / 8), "down"), Door(int(size - size / 80), int(size * 3 / 8), int(size / 80), int(size / 8), "up"), Door(int(size - size / 80), int(size * 4 / 8), 10, int(size / 8), "down") ] player.doors = doors def changeSlice(nmap):