def gameInit(self): # make game board 0~16 self.boards.append(Board(0, 1, "정문", self.texArr)) self.boards.append(Board(1, 0, "넉터", self.texArr)) self.boards.append(Board(2, 0, "제6 공학관", self.texArr)) self.boards.append(Board(3, 0, "인문관", self.texArr)) self.boards.append(Board(4, 0, "대학본부", self.texArr)) self.boards.append(Board(5, 0, "제2 공학관", self.texArr)) self.boards.append(Board(6, 0, "문창회관", self.texArr)) self.boards.append(Board(7, 0, "자연대 연구실험동", self.texArr)) self.boards.append(Board(8, 0, "새벽벌도서관", self.texArr)) self.boards.append(Board(9, 0, "사회관", self.texArr)) self.boards.append(Board(10, 0, "금정회관", self.texArr)) self.boards.append(Board(11, 0, "법학관", self.texArr)) self.boards.append(Board(12, 0, "테니스장", self.texArr)) self.boards.append(Board(13, 0, "제 1도서관", self.texArr)) self.boards.append(Board(14, 0, "무지개문", self.texArr)) self.boards.append(Board(15, 0, "건설관", self.texArr)) self.dice = Dice(self.texArr) # player setting for player_no in range(4): self.player.append(Player(player_no)) # character setting for player_no in range(4): self.characters.append(Character(self, player_no, player_no)) for build_no in range(16): self.buildings.append((Building(build_no, self.texArr)))
def get_buildings(village): driver = village.driver #First get resource production buildings driver.get(server + "/dorf1.php") areas = driver.find_elements_by_css_selector("#rx > area") areas_href = [] for i in areas: areas_href.append(i.get_attribute("href")) #areas_href = (i.get_attribute("href") for i in areas) resource_buildings = [] for x in areas_href: print(x) driver.get(x) cost_spans = driver.find_elements_by_css_selector( "#contract > .resourceWrapper > .resource > .value") cost = [] for span in cost_spans: cost.append(int(span.text)) building = Building.Building() building.cost = cost building.href = x building.village = village building.is_resource = True resource_buildings.append(building) print(resource_buildings)
def main(): win = GraphWin("TestWindow", 1900, 1000) b1 = Building(100, 400, "gray", win, "black", "white") b2 = House(600, 400, color_rgb(219, 215, 177), win, "white", color_rgb(81, 45, 45)) b3 = Townhouse(1100, 400, color_rgb(102, 51, 0), win, "white", color_rgb(79, 36, 18)) win.getMouse() win.close()
def location_options(self, player_id, loc_name, loc_type, building_types): loc_inst = Location() build_inst = Building.Building() desc_str = "You find yourself in the {} of {}.\nYou see".format(loc_type, loc_name) opts_str = "[(M)ap] [(Q)uest] [(I)nventory] [(H)elp] [(E)xit]\n" for index, building_type in enumerate(building_types): if index < (len(building_types) - 1): desc_str += " a {},".format(building_type) elif index == (len(building_types) - 1): desc_str += " and a {}.\nWhat do you do?\n".format(building_type) opts_str += "{}) Go to {}\n".format((index + 1), building_type) opts_str += "{}) Leave {}\n".format((len(building_types)+1), loc_name) print(desc_str) print(opts_str) selection = input("Selection: ") try: select_num = int(selection) if select_num <= len(building_types): bldg_type = building_types[select_num-1] curr_name = characterInst.get_char_name(player_id) loc_id = loc_inst.get_current_location(curr_name) build_inst.enter_building(bldg_type, player_id, loc_id) else: print("Leaving {}".format(loc_name)) nearby_towns = loc_inst.leave(player_id, False) nearby_str = "[(M)ap] [(Q)uest] [(I)nventory] [(H)elp] [(E)xit]\n" for index, town in enumerate(nearby_towns): town_name = town["city_name"] nearby_str += "{}) Go to {}\n".format((index + 1), town_name) nearby_str += "{}) Head back into {}\n".format((len(nearby_towns) + 1), loc_name) print(nearby_str) travel_str = input("Selection: ") selection = travel_str travel_id = int(travel_str) if travel_id <= len(nearby_towns): dest_name = nearby_towns[travel_id-1]["city_name"] dest_obj = locationInst.go_to(dest_name, player_id) destType = dest_obj["town_description"] destBldgs = dest_obj["buildings"] self.location_options(player_id, dest_name, destType, destBldgs) else: dest_name = loc_name self.location_options(player_id, dest_name, loc_type, building_types) except ValueError: self.menu_option(selection, player_id, loc_name, loc_type, building_types)
def __init__(self, deck, left=True): """Build everything and get 6 cards from 'deck'""" res_x = Const.RESX res_y = Const.RESY pos_x = res_x - 11 * res_x / 80 if left: pos_x = res_x / 80 self.tower = Building.Building(left, True, Const.INIT_TOWER) self.wall = Building.Building(left, False, Const.INIT_TOWER / 2) self.brick = Ressource.Ressource((pos_x, res_y / 20), Const.DARK_RED, _("Bricks")) self.gem = Ressource.Ressource((pos_x, res_y / 10 + res_y / 7), Const.DARK_BLUE, _("Gems")) self.crea = Ressource.Ressource( (pos_x, 3 * res_y / 20 + 2 * res_y / 7), Const.DARK_GREEN, _("Creatures")) self.cards = [] for i in xrange(1, 7): self.cards.append( deck.get_card((i * res_x / 49 + (i - 1) * res_x / 7, res_y - Const.CARD_HEIGHT))) self.win = False self.deck = deck
def create_npc(self, player_id, typeStr, location_id): buildInst = Building.Building() with open('npc_names.json') as data: npc_names = json.load(data) random_npc = randint(0, len(npc_names) - 1) name = npc_names[random_npc]['name'] if (typeStr == 'BlackSmith'): function = 'Blacksmith' elif (typeStr == 'Tavern'): function = 'Bartender' elif (typeStr == 'Church'): function = 'Priest' elif (typeStr == 'Potion Shop'): function = 'Potion Dealer' elif (typeStr == 'Armor Shop'): function = 'Armor Dealer' elif (typeStr == 'Defense Shop'): function = 'Defense Dealer' elif (typeStr == 'Inn'): function = 'Innkeeper' elif (typeStr == 'Clinic'): function = 'Healer' fullName = name + " the " + function self.connection.cursor.execute( """INSERT INTO `NPC`(npc_name, npc_function, location_id) VALUES('{}', '{}', '{}');""".format(fullName, typeStr, location_id)) self.connection.conn.commit() print("Upon entering the {} you see someone working hard.\n".format( typeStr)) print("Options: \n") selection = input("1) Approach them\n" "2) Leave\n" "Selection: ") if selection == "1": print("\"Hello, I'm {}. I've got a problem can you handle it?\"\n". format(fullName)) choice = input("(Y/N) ") if choice == 'Y' or choice == 'y': #create quest description = self.create_quest(location_id, player_id) print("\"I need you to {}\"\n".format(description)) print("Quest added to your quest log!") else: print("OK then out ya go!\n") buildInst.leave_building(player_id, location_id)
def expandNode(self, currentState, move): gameState = currentState.fastclone() # ourInventory = gameState.inventories[self.playerId] ourId = gameState.whoseTurn ourInventory = gameState.inventories[gameState.whoseTurn] if (move.moveType == MOVE_ANT): antToMove = None for ant in ourInventory.ants: if ant.coords == move.coordList[0]: antToMove = ant if antToMove is not None: antToMove.coords = move.coordList[-1] antToMove.hasMoved = True # check if other ants near by for attack opponentId = self.getOpponentId(gameState.whoseTurn) enemyInv = gameState.inventories[opponentId] ## Checks if can attack. self.attackSequence(enemyInv, antToMove) elif (move.moveType == BUILD): # just worried about building Ants and Tunnel if (move.buildType == WORKER): # add ant ourInventory.ants.append(Ant(move.coordList[-1], WORKER, ourId)) # subtract food ourInventory.foodCount -= 1 elif (move.buildType == DRONE): ourInventory.ants.append(Ant(move.coordList[-1], DRONE, ourId)) ourInventory.foodCount -= 1 elif (move.buildType == SOLDIER): ourInventory.ants.append( Ant(move.coordList[-1], SOLDIER, ourId)) ourInventory.foodCount -= 2 elif (move.buildType == R_SOLDIER): ourInventory.ants.append( Ant(move.coordList[-1], R_SOLDIER, ourId)) ourInventory.foodCount -= 2 elif (move.buildType == TUNNEL): ourInventory.constrs.append( Building(move.coordList[-1], TUNNEL, ourId)) ourInventory.foodCount -= 3 else: self.pickUpFood(gameState, ourInventory) self.dropOffFood(gameState, ourInventory) return gameState return gameState
def __init__(self, settings, gui): if isinstance(settings, Config.Config_World): self.settings = settings self.gui = gui if isinstance(settings.screen, Config.Config_Screen): render.start(self.settings.screen.x_pos, self.settings.screen.y_pos, self.settings.screen.x_size, self.settings.screen.y_size, 1000) # creating city grid for b in range(2): self.x_location += 100 self.y_location = 90 for z in range(3): self.y_location -= 20 # self.x_location += 20 for i in range(2): self.y_location -= 10 self.x_location -= 20 self.c = random.randint(0, 1) for t in range(2): self.c2 = random.randint(0, 1) b_location = P3.P3(self.x_location, self.y_location, 0) # print(b_location) buildings.extend([ Building.Building(b_location, 10, random.randrange(20, 65), 10, (self.c, 0, self.c2)) ]) self.x_location += 10 if isinstance(settings, Config.Config_World): flock = settings.flocks[0] if isinstance(flock, Config.Config_Flock): self.F1 = Flock.Flock(flock.count, World.make_force_field(buildings), flock.center, flock.radius) self.render = render.Render(self.F1) gui.set_tick_method(self.tick)
def generateRandomBuildings(numberOfBuildings, city, areaRange=[10, 1000]): direct = city.streetNWAdm.getDirectEdges() buildings = [] for _ in range(numberOfBuildings): randomNumber = random.randint(0, len(direct) - 1) randomEdge = direct[randomNumber] # Filter not highway ways and some unwanted highway ways if not city.isStreetWay(randomEdge[City.WAY]): continue nodeId = ToolsExt.generateRandomNodeInEdge(randomEdge, city) randomArea = random.randint(areaRange[0], areaRange[1]) building = Building.Building(nodeId, randomArea, city.getNodeLat(nodeId), city.getNodeLon(nodeId)) buildings.append(building) return buildings
import Building import Sprite import pygame building1 = Building.Building( Sprite.Sprite(pygame.image.load('images/ArcherTowerBuilding.png')), Building.archerTowerEffect, 1) buildings = [building1]
RSI_steel_door = 35 # Building Materials (Mark's addition) RSI_interior_wall = .1 * RSI_drywall + .2 * RSI_fiberglass RSI_exterior_wall = .05 * RSI_drywall + .3 * RSI_fiberglass + .15 * RSI_concrete RSI_roofing = 0.05 * RSI_drywall + 0.3 * RSI_fiberglass + RSI_wood_roof # inline function for parallel Reff r_par = lambda A, R: 1 / (sum(np.divide(np.array(A), np.array(R))) / sum( np.array(A))) #note: A and R must be np arrays ## Creating the building L = 17 #length of building, replace w/ your own value W = 13 #width of building Tmin = [294, 294, 294, 294, 294, 291, 290] Tmax = [300, 300, 300, 300, 300, 305, 295] building = Building(L, W) TH_range = [300, 320] fH_max = 4 building.addHeater(TH_range, fH_max, building) TC_range = [285, 295] fC_max = 2 building.addCooler(TC_range, fC_max, building) ## Add rooms # use building.addRoom(roomID,TRange,roomL,roomW) building.addRoom(0, [294, 300], 6, 5) building.addRoom(1, [294, 300], 5, 7) building.addRoom(2, [294, 300], 8, 8) building.addRoom(3, [294, 300], 5, 6) building.addRoom(4, [294, 300], 6, 5) building.addRoom(5, [291, 305], 4, 4)
from Graphics import * import time from Building import * from Base import * win = GraphWin("City",1900,1000) land = City(win) land.backdrop() b1 = Building(100, 350, "gray", win, "black", "white") b2 = House(600, 350, color_rgb(219, 215, 177), win, "white", color_rgb(81, 45, 45)) b3 = Townhouse(1200, 350, color_rgb(102, 51, 0), win, "white", color_rgb(79, 36, 18)) land.drawBox() win.getMouse() y = 0 vlc.MediaPlayer("siren.wav").play() while y <= 600: nuke = Nuke(win, 950, y) y += 100 time.sleep(1) nuke.explode() win.getMouse()
def gameInit(self): self.sounds = Sound.Sound() self.building = Building.Building(self.screen, self.screenSize) if self.rainEffect: self.weather = [] for columnNumber in range(1, self.building.leftWallX // Weather.SIZE): self.weather.append( Weather.Column(columnNumber * Weather.SIZE, self.screen, self.building.floorY)) for columnNumber in range(self.building.leftWallX // Weather.SIZE, self.building.rightWallX // Weather.SIZE): self.weather.append( Weather.Column(columnNumber * Weather.SIZE, self.screen, self.building.leftWallX)) for columnNumber in range(self.building.rightWallX // Weather.SIZE, self.screenWidth // Weather.SIZE): self.weather.append( Weather.Column(columnNumber * Weather.SIZE, self.screen, self.building.floorY)) self.sky = Weather.Sky(self.screen, self.screenWidth, self.screenHeight, self.building.leftWallX, self.building.rightWallX, self.building.ceilingY, self.sounds) # RANDOMLY SPAWNED self.hero = Character.Player(self.screen, self.building, self.screenWidth, self.screenHeight) self.cultist = Trash.Cultist(self.screen, self.building) self.enemiesToSpawn.append(self.cultist) self.cultist2 = Trash.Cultist(self.screen, self.building) self.enemiesToSpawn.append(self.cultist2) self.angel = Trash.Angel(self.screen, self.building) #self.enemies.append(self.angel) #self.angel.spawn() self.enemiesToSpawn.append(self.angel) self.skeleton = Trash.Skeleton(self.screen, self.building) self.enemiesToSpawn.append(self.skeleton) self.skeleton2 = Trash.Skeleton(self.screen, self.building) self.enemiesToSpawn.append(self.skeleton2) self.bomb = Equipment.Bomb(self.screen, self.building) self.equipmentToSpawn.append(self.bomb) self.bomb2 = Equipment.Bomb(self.screen, self.building) self.equipmentToSpawn.append(self.bomb2) self.garlic = Equipment.Garlic(self.screen, self.building) self.equipmentToSpawn.append(self.garlic) self.garlic2 = Equipment.Garlic(self.screen, self.building) self.equipmentToSpawn.append(self.garlic2) self.flute = Equipment.Flute(self.screen, self.building) self.equipmentToSpawn.append(self.flute) self.flute2 = Equipment.Flute(self.screen, self.building) self.equipmentToSpawn.append(self.flute2) self.rune = Equipment.Rune(self.screen, self.building) self.equipmentToSpawn.append(self.rune) self.rune2 = Equipment.Rune(self.screen, self.building) self.equipmentToSpawn.append(self.rune2) self.rune3 = Equipment.Rune(self.screen, self.building) self.equipmentToSpawn.append(self.rune3) self.sword = Equipment.Sword(self.screen, self.building) self.equipmentToSpawn.append(self.sword) self.whip = Equipment.Whip(self.screen, self.building) self.equipmentToSpawn.append(self.whip) self.shield = Equipment.Shield(self.screen, self.building) self.equipmentToSpawn.append(self.shield)
def main(num_people): #initial the elevator system system = System(3) #initial the building with total number of customers, total floor by default is 5 building = Building(num_people) #pools = building.adict max_iter = 2500 count = {0: 3, 1: 3, 2: 3} peoplecount = 0 a = 0 # start the simulation for step in range(max_iter): # print step # print peoplecount ## if peoplecount < building.total_cus if peoplecount < 0.6 * building.total_cus or ( len(system.elevators[0].remain_list) + len(system.elevators[1].remain_list) + len(system.elevators[2].remain_list)) > 0: #Update pool in each level pools = building.dictionUpdate() system.requireOut(pools) #print pools[1].alreadyIn for key in system.elevators: #print 1,system.elevators[0].direction,system.elevators[0].cur_floor #print system.requireout_up,system.requireout_down,len(system.elevators[0].remain_list),len(system.elevators[1].remain_list) #update RequireOut information system.outdemand(key) #print system.elevators[key].cur_floor #direction change system.DecisionDecide(system.elevators[key]) #print system.elevators[2].Aimminglist #move or load & release customers #if elevator stops, it will stop 4 time step # print count[0] # print 0,system.elevators[0].Aimminglist #print key,system.elevators[0].cur_floor,len(system.elevators[0].remain_list),system.elevators[0].Aimminglist,system.elevators[0].direction,count[0] # print system.elevators[key].Aimminglist,key if count[key] == 3: if (system.elevators[key].cur_floor == 1 and system.elevators[key].direction == 'down'): system.elevators[key].direction = 'stay' elif (system.elevators[key].cur_floor == len( system.requireout_up) and system.elevators[key].direction == 'up'): system.elevators[key].direction = 'stay' system.elevators[key].move() # print system.requireout_up,system.requireout_down # if there's requires,open the door, upload & release customers if len(system.elevators[key].Aimminglist) == 1: if system.elevators[key].Aimminglist[ 0] == system.elevators[key].cur_floor: count[key] = 0 else: if system.elevators[key].Aimminglist[ 0] == system.elevators[ key].cur_floor or system.elevators[ key].Aimminglist[1] == system.elevators[ key].cur_floor or system.elevators[ key].Aimminglist[ -1] == system.elevators[ key].cur_floor: count[key] = 0 else: #print system.elevators[0].cur_floor,system.elevators[0].direction,count[0] if len(system.elevators[key].Aimminglist) == 1: count[key] = count[key] + 1 if system.elevators[key].Aimminglist[ 0] == system.elevators[key].cur_floor: j = 0 while j < len(system.elevators[key].remain_list): cus = system.elevators[key].remain_list[j] if cus.dest_floor == system.elevators[ key].cur_floor: system.elevators[key].cancel_customer(cus) A4 = system.elevators[key].Aimminglist[1:] if system.elevators[key].cur_floor in A4: A4.remove( system.elevators[key].cur_floor) system.elevators[key].Aimminglist = [ system.elevators[key].Aimminglist[0] ] + A4 peoplecount = peoplecount + 1 else: j = j + 1 if len(system.elevators[key].remain_list ) == system.elevators[key].capacity: pass else: if (system.elevators[key].direction == "up") or ( (system.elevators[key].direction == 'stay') and (len(pools[system.elevators[key]. cur_floor].pool_up) >= len(pools[system.elevators[key]. cur_floor].pool_down))): z = 0 while z < len(pools[system.elevators[key]. cur_floor].pool_up): cus = pools[system.elevators[key]. cur_floor].pool_up[z] system.elevators[key].add_customer(cus) pools[system.elevators[key]. cur_floor].Uppoolremove(cus) if len( system.elevators[key]. remain_list ) == system.elevators[key].capacity: break elif (system.elevators[key].direction == "down") or ( system.elevators[key].direction == 'stay' and len(pools[system.elevators[key]. cur_floor].pool_up) < len(pools[system.elevators[key]. cur_floor].pool_down)): z = 0 while z < len(pools[system.elevators[key]. cur_floor].pool_down): cus = pools[system.elevators[key]. cur_floor].pool_down[z] system.elevators[key].add_customer(cus) pools[system.elevators[key]. cur_floor].Downpoolremove(cus) if len( system.elevators[key]. remain_list ) == system.elevators[key].capacity: break else: pass system.elevators[key].requireIn.sort() for i in system.elevators[key].requireIn: if i not in system.elevators[key].Aimminglist[ 1:]: system.elevators[key].Aimminglist.append(i) Aimin = system.elevators[key].Aimminglist[1:] Aimin.sort() system.elevators[key].Aimminglist = [ system.elevators[key].Aimminglist[0] ] + Aimin else: count[key] = count[key] + 1 if system.elevators[key].Aimminglist[ 1] == system.elevators[ key].cur_floor or system.elevators[ key].Aimminglist[( len(system.elevators[key]. Aimminglist) - 1 )] == system.elevators[key].cur_floor: #print 100,system.elevators[key].Aimminglist i = 0 while i < len(system.elevators[key].remain_list): cus = system.elevators[key].remain_list[i] if cus.dest_floor == system.elevators[ key].cur_floor: system.elevators[key].cancel_customer(cus) A4 = system.elevators[key].Aimminglist[1:] if system.elevators[key].cur_floor in A4: A4.remove( system.elevators[key].cur_floor) system.elevators[key].Aimminglist = [ system.elevators[key].Aimminglist[0] ] + A4 peoplecount = peoplecount + 1 else: i = i + 1 if len(system.elevators[key].remain_list ) == system.elevators[key].capacity: pass else: if (system.elevators[key].direction == "up") or ( (system.elevators[key].direction == 'stay') and (len(pools[system.elevators[key]. cur_floor].pool_up) >= len(pools[system.elevators[key]. cur_floor].pool_down))): z = 0 while z < len(pools[system.elevators[key]. cur_floor].pool_up): cus = pools[system.elevators[key]. cur_floor].pool_up[z] system.elevators[key].add_customer(cus) pools[system.elevators[key]. cur_floor].Uppoolremove(cus) if len( system.elevators[key]. remain_list ) == system.elevators[key].capacity: break elif (system.elevators[key].direction == "down") or ( system.elevators[key].direction == 'stay' and len(pools[system.elevators[key]. cur_floor].pool_up) < len(pools[system.elevators[key]. cur_floor].pool_down)): z = 0 while z < len(pools[system.elevators[key]. cur_floor].pool_down): cus = pools[system.elevators[key]. cur_floor].pool_down[z] system.elevators[key].add_customer(cus) pools[system.elevators[key]. cur_floor].Downpoolremove(cus) if len( system.elevators[key]. remain_list ) == system.elevators[key].capacity: break else: pass system.elevators[key].requireIn.sort() for i in system.elevators[key].requireIn: if i not in system.elevators[key].Aimminglist[ 1:]: system.elevators[key].Aimminglist.append(i) Aimin = system.elevators[key].Aimminglist[1:] Aimin.sort() system.elevators[key].Aimminglist = [ system.elevators[key].Aimminglist[0] ] + Aimin else: return step