def start(self): self.players = [] self.time_left = 15 self.time_til_bomb = -1 self.ct_rounds = 0 self.t_rounds = 0 self.bomb_location = None if self.player_is_terrorist: self.players.append(Player(Terrorist)) self.players.append(NPC(CounterTerrorist)) else: self.players.append(Player(CounterTerrorist)) self.players.append(NPC(Terrorist)) for i in range(1, 5): self.players.append(NPC(CounterTerrorist)) self.players.append(NPC(Terrorist)) t_with_bomb = randint(1, 5) t_index = 0 for player in self.players: if player.side != Terrorist: continue t_index += 1 if t_index == t_with_bomb: player.give_bomb()
def update(self, dT): if not self.grabbedBy: self.collide() NPC.update(self, dT) else: self.pos = self.grabbedBy.pos if not self.alive: self.imageIndex += 1 self.image = self.deathAnim[min(self.imageIndex, len(self.deathAnim)-1)]
def case_message_npc_create(self): pid = int(self.readdouble()) name = self.readstring() x = self.readdouble() y = self.readdouble() hpmax = self.readdouble() hp = self.readdouble() n = NPC(self.world, name, pid, x, y, hpmax) n.hp = hp self.world.npcs.append(n) n.start()
def __init__(self, size, position, maxRotVel, maxRotAcc, a): NPC.__init__(self, size, position, maxRotVel, maxRotAcc, a) self.name = 'Prey' self.alive = True self.deathAnim = [] for i in range(6): self.deathAnim.append( pygame.image.load('data/Prey 0%d.png' % (i+1))) self.imageIndex = 0 self.image = self.deathAnim[self.imageIndex] self.radius = self.image.get_rect().width/2 self.lifeSpan = 30 * len(self.deathAnim)
def mouseChunkBuild(gameobj): tempx, tempy = pygame.mouse.get_pos() mousex = int(((tempx + gameobj.player.pos.x) - mapDict["HALF_WIDTH"]) / mapDict["GRID_SIZE"]) # convert to grid system mousey = int(((tempy + gameobj.player.pos.y) - mapDict["HALF_HEIGHT"]) / mapDict["GRID_SIZE"]) # convert to grid system try: ind = gameobj.poslist[mousey][mousex] except: return chunk = findChunk(gameobj, mousex, mousey) if gameobj.blocksetlist[ind].blockType == "empty": if globDict["blockbuild"].lower() == "block": gameobj.blocksetlist[ind] = BlockSet(mousex * mapDict["GRID_SIZE"], mousey * mapDict["GRID_SIZE"], globDict["size"], "block") gameobj.chunklist[chunk].bl.append(gameobj.blocksetlist[ind]) gameobj.chunklist[chunk].pl.append(ind) gameobj.chunklist[chunk].rl.append(gameobj.blocksetlist[ind].rect) elif globDict["blockbuild"].lower() == "npc": temp = NPC(mousex * mapDict["GRID_SIZE"], mousey * mapDict["GRID_SIZE"], 1, "npc", gameobj.player, globDict["vrange"]) gameobj.entlist.append(temp) gameobj.mousestate[1] = False return elif globDict["blockbuild"].lower() == "point": gameobj.blocksetlist[ind] = BlockSet(mousex * mapDict["GRID_SIZE"], mousey * mapDict["GRID_SIZE"], .5, "point") gameobj.chunklist[chunk].bl.append(gameobj.blocksetlist[ind]) gameobj.chunklist[chunk].pl.append(ind) gameobj.chunklist[chunk].rl.append(gameobj.blocksetlist[ind].rect) elif globDict["blockbuild"].lower() == "tower": gameobj.blocksetlist[ind] = Tower(mousex * mapDict["GRID_SIZE"], mousey * mapDict["GRID_SIZE"], 1, "tower", gameobj.player, globDict["vrange"]) gameobj.chunklist[chunk].bl.append(gameobj.blocksetlist[ind]) gameobj.chunklist[chunk].pl.append(ind) gameobj.chunklist[chunk].rl.append(gameobj.blocksetlist[ind].rect) elif globDict["blockbuild"].lower() == "invincible": gameobj.blocksetlist[ind] = BlockSet(mousex * mapDict["GRID_SIZE"], mousey * mapDict["GRID_SIZE"], 1, "invincible") gameobj.chunklist[chunk].bl.append(gameobj.blocksetlist[ind]) gameobj.chunklist[chunk].pl.append(ind) gameobj.chunklist[chunk].rl.append(gameobj.blocksetlist[ind].rect) elif globDict["blockbuild"].lower() == "respawn tower": gameobj.blocksetlist[ind] = RespawnTower( mousex * mapDict["GRID_SIZE"], mousey * mapDict["GRID_SIZE"], 1, "respawntower", gameobj.player) gameobj.chunklist[chunk].bl.append(gameobj.blocksetlist[ind]) gameobj.chunklist[chunk].pl.append(ind) gameobj.chunklist[chunk].rl.append(gameobj.blocksetlist[ind].rect)
def inn_decision(self, hero): inn_keeper = NPC(weapon_pile().get_random_weapon()) inn_choices = ["Sleep for the night", "Leave"] counter = 1 for i in inn_choices: print(str(counter) + ". " + i) counter += 1 inn_decision = input("Your decision: ") if int(inn_decision) is 1: print(hero.char.health_display()) if hero.char.max_health - hero.char.current_health == 0: print("It will cost you 5 gold.") else: print("It will cost you " + str((hero.char.max_health - hero.char.current_health) * 2) + " gold.") if hero.char.money >= (hero.char.max_health - hero.char.current_health) * 2 or hero.char.money >= 5: sleep_yn = input("Would you like to stay the night: ") if sleep_yn.upper() is "Y": if hero.char.max_health - hero.char.current_health == 0: hero.char.decrease_money(5) else: hero.char.decrease_money((hero.char.max_health - hero.char.current_health) * 2) hero.char.current_health = hero.char.max_health print("The " + hero.char.name + " walks upstairs to the rented room, and sleeps for the night.") else: print("The innkeeper looks at you with a furrowed brow and says \"Sorry, it appears you don't have enough gold.\"") print(hero.char.name + " leaves the inn.")
def onPluginStart(): # (Line 16) sys.SetPColor(7, 0); // 플레이어 7 색 변경 sys.SetPColor(7, 0) # (Line 17) sys.SetPColor(8, 196); // 플레이어 8 색 변경 sys.SetPColor(8, 196) # (Line 18) sys.RegisterMSQC(); // MSQC 변수 sys.RegisterMSQC() # (Line 19) sys.SinglePlayCheck(); // 싱글플레이 체크 sys.SinglePlayCheck() # (Line 20) sys.SetAlly(); // 동맹 설정 sys.SetAlly() # (Line 21) npc.CreateNPC(); // NPC 유닛 생성 npc.CreateNPC() # (Line 22) item.SetItemInfo(); // 아이템 정보 입력 item.SetItemInfo() # (Line 24) foreach (cp : EUDLoopPlayer()) { for cp in EUDLoopPlayer(): # (Line 25) setcurpl(cp); f_setcurpl(cp) # (Line 26) inven.ResetInven(); // 인벤토리 초기화 inven.ResetInven() # (Line 27) sys.SetName(); // 유닛 이름 변경 sys.SetName() # (Line 28) screen.light[cp] = 31; // 밝기 최대로 변경 _ARRW(screen.light, cp) << (31) # (Line 29) statusBar.stats[cp] = statusBar.USER_STATUS; // 상태바 기본값으로 설정 _ARRW(statusBar.stats, cp) << (statusBar.USER_STATUS) # (Line 30) char.NewCharacter(); // 캐릭터 생성 (임시) char.NewCharacter() # (Line 33) item.AddItem(10000, 1, 1, 10, true); item.AddItem(10000, 1, 1, 10, True) # (Line 34) item.AddItem(10000, 1, 2, 10, true); item.AddItem(10000, 1, 2, 10, True)
def __init__(self, size, position, maxRotVel, maxRotAcc, a): NPC.__init__(self, size, position, maxRotVel, maxRotAcc, a) self.origImage = pygame.image.load('data/Predator.png') self.dieImg = [pygame.image.load('data/Predator 01.png'), pygame.image.load('data/Predator 02.png'), pygame.image.load('data/Predator 03.png'), pygame.image.load('data/Predator 04.png'), pygame.image.load('data/Predator 05.png'), pygame.image.load('data/Predator 06.png'), pygame.image.load('data/Predator 07.png'), pygame.image.load('data/Predator 08.png'), pygame.image.load('data/Predator 09.png')] self.dieLvl = 0 self.image = self.origImage self.name = 'Predator' self.lifeSpan = 10000 self.birth = time.time() self.rotate = 0.0 self.radius = self.image.get_rect().width/2 self.chaseDist = 200
def __init__(self, Im_black_piece, Im_black_crown, Im_red_piece, Im_red_crown): self.turn = 1 self.turnNoKill = 0 self.BLACK_TEAM = "black" self.RED_TEAM = "red" self.board = [] self.sequenceKill = False #Instancing each piece self.blackOnes = [] self.redOnes = [] #Making players self.npc = NPC(self.board, self.blackOnes) self.user = User(self.board, self.redOnes) self.images = [ Im_black_piece, Im_black_crown, Im_red_piece, Im_red_crown ]
def __init__(self): self.enemies = [] self.events = [ Event("Start"), Event("Forest"), Event("Clean Garden"), Event("Get Crown") ] self.events += [ Event("Mountain"), Event("Ocean"), Event("Goblin King") ] self.locations = ["start", "desert"] self.person = [] self.Done = True self.King = King() self.Gardener = NPC("Gardener") self.Blacksmith = NPC("Blacksmith") self.Worker = NPC("Worker") self.ChatBot = NPC("ChatBot")
def update(self, dT): self.collide() #slow die cImg = self.origImage if time.time() - self.birth > Variables.PredatorLS: if self.dieLvl == len(self.dieImg)-1: self.iDied = 1 else: self.dieLvl += 1 cImg = self.dieImg[self.dieLvl] NPC.update(self, dT) old = Vect2(self.image.get_rect().center) rot_image = pygame.transform.rotate(cImg, self.rotate) self.image = rot_image new = Vect2(rot_image.get_rect().center) self.pos = self.pos-(new-old) self.rotate += 7.5 if self.rotate >= 345: self.rotate = 0 #begin death animation x =1 if not self.grabbedBy: NPC.update(self, dT) old = Vect2(self.image.get_rect().center) rot_image = pygame.transform.rotate(cImg, self.rotate) self.image = rot_image new = Vect2(rot_image.get_rect().center) self.pos = self.pos-(new-old) else: self.pos = self.grabbedBy.pos
def enter(): global hero, npc, end, map, cnt, level_of_difficulty, current_time current_time = time.time() level_of_difficulty = 25 map = Map() cnt = Count() hero = Hero() npc = [[NPC() for i in range(4)] for i in range(7)] start_positon = 2 end = False initialize_NPC(start_positon) # 빈칸 생성 game_world.add_object(hero, COLUMN_MAX) game_world.add_object(map, 0) game_world.add_object(cnt, 0)
def __init__(self, Im_black_piece, Im_black_crown, Im_red_piece, Im_red_crown): self.turn = 1 self.turnNoKill = 0 self.BLACK_TEAM = "black" self.RED_TEAM = "red" self.board = [] self.sequenceKill = False #Instancing each piece self.blackOnes = [] self.redOnes = [] #Making players self.npc = NPC(self.board, self.blackOnes) self.user = User(self.board, self.redOnes) self.images = [Im_black_piece, Im_black_crown, Im_red_piece, Im_red_crown]
def __init__(self, hero): print("\n" + hero.char.name + " currently has " + str(hero.char.money) + " gold.") print("The shopkeeper greets you") input() shopkeep = NPC(weapon_pile().get_random_weapon()) shopper_choice = input("Are you buying or selling?: ") if "B" in str(shopper_choice).upper(): self.buying_menu(hero) if "S" in str(shopper_choice).upper(): self.sellingMenu(hero) if "K" in str(shopper_choice).upper() or "A" in str( shopper_choice).upper(): print("\nYou lunge at the " + shopkeep.Name + " with your " + shopkeep.Weapon.name + "!\n") Battle(hero, shopkeep)
# Set player statistcs. firstPlayer = currentPlayer if currentPlayer == userColor: firstPlayer = userName firstColor = userColor secondPlayer = "NPC" secondColor = npcColor else: firstPlayer = "NPC" firstColor = npcColor secondPlayer = userName secondColor = userColor # Instantiations myBoard = Board(currentPlayer) npc = NPC(npcColor, 3) prompt = "> " winner = None movesMade = [] print myBoard # Game loop while (myBoard.blackCount + myBoard.whiteCount) < 36: outputFile.write("{}\n{}\n".format(firstPlayer, secondPlayer)) outputFile.write("{}\n{}\n".format(firstColor.upper(), secondColor).upper()) if currentPlayer == firstColor: outputFile.write("1\n") else: outputFile.write("2\n")
def play_game(self): """ Does the work of putting rooms in the game, laying out the map and progression """ # def __init__(self, name, desc, n_exit, e_exit, s_exit, w_exit, special_command) for a Room # def __init__(self, name, desc, n_exit, e_exit, s_exit, w_exit, special_command, puzzle_number) for a puzzle Room # def __init__(self, name, desc, n_exit, e_exit, s_exit, w_exit, special_command, npc_character) for a room with a NPC start_room = Room("Forest Clearing", "You're in a warmly lit area surrounded by trees. ", None, None, None, None, False) tree_with_branch = RoomWithPuzzle( "Bushy Tree", "A well grown tree inhabits this part of the woods. One of its branches seems to have fallen to the ground.", None, None, None, None, True, 1) hiker_area = RoomWithNPC( "Someone's Campsite", "A well cleaned tent area occupies the south part of the area.\nA lone, burly man is sitting on a chair, reading a book called \'Bear Survival\'.", None, None, None, None, True, None) hiker_tent = RoomWithPuzzle( "Hiker's Tent", "You immediatly regret your decision on coming here. Filtering out the weird stuff, you notice a flashlight in the corner of the room", None, None, None, None, True, 9) crash_site = RoomWithPuzzle( "Car Crash Site", "A used to be fancy car sits dejectely, smoke and oil leaking out of it. You recalled that this was your sweet ride! To your dismay, the car seems to be sealed shut...maybe if you had some sort of leverage to pull it open?", None, None, None, None, True, 2) thick_brush = RoomWithPuzzle( "Thorny Path", "A thick, spiky overgrowth blocks the east path. There's no other way around it.", None, None, None, None, True, 3) open_field = Room("Forest Entrance", "A vast field of grass occupies this space.", None, None, None, None, False) bear_den = RoomWithPuzzle( "Grizzly Bear's Den", "A wretched stench greets you as you see a huge grizzly bear sleeping on a leafy patch. There seems to be something gleaming past it though...", None, None, None, None, True, 4) hill_shack = RoomWithPuzzle( "Hill's Foot", "The old shack looms at the top of the hill. It might be a good idea to investigate it...to the south you see a shriveld old man sitting on a stump.", None, None, None, None, True, 5) shack_patio = RoomWithNPC( "Sunny Stump", "Upon coming here, the old man seems to be looking at his oddly out of place smartphone.", None, None, None, None, True, None) river_area = RoomWithPuzzle( "Raging River", "A river stands between you and a dark cave. To the east is a lone, young man sitting on a towel. The river is extrememy fast...", None, None, None, None, True, 6) picnic_area = RoomWithNPC( "Sunny Spot", "The man appears to be in some sort of weird trance. He looks friendly though. Too friendly maybe.", None, None, None, None, True, None) dark_cave = RoomWithPuzzle( "Dark Cave Entrance", "There's little light in here to see anything. It might be wise to not go in blindly...", None, None, None, None, True, 7) golden_door = RoomWithPuzzle( "Gold Door", "After traveling a while, a huge golden door sits in front of you. It reads: \'ENTER PASSWORD\'", None, None, None, None, True, 8) # def __init__(self, name, talk_d, attack_d, fatal) for a NPC npc_1 = NPC( "Hiker Joe", "Ahoy, mate! You're looking pretty beaten up! I would help you, but I'm in the middle of bear watching! These woods are filled with them!\nIf you ever see one, sleeping or not, the best thing to do is to SNEAK by them! Trust me.\nHey, if you want some grub, I have some stuff in my tent! Just don't make a bear mess in there! Haha!", "WOAH! What you think you're doing?! You're lucky you're not a bear, since I would immediatly beat your ass up!", False) npc_2 = NPC( "Hermit Bill", "Hm? What brings you here, sonny? I rarely get visitors around here ever since the bear incident. You look like you want to access the Internet don't you?\nI know you young ones...always wanting to get the Internet without anyone's permission! Well, since you look desperate, I'll let you use mine.\nThe password is 1234567890...oh you're phone's dead? Sucker!", "SON. I'll have you know that I am a secret agent working here to kill anyone that tries to attack me in hopes to get my wifi.\nAnd you done f****d up.", True) npc_3 = NPC( "High Hugo", "Sup dude? You look like you've been to some shit rave...man...times like this is when you just need to relax and drink some good 231.\nWhat's 231? Dude, that's the bro code for having a good time and when you need a easy solution to something. Remember it well. You'll thank me later.", "ASDFGHJJ TIME TO ACTIVATE BRO TIME! GET REKED!", True) # def __init__(self, path_destination, is_locked) for a Path path1_n = Path(thick_brush, False) path1_s = Path(tree_with_branch, False) path1_e = Path(hiker_area, False) path1_w = Path(crash_site, False) path2_n = Path(start_room, False) path3_w = Path(start_room, False) path3_s = Path(hiker_tent, False) path4_n = Path(hiker_area, False) path5_e = Path(start_room, False) path6_s = Path(start_room, False) path6_e = Path(open_field, True) path7_n = Path(bear_den, False) path7_e = Path(hill_shack, False) path7_s = Path(river_area, False) path7_w = Path(thick_brush, False) path8_w = Path(open_field, False) path9_w = Path(open_field, False) path9_s = Path(shack_patio, False) path10_w = Path(hill_shack, False) path11_e = Path(picnic_area, False) path11_s = Path(dark_cave, True) path11_n = Path(open_field, False) path12_n = Path(river_area, False) path12_s = Path(golden_door, True) path13_n = Path(dark_cave, False) start_room.set_exits(path1_n, path1_s, path1_e, path1_w) tree_with_branch.set_exits(path2_n, None, None, None) hiker_area.set_exits(None, path3_s, None, path3_w) hiker_tent.set_exits(path4_n, None, None, None) crash_site.set_exits(None, None, path5_e, None) thick_brush.set_exits(None, path6_s, path6_e, None) open_field.set_exits(path7_n, path7_s, path7_e, path7_w) bear_den.set_exits(None, None, None, path8_w) hill_shack.set_exits(None, path9_s, None, path9_w) shack_patio.set_exits(None, None, None, path10_w) river_area.set_exits(path11_n, path11_s, path11_e, None) dark_cave.set_exits(path12_n, path12_s, None, None) golden_door.set_exits(path13_n, None, None, None) hiker_area.npc_character = npc_1 shack_patio.npc_character = npc_2 picnic_area.npc_character = npc_3 print "You were enjoying a lovely evening on your hot date when suddenly, you forgot to use yout turn signal and ran into another car that was passing by!" print "You would have been fine if you weren't on a mountain, but you were and now your car was in a wreck and your date missing!" print "It's your goal now to salvage what you can find and get out of here!" self.set_room(start_room) while self.player.clear_game == False: print "\n" self.current_room.examine_room() self.command_parser()
from NPC import NPC, DialogNode arry_npc = NPC("'Arry") arry_dialog_0 = DialogNode("Anything else?") arry_dialog_1 = DialogNode("Hey there mate, how can I help?", arry_dialog_0) arry_dialog_2 = DialogNode( "Well, I moved here when my ol Dorris passed, oh that must of been 7 years back? I couldn't stay in Noamsted, too many memories." ) arry_dialog_3 = DialogNode("Used to be quite nice... used to be", arry_dialog_0) arry_dialog_4 = DialogNode( "Well, I myself like to fish, not very good at it but helps pass the time." ) arry_dialog_5 = DialogNode( "Ha Ha Ha Ha, well I definitely wouldn't know anything about that. Im all legit, 100% all import export... uh fish that is." ) arry_dialog_6 = DialogNode( "Despite my appearance, I used to live a very different life. If I had realised Dorris would be caught up in it, I would have moved a long time ago.", arry_dialog_0) arry_dialog_0.responses = [[ "How long have you lived here for?", arry_dialog_2 ], ["What do you do around here?", arry_dialog_4]] arry_dialog_2.responses = [["How did you like Noamsted?", arry_dialog_3], [ "Im sorry to hear that, how did she pass?", arry_dialog_6 ]] arry_dialog_4.responses = [[
# Set player statistcs. firstPlayer = currentPlayer if currentPlayer == userColor: firstPlayer = userName firstColor = userColor secondPlayer = "NPC" secondColor = npcColor else: firstPlayer = "NPC" firstColor = npcColor secondPlayer = userName secondColor = userColor # Instantiations myBoard = Board(currentPlayer) npc = NPC(npcColor, 3) prompt = "> " winner = None movesMade = [] print myBoard # Game loop while (myBoard.blackCount + myBoard.whiteCount) < 36: outputFile.write("{}\n{}\n".format(firstPlayer, secondPlayer)) outputFile.write("{}\n{}\n".format(firstColor.upper(), secondColor).upper()) if currentPlayer == firstColor: outputFile.write("1\n") else: outputFile.write("2\n") outputFile.write("{}\n".format(myBoard.getSnapshot()))
def createHouse(self): arrNPCs = [NPC() for i in range(self.population)] print("Creating a house with", len(arrNPCs), "monsters.")
def get_location(id): # TODO AAA start = [NPC('start', '1')] return Location(start, 'История первая: "Прототип движения по диалогам"')
if 'type' in i: type = i['type'] if 'health' in i: health = i['health'] if 'attack' in i: attack = i['attack'] if 'xp' in i: xp = i['xp'] if 'serial' in i: serial = i['serial'] #we'll do text but i got to ask the coop ;) #till then we're loading in sample texts if 'file_loc' in i: file = i['file_loc'] npc_list.append(NPC(x, y, type, health, attack, xp, a, file, serial)) '''Things that the MAP objects take in and are used for loading in from sprite sheet''' for i in map_set: if 'x' in i: x = i['x'] if 'y' in i: y = i['y'] if 'type' in i: type = i['type'] if 'file_x' in i: file_x = i['file_x'] if 'file_y' in i: file_y = i['file_y'] if 'width' in i: width = i['width'] if 'height' in i:
class Board: #Constructor def __init__(self, Im_black_piece, Im_black_crown, Im_red_piece, Im_red_crown): self.turn = 1 self.turnNoKill = 0 self.BLACK_TEAM = "black" self.RED_TEAM = "red" self.board = [] self.sequenceKill = False #Instancing each piece self.blackOnes = [] self.redOnes = [] #Making players self.npc = NPC(self.board, self.blackOnes) self.user = User(self.board, self.redOnes) self.images = [ Im_black_piece, Im_black_crown, Im_red_piece, Im_red_crown ] #Reset the board to the default state def resetBoard(self): for i in range(0, 12): self.blackOnes.append( SimplePiece(self.images[0], 1, self.BLACK_TEAM)) self.redOnes.append(SimplePiece(self.images[2], -1, self.RED_TEAM)) #making my matrix's board self.board = [[ None, self.blackOnes[0], None, self.blackOnes[1], None, self.blackOnes[2], None, self.blackOnes[3] ], [ self.blackOnes[4], None, self.blackOnes[5], None, self.blackOnes[6], None, self.blackOnes[7], None ], [ None, self.blackOnes[8], None, self.blackOnes[9], None, self.blackOnes[10], None, self.blackOnes[11] ], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [ self.redOnes[0], None, self.redOnes[1], None, self.redOnes[2], None, self.redOnes[3], None ], [ None, self.redOnes[4], None, self.redOnes[5], None, self.redOnes[6], None, self.redOnes[7] ], [ self.redOnes[8], None, self.redOnes[9], None, self.redOnes[10], None, self.redOnes[11], None ]] ''' self.board = [[None, self.blackOnes[0], None, self.blackOnes[1], None, self.blackOnes[2], None, self.blackOnes[3]], [self.blackOnes[4], None, self.blackOnes[5], None, self.blackOnes[6], None, self.blackOnes[7], None], [None, self.blackOnes[8], None, self.blackOnes[9], None, self.blackOnes[10], None, self.blackOnes[11]], [None, None, self.redOnes[0], None, None, None, None, None], [None, None, None, None, None, self.redOnes[5], None, self.redOnes[6]], [None, None, self.redOnes[1], None, self.redOnes[2], None, self.redOnes[3], None], [None, self.redOnes[4], None, None, None, None, None, self.redOnes[7]], [self.redOnes[8], None, self.redOnes[9], None, self.redOnes[10], None, self.redOnes[11], None]] ''' self.npc.board = self.board self.user.board = self.board #Set their positions for i in range(0, 8): for j in range(0, 8): if self.board[i][j] != None: self.board[i][j].setPosition(i, j) #Make the npc play def NPCTime(self): #print ("Size of the lists:\n black: %d\n red: %d) % (len(self.blackOnes), len(self.redOnes)) #get best path and if had some kill; hasKill, path = self.npc.play(self.getState(), self.board) #If hasn't any move to do if len(path) == 0: self.blackOnes = [] return pygame.time.wait(1000) #wait 1 sec #kill and sequence kill. if hasKill: while len(path) >= 2: self.board[path[0][0]][path[0][1]].makeKill( path[1], self.redOnes, self.board) del path[0] self.turnNoKill = 0 #moving else: self.board[path[0][0]][path[0][1]].makeMove(path[1], self.board) del path[0] self.turnNoKill += 1 self.turn += 1 self.crown(path[0][0], path[0][1]) #Let the user play def userTime(self, clickedLine, clickedCollum): # See if has any movement to do. hasMovements = False for piece in self.user.piecesVector: if len(piece.canKill(self.board)) > 0: hasMovements = True break elif len(piece.canMove(self.board)) > 0: hasMovements = True break if not hasMovements: self.user.piecesVector = [] return #clicked on his own piece if self.isRedTeam(self.board[clickedLine] [clickedCollum]) and not self.sequenceKill: self.user.setSelected(clickedLine, clickedCollum) #clicked on a empty space elif self.board[clickedLine][ clickedCollum] == None and self.user.selected != None: #See if the selected destination is to walk. if (clickedLine, clickedCollum) in self.user.movesOfSelectedToWalk: self.turnNoKill += 1 #See if the selected destination is to eat. elif (clickedLine, clickedCollum) in self.user.movesOfSelectedToKill: self.turnNoKill = 0 else: return self.user.play(clickedLine, clickedCollum, self.blackOnes) self.user.setSelected(clickedLine, clickedCollum) #See if the player can kill another piece if len(self.user.movesOfSelectedToKill ) > 0 and self.turnNoKill == 0: self.sequenceKill = True else: self.turn += 1 self.crown(clickedLine, clickedCollum) self.sequenceKill = False self.user.deselect() #Winner's conditions def winConditions(self): if len(self.redOnes) == 0: return 1 elif len(self.blackOnes) == 0: return 2 elif self.turnNoKill >= 20: return 3 else: return 0 #The piece is a red one? def isRedTeam(self, somePiece): if somePiece != None and somePiece.team == self.RED_TEAM: return True return False #The piece is a black one? def isBlackTeam(self, somePiece): if somePiece != None and somePiece.team == self.BLACK_TEAM: return True return False #That piece on the board should be crown? def crown(self, line, collum): if isinstance(self.board[line][collum], SimplePiece): if line == 7 and self.board[line][collum].team == self.BLACK_TEAM: index = self.npc.findPiece(line, collum) self.blackOnes[index] = CrownPiece(self.images[1], self.BLACK_TEAM) self.board[line][collum] = self.blackOnes[index] elif line == 0 and self.board[line][collum].team == self.RED_TEAM: index = self.user.findPiece(line, collum) self.redOnes[index] = CrownPiece(self.images[3], self.RED_TEAM) self.board[line][collum] = self.redOnes[index] self.board[line][collum].setPosition(line, collum) #Get the board def getState(self): state = "" for i in range(0, 8): for j in range(0, 8): p = self.board[i][j] if isinstance(p, Piece): if isinstance(p, SimplePiece): if p.team == self.RED_TEAM: state = state + "r " elif p.team == self.BLACK_TEAM: state = state + "b " elif isinstance(p, CrownPiece): if p.team == self.RED_TEAM: state = state + "R " elif p.team == self.BLACK_TEAM: state = state + "B " else: state = state + "# " return state
def enter_building(self, build_type, player_id, location_id): npcInst = NPC() print("You enter the {}\n".format(build_type)) npcInst.create_npc(player_id, build_type, location_id)
class Board: #Constructor def __init__(self, Im_black_piece, Im_black_crown, Im_red_piece, Im_red_crown): self.turn = 1 self.turnNoKill = 0 self.BLACK_TEAM = "black" self.RED_TEAM = "red" self.board = [] self.sequenceKill = False #Instancing each piece self.blackOnes = [] self.redOnes = [] #Making players self.npc = NPC(self.board, self.blackOnes) self.user = User(self.board, self.redOnes) self.images = [Im_black_piece, Im_black_crown, Im_red_piece, Im_red_crown] #Reset the board to the default state def resetBoard(self): for i in range(0, 12): self.blackOnes.append( SimplePiece(self.images[0], 1, self.BLACK_TEAM) ) self.redOnes.append( SimplePiece(self.images[2], -1, self.RED_TEAM) ) #making my matrix's board self.board = [[None, self.blackOnes[0], None, self.blackOnes[1], None, self.blackOnes[2], None, self.blackOnes[3]], [self.blackOnes[4], None, self.blackOnes[5], None, self.blackOnes[6], None, self.blackOnes[7], None], [None, self.blackOnes[8], None, self.blackOnes[9], None, self.blackOnes[10], None, self.blackOnes[11]], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [self.redOnes[0], None, self.redOnes[1], None, self.redOnes[2], None, self.redOnes[3], None], [None, self.redOnes[4], None, self.redOnes[5], None, self.redOnes[6], None, self.redOnes[7]], [self.redOnes[8], None, self.redOnes[9], None, self.redOnes[10], None, self.redOnes[11], None]] ''' self.board = [[None, self.blackOnes[0], None, self.blackOnes[1], None, self.blackOnes[2], None, self.blackOnes[3]], [self.blackOnes[4], None, self.blackOnes[5], None, self.blackOnes[6], None, self.blackOnes[7], None], [None, self.blackOnes[8], None, self.blackOnes[9], None, self.blackOnes[10], None, self.blackOnes[11]], [None, None, self.redOnes[0], None, None, None, None, None], [None, None, None, None, None, self.redOnes[5], None, self.redOnes[6]], [None, None, self.redOnes[1], None, self.redOnes[2], None, self.redOnes[3], None], [None, self.redOnes[4], None, None, None, None, None, self.redOnes[7]], [self.redOnes[8], None, self.redOnes[9], None, self.redOnes[10], None, self.redOnes[11], None]] ''' self.npc.board = self.board self.user.board = self.board #Set their positions for i in range(0, 8): for j in range(0, 8): if self.board[i][j] != None: self.board[i][j].setPosition(i, j) #Make the npc play def NPCTime(self): #print ("Size of the lists:\n black: %d\n red: %d) % (len(self.blackOnes), len(self.redOnes)) #get best path and if had some kill; hasKill, path = self.npc.play(self.getState(), self.board) #If hasn't any move to do if len(path) == 0: self.blackOnes = []; return; pygame.time.wait(1000) #wait 1 sec #kill and sequence kill. if hasKill: while len(path) >= 2: self.board[path[0][0]][path[0][1]].makeKill(path[1], self.redOnes, self.board) del path[0] self.turnNoKill = 0 #moving else: self.board[path[0][0]][path[0][1]].makeMove(path[1], self.board) del path[0] self.turnNoKill += 1 self.turn += 1 self.crown(path[0][0], path[0][1]) #Let the user play def userTime(self, clickedLine, clickedCollum): # See if has any movement to do. hasMovements = False for piece in self.user.piecesVector: if len( piece.canKill(self.board) ) > 0: hasMovements = True break elif len( piece.canMove(self.board) ) > 0: hasMovements = True break if not hasMovements: self.user.piecesVector = [] return #clicked on his own piece if self.isRedTeam(self.board[clickedLine][clickedCollum]) and not self.sequenceKill: self.user.setSelected(clickedLine, clickedCollum) #clicked on a empty space elif self.board[clickedLine][clickedCollum] == None and self.user.selected != None: #See if the selected destination is to walk. if (clickedLine, clickedCollum) in self.user.movesOfSelectedToWalk: self.turnNoKill +=1 #See if the selected destination is to eat. elif (clickedLine, clickedCollum) in self.user.movesOfSelectedToKill: self.turnNoKill = 0 else: return; self.user.play(clickedLine, clickedCollum, self.blackOnes) self.user.setSelected(clickedLine, clickedCollum) #See if the player can kill another piece if len(self.user.movesOfSelectedToKill) > 0 and self.turnNoKill == 0: self.sequenceKill = True else: self.turn += 1 self.crown(clickedLine, clickedCollum) self.sequenceKill = False self.user.deselect() #Winner's conditions def winConditions(self): if len(self.redOnes) == 0: return 1 elif len(self.blackOnes) == 0: return 2 elif self.turnNoKill >= 20: return 3 else: return 0 #The piece is a red one? def isRedTeam(self, somePiece): if somePiece != None and somePiece.team == self.RED_TEAM: return True return False #The piece is a black one? def isBlackTeam(self, somePiece): if somePiece != None and somePiece.team == self.BLACK_TEAM: return True return False #That piece on the board should be crown? def crown(self, line, collum): if isinstance(self.board[line][collum], SimplePiece): if line == 7 and self.board[line][collum].team == self.BLACK_TEAM: index = self.npc.findPiece(line, collum) self.blackOnes[index] = CrownPiece(self.images[1], self.BLACK_TEAM) self.board[line][collum] = self.blackOnes[index] elif line == 0 and self.board[line][collum].team == self.RED_TEAM: index = self.user.findPiece(line, collum) self.redOnes[index] = CrownPiece(self.images[3], self.RED_TEAM) self.board[line][collum] = self.redOnes[index] self.board[line][collum].setPosition(line, collum) #Get the board def getState(self): state = "" for i in range(0, 8): for j in range(0, 8): p = self.board[i][j] if isinstance(p, Piece): if isinstance(p, SimplePiece): if p.team == self.RED_TEAM: state = state + "r " elif p.team == self.BLACK_TEAM: state = state + "b " elif isinstance(p, CrownPiece): if p.team == self.RED_TEAM: state = state + "R " elif p.team == self.BLACK_TEAM: state = state + "B " else: state = state + "# " return state
def createRooms(self): #Salas sala = Room("sala") comedor = Room("comedor") cocina = Room("cocina") lavadero = Room("lavadero") jardin = Room("jardin") pasillo = Room("pasillo") dormitorio = Room("dormitorio") baño = Room("baño") balcon = Room("balcon") #Definimos las salas cerradas garaje = lockedRoom("garaje") #Definimos salidas garaje.setExit('east', sala) sala.setExit('north', comedor) sala.setExit('east', pasillo) sala.setExit('west', garaje) comedor.setExit('north', lavadero) comedor.setExit('east', cocina) comedor.setExit('south', sala) cocina.setExit('north', jardin) cocina.setExit('west', comedor) lavadero.setExit('south', comedor) jardin.setExit('south', cocina) pasillo.setExit('up', dormitorio) pasillo.setExit('west', sala) dormitorio.setExit('north', baño) dormitorio.setExit('east', balcon) dormitorio.setExit('down', pasillo) baño.setExit('south', dormitorio) balcon.setExit('west', dormitorio) #Definimos items lampara = Item('lampara', 'Una lámpara rota', 2) botella = Item('botella', 'Una botella vacía', 3) zapato = Item('zapato', 'Un zapato', 1.5) heladera = Item('heladera', 'Una heladera', 8) lavarropas = Item('lavarropas', 'Lavarropas', 10) tender = Item('tender', 'Un tender con ropa', 6) muñeco = Item('muñeco', 'Un muñeco de trapo', 3) cuadro = Item('cuadro', 'Un cuadro', 2) banco = Item('banco', 'Un banco', 4) mesa = Item('mesa', 'Una mesa de madera', 6) espejo = Item('espejo', 'Un espejo', 3) computadora = Item('computadora', 'Una computadora de escritorio', 6) cama = Item('cama', 'Una cama', 7) linterna = Item('linterna', 'Una linterna', 1) #Definimos items comestibles con sus respectivas propiedades. manzana = Comestible('manzana', 'Una manzana ordinaria', 1, 0, None) galleta = Comestible('galleta', 'Una galleta mágica', 2, 2, 'weight') #Definimos items utilizables, con su respectiva función. key = Usable('llave', 'Llave maestra', 1, 'key') beamer = Usable('portalgun', 'Arma de portales', 3, 'teleport') #Definimos cofres magic_box = Chest('Cofre', 'Magico cofre con muchos tesoros dentro', 1000, [manzana, galleta, espejo]) #Añadiendo items a las distintas salas. comedor.addItem(zapato) sala.addItem(linterna) sala.addItem(lampara) cocina.addItem(botella) cocina.addItem(heladera) lavadero.addItem(lavarropas) jardin.addItem(tender) jardin.addItem(muñeco) pasillo.addItem(cuadro) balcon.addItem(banco) balcon.addItem(mesa) baño.addItem(espejo) dormitorio.addItem(cama) dormitorio.addItem(galleta) dormitorio.addItem(computadora) sala.addItem(manzana) sala.addItem(beamer) sala.addItem(key) sala.addItem(magic_box) #Definimos misiones mision1 = Mission('1ra mision', 'Llegar al dormitorio en menos de 10 movimientos', 10, 'checkpoint', 'dormitorio') #Definiendo NPC mago = NPC('Mago', sala, 'Traeme un arma de portales y te devolveré una galleta', beamer, galleta) aprendiz = NPC( 'Aprendiz', cocina, 'Bienvenido a Zuul, revisa toda la casa para encontrar objetos importantes' ) #Agregandolo a la sala sala.addNPC(mago) cocina.addNPC(aprendiz) #Definiendo jugador self.player = Player('Peter', None, 0) self.player.addMission(mision1) #Definiendo sala self.currentRoom = sala self.player.setActualRoom(self.currentRoom) return
from NPC import NPC from player import player player1 = player({}) NPC1 = NPC('阿尔萨斯', ' 使用霜之哀伤的怒火攻击敌人', '1') NPC2 = NPC('吉安娜', ' 使用奥数法术攻击敌人', '2') NPC3 = NPC('乌塞尔', ' 使用圣光的力量治愈盟友', '3') while True: NPC.show() player1.showdangqian() c = input('请选择你要继续的操作:' '1. 邀请组队 ' '2. 踢出队伍 ' '0. 完成 \n' '') if c == '1': b = input('请选择可选NPC中要组队的NPC的ID\n') if b == '1': player1.addNPC(b) if b == '2': player1.addNPC(b) if b == '3': player1.addNPC(b) if c == '2': b = input('请选择可选NPC中要踢出的NPC的ID\n') if b == '1': player1.removeNPC(b) if b == '2': player1.removeNPC(b) if b == '3': player1.removeNPC(b) if c == '0': break