def defaultaccounts(): ##### # USER ACCOUNT hub.accounts = account.accountmanager() hub.accounts.add("cholo", "cholo") print "User accounts = %d" % hub.accounts.count() testaccount = hub.accounts.dologin("cholo", "cholo") testaccount.data["characterfile"] = "cholo.dat" hub.accounts.add("j", "j") testaccount2 = hub.accounts.dologin("j", "j") testaccount2.data["characterfile"] = "john.dat" hub.accounts.save() ##### # CHARACTERS newcharacter = character.character(testaccount, "Cholo") newcharacter.setattribute("maxhp", 12) newcharacter.setattribute("hp", 12) newcharacter.save() newchar2 = character.character(testaccount2, "John") newchar2.setattribute("maxhp", 12) newchar2.setattribute("hp", 12) newchar2.save()
def __init__(self, width=610, height=610): pygame.init() hr = 48 print(" " + "-" * hr + " ") print("|" + " " * 15 + "Welcome to aiRPG" + " " * 15 + " |") print("|" + " COS30002-Artificial Intelligence for Games" + " |") print("|" + " " * 17 + "Created By " + " " * 17 + " |") print("|" + " " * 10 + "Kaelob Smythe ( 100597078 ) " + " " * 7 + " | ") print(" " + "-" * hr + " ") self.width, self.height = width, height self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((self.width, self.height)) self.done = False pygame.display.set_caption("aiRPG") ## Create the Hero, and set variables for GOAP self.hero = character(0, 9) self.hero.setHP(20) self.hero.setDamage(4) self.hero.setHeal(10) ## Create the Enemy, and set variables for GOAP self.enemy = character(9, 3) self.enemy.setHP(20) self.enemy.setDamage(6) self.enemy.setHeal(6) self.grid = Grid_World(self)
def __init__(self): self.name = '' self.pokemon = [character(), character(), character(), character()] self.hasWon = False self.currentPokemon = 0 self.recentMove = 0 self.ID = None self.pokemonLeft = 4 self.lockMove = False self.switchPokemon = 0
def enter(): global player, grass global enemy1, mop global boss player = character() grass = Grass() boss = Boss()
def enter(): global player,grass global enemy1,mop player = character() grass = Grass() enemy1 = Enemy() mop = [Enemy() for i in range(5)]
def LoadChars(chars = {}, whitelist = {}, txtPath = lists, jsonPath = persists) : # { 'name' : obj } # 1. Get list of API keys # 2. For each key, query all characters on account # 3. For each character, check if it's whitelisted # 4. For each whitelisted character, create a character object and add to the list # 5. Return said list charlist = [] urllib.request.urlretrieve(vars.keycsv, vars.lists + vars.keyfile) if keyfile in os.listdir(txtPath) : # Loads text file database, if it exists with open(vars.lists + vars.keyfile, 'r') as file : # Note: Specific parsing required per deployment! keys = file.read().splitlines() for key in keys[1:] : try: if len(key) > 4 : # any number greater than the minimum number of commas in a blank field (',,,,') s = key.split(',') # .csv format keyID = s[2] vCode = s[3] root = GetRoot('{}?keyID={}&vCode={}'.format(vars.apikeyinfoURL, keyID, vCode), '/xml/APIKeyInfo.xml') if len(root.attrib) and root[1].tag != 'error' : for row in root[1][0][0] : if (row.get('factionID') in whitelist) or row.get('characterName') not in charlist : if (row.get('factionID') in whitelist) or (row.get('allianceID') in whitelist) or (row.get('corporationID') in whitelist) or (row.get('characterID') in whitelist) : newchar = char.character(s, row) chars[newchar.charName] = newchar #chars.append(char.character(s, row)) charlist.append(row.get('characterName')) finally : pass return chars
def enter(): global stage,mop,State stage = Stage() global player global enemy1 global bullet global Monbullet global midbullet global Bossbullet global Bossbullet2 global Bossbullet3 global boss global middle bullet = [] Monbullet = [] midbullet = [] Bossbullet = [] Bossbullet2 = [] Bossbullet3 = [] player = character() #enemy1 = Enemy() mop = [Enemy(100+(75*i), 700) for i in range(6)] boss = [Enemy2(250, 1000) for j in range(1)] middle = [middleboss(150 + (200 * k),800) for k in range(2)]
def enter(): global stage, mop, State stage = Stage() global player global enemy1 global bullet global Monbullet global midbullet global Bossbullet global Bossbullet2 global Bossbullet3 global boss global middle global upbullet global Upgrade global Chance global bgm global missilesound, explosionsound, itemsound global Attack missilesound = None explosionsound = None itemsound = None bullet = [] upbullet = [] Monbullet = [] midbullet = [] Bossbullet = [] Bossbullet2 = [] Bossbullet3 = [] Attack = [] player = character() # enemy1 = Enemy() # bgm = load_music("resource/stage.mp3") # #start_state.bgm.resume() # bgm.set_volume(64) # bgm.repeat_play() mop = [Enemy(100 + (75 * i), 700) for i in range(6)] boss = [Enemy2(250, 1000) for j in range(1)] middle = [middleboss(150 + (200 * k), 800) for k in range(2)] Chance = [Upgrade2(75 - (l * 50), 20) for l in range(2)] bgm = load_music("resource/stage.mp3") Upgrade = [Upgrade1(100 + (j * 100), 100 + (j * 100)) for j in range(2)] bgm.set_volume(64) bgm.repeat_play() if missilesound == None: missilesound = load_wav("resource/missile.wav") missilesound.set_volume(50) if itemsound == None: itemsound = load_wav("resource/missile up.wav") itemsound.set_volume(50) if explosionsound == None: explosionsound = load_wav("resource/explo.wav") explosionsound.set_volume(50)
def testParalysis(self): char_one = character.character() char_one.resist = self.t_resist char_one.logic_table["paralysis"] = lambda a, b, : logic.paralysis( a, b) #Test : make sure that paralysis doesn't happen. t1 = lambda: .51 #Test : make sure that paralysis does happen. t2 = lambda: .49 #Test : make sure resistances work. #Test : make sure that paralysis doesn't stack. #Test : make sure it does stack. t3 = lambda: .24 t4 = lambda: .12 #Test : make sure the maximum value is five. #Test : Make sure that it decrements to zero. #Test : Make sure paralysis will remove itself from the character's effect table. logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t1, self.t_mag, self.t_duration) self.assertNotIn("paralysis", char_one.etable) logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t2, self.t_mag, self.t_duration) self.assertNotIn("paralysis", char_one.etable) logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t3, self.t_mag, self.t_duration) self.assertIn("paralysis", char_one.etable) self.assertEqual(1, char_one.etable["paralysis"][0]) logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t3, self.t_mag, self.t_duration) self.assertEqual(1, char_one.etable["paralysis"][0]) logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t4, self.t_mag, self.t_duration) self.assertEqual(2, char_one.etable["paralysis"][0]) logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t4, self.t_mag, self.t_duration) logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t4, self.t_mag, self.t_duration) logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t4, self.t_mag, self.t_duration) logic.applyParalysisSkeleton(char_one, self.t_effect, self.t_stack, t4, self.t_mag, self.t_duration) self.assertEqual(5, char_one.etable["paralysis"][0]) char_one.logic_table.checkCondition() self.assertFalse(char_one.canmove) self.assertEqual(char_one.etable["paralysis"][0], 4) char_one.logic_table.checkCondition() char_one.logic_table.checkCondition() char_one.logic_table.checkCondition() char_one.logic_table.checkCondition() self.assertFalse(char_one.canmove) char_one.logic_table.checkCondition() self.assertTrue(char_one.canmove) self.assertNotIn("paralysis", char_one.etable) del char_one
def main(): print("\n" + logo) print(" v0.0.01 // 09.01.2019 // @cvasqxz\n") addr1 = input("> Enter valid address #1: ") addr2 = input("> Enter valid address #2: ") addr1 = "cRomsSTmwGCn2aGSrxik26iqTf655juUBR" addr2 = "coHGHzJSWLpUjbVrcNhKg4uckdfCDmNzU1" if checkAddr(addr1) and checkAddr(addr2) and not addr1 == addr2: player1 = character(addr1) player2 = character(addr2) player1.print() player2.print() print("\n\n- BATTLE BEGINS !!!") firstTurn = randint(0, 1) print("- Player #%i Starts" % (firstTurn + 1)) turn = 1 while player1.isAlive() and player2.isAlive(): print("\n- TURN #%i" % turn) print("\t* HP: (%i) vs (%i)" % (player1.hp, player2.hp)) chrATK1 = player1.getDamage(player1.moves[randint(0, 3)]) chrATK2 = player2.getDamage(player2.moves[randint(0, 3)]) print("\t* Player #1 move: %s" % chrATK1) print("\t* Player #2 move: %s" % chrATK2) if firstTurn: player1.takeDamage(chrATK2) if player1.hp == 0: break player2.takeDamage(chrATK1) else: player2.takeDamage(chrATK1) if player2.hp == 0: break player1.takeDamage(chrATK2) firstTurn = not firstTurn turn += 1 winner = 'player #1' if player1.hp > player2.hp else 'player #2' print("\n- WINNER: %s" % winner)
def enter(): global stage, mop stage = Stage() global player global enemy1 global bullet player = character() enemy1 = Enemy() mop = [Enemy() for i in range(10)] bullet = Missile1(0, 0)
def gameInit(): #Declare window object global window global player player = ch.character() #Initialize pygame and window pygame.init() window = pygame.display.set_mode((const.width, const.height)) rand.seed()
def loadCharacter(self): self.file_opt = options = {} options['defaultextension'] = '.ddchar' options['filetypes'] = [('character files', '.ddchar')] options['initialdir'] = 'save_files/' options['initialfile'] = '' options['title'] = 'Choose an encounter file to open' load_filename = tkFileDialog.askopenfilename(**self.file_opt) if load_filename: self.character = character(filename=load_filename) return
def main(argv): # setup np.random.seed(12345) numberBlocksInWorld = 8 # build world newWorld = mapbuilding.mapOfWorld(numberBlocksInWorld) newWorld.makeRandomMap() newWorld.addRoomsToWorld() # make characters jacob = character.character( "jacob", 100, 20, "rain", "hello I am jacob", newWorld.worldRooms[0] ) taco = character.character( "taco", 30, 2, "hungry people", "taco, I am", newWorld.worldRooms[5] ) print(jacob.location.roomID) print(taco.location.roomID) print(newWorld.worldMap) return 0
def handler_message(event): global count if event.message.text == 'gamestart': character.character(event.source.user_id) ca = open('cb/ability.json', 'r') cb = json.load(ca) sanA = cb[event.source.user_id]['san'] count[event.source.user_id] = 0 with open('cb/item.json', 'r') as it: wallpaper_key = json.load(it) with open('cb/item.json', 'w') as key_get: wallpaper_key[event.source.user_id] = { "wallpaper": "false", "key_1": "false" } json.dump(wallpaper_key, key_get) with open('cb/sign.json', 'r') as sign_in_name: sign_in = json.load(sign_in_name) with open('cb/sign.json', 'w') as gg: sign_in[event.source.user_id] = {"sign": "false"} json.dump(sign_in, gg) with open('cb/button.json', 'r') as it: get_button = json.load(it) with open('cb/button.json', 'w') as key_: get_button[event.source.user_id] = {"button": "false"} json.dump(get_button, key_) con_QRB = QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="了解了!", data="text=capital_1")) ]) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text="您的SAN值為{},請努力不要讓SAN值歸零喔!".format(sanA)), TextSendMessage(text="遊戲開始..."), TextSendMessage( text= "友情提示:本遊戲中有許多以骰子作檢定的動作\nSAN值都是以100面骰作檢定,若大於自身SAN值則做扣除SAN值判定,若小於自身SAN值則視情況做判定。", quick_reply=con_QRB) ]) line_bot_api.unlink_rich_menu_from_user(event.source.user_id)
def spawnCharacter (self): char = character(); # install the preprocessed blocks char.tactics = self.tactics char.feats = self.feats char.skills = self.skills char.languages = self.languages char.special_qualities = self.special_qualities char.combat_gear = self.combat_gear char.other_gear = self.other_gear return char;
def enter(): global stage,mop,State stage = Stage() global player global enemy1 global bullet global Monbullet bullet = [] Monbullet = [] player = character() enemy1 = Enemy() mop = [Enemy() for i in range(4)]
def __init__(self, type, character): import character as char checked = char.character() if type is "Bone": if checked.Race.SEXTYPE is not "Dymitive" and not "Plafor" and checked.Gender is "Male": self.result = "Penis" elif checked.Race.SEXTYPE is "Dymitive" and checked.Gender is "Fale": self.result = "Venis" elif checked.Race.SEXTYPE is "Anthronic" and checked.Gender is "Fale": self.result = "Ovipositor" elif type is "Hole": if checked.Race.SEXTYPE is "Tyromitive" and checked.Gender is "Fale": self.result = "V****a" elif checked.Race.SEXTYPE is "Dymitive" and checked.Gender is "Male": self.result = "Pagina" else: self.result = "Sprayer"
def mkcharacter(): gender = "male" if random.randrange(2) == 1 else "female" name = getRdName(gender) secondname = getRdsecondName() if antag: fakename = getRdName(gender) fakesecondname = getRdsecondName() else: fakename = "none" fakesecondname = "none" age = random.randrange(50) job = getJob(antag) record = "ERROR_NOT_FILE_FOUND" medicalRecord = "ERROR_NOT_FILE_FOUND" realRecord = "ERROR_NOT_FILE_FOUND" newcharacter = character.character(name, secondname, fakename, fakesecondname, age, job, record, medicalRecord, realRecord, gender) return newcharacter
def initGame(self): self.gameLock.acquire() self.character = character.character() self.brute = brute.brute(self.scene) self.bruteFirstBornTime = 12 self.bruteBornInterval = 18 self.ghosts = {} self.ghostId = 1 self.ghostMax = 3000 self.ghostBornInterval = 2.6 self.balls = {} self.submachineBullets = props.props() self.sniperBullets = props.props() self.medicines = props.props() self.gameTime = 0 self.gameResult = 0 # 0 for playing, 1 for win, 2 for lose self.level = 0 self.killBrute = 0 self.maxLevel = 5 self.gateMaxHp = 8000 self.gateHp = self.gateMaxHp self.gameLock.release()
#global constants screen_dimensions = 640, 480 #initialize pygame library pygame.init() #set up the screen screen = pygame.display.set_mode(screen_dimensions) #set window title pygame.display.set_caption("Poncho") #create the gui overlay that gives info about the game to the player gui_overlay = gui.gui() #create kid and set default position kid = character.character() #hook up the player to the gui gui_overlay.set_player(kid) #convert image for bullet to screen format bullet.bullet_image = bullet.bullet_image.convert_alpha() #create a red tile for testing red_tile = pygame.Surface((tilemap.tile_size,tilemap.tile_size)) red_tile.fill(0xFF0000) #create a blue tile for testing blue_tile = pygame.Surface((tilemap.tile_size,tilemap.tile_size)) blue_tile.fill(0xFFFFFF)
def generateCharacters(self, mapName, weights): mapCharacters = [[]] if mapName == "bom": mapCharacters = [[None for i in xrange(15)] for j in xrange(10)] self.mapLords = 1 #weapons in map ironAxe = weapon("Iron Axe", "axe", 8, 75, 0, 1, 10) steelAxe = weapon("Steel Axe", "axe", 11, 65, 0, 1, 15) ironSword = weapon("Iron Sword", "sword", 5, 90, 0, 1, 5) maniKatti = weapon("Mani Katti", "sword", 8, 80, .20, 1, 3) slimLance = weapon("Slim Lance", "lance", 4, 85, .05, 1, 4) ironLance = weapon("Iron Lance", "lance", 7, 80, 0, 1, 8) ironBow = weapon("Iron Bow", "bow", 6, .85, 0, 2, 5) #characters #lyn lynPrimOweights = weights["lynPrimOweights"] lynPrimDweights = weights["lynPrimDweights"] lynSecOweights = None lynSecDweights = None lynStats = stats(19, 5, 10, 12, 8, 2, 1, 5, 5) lyn = character("Lyn", "Lord", maniKatti, None, False, False, lynStats, 19, lynPrimOweights, lynPrimDweights, lynSecOweights, lynSecDweights) #kent kentPrimOweights = weights["kentPrimOweights"] kentPrimDweights = weights["kentPrimDweights"] kentSecOweights = weights["kentSecOweights"] kentSecDweights = weights["kentSecDweights"] kentStats = stats(22, 6, 6, 8, 3, 5, 1, 9, 7) kent = character("Kent", "Cavalier", ironSword, ironLance, False, False, kentStats, 22, kentPrimOweights, kentPrimDweights, kentSecOweights, kentSecDweights) #sain sainPrimOweights = weights["sainPrimOweights"] sainPrimDweights = weights["sainPrimDweights"] sainSecOweights = weights["sainSecOweights"] sainSecDweights = weights["sainSecDweights"] sainStats = stats(21, 9, 4, 8, 4, 7, 1, 9, 7) sain = character("Sain", "Cavalier", ironSword, ironLance, False, False, sainStats, 21, sainPrimOweights, sainPrimDweights, sainSecOweights, sainSecDweights) #wil wilPrimOweights = weights["wilPrimOweights"] wilPrimDweights = weights["wilPrimDweights"] wilSecOweights = None wilSecDweights = None wilStats = stats(20, 6, 5, 5, 6, 5, 0, 6, 5) wil = character("Wil", "Archer", ironBow, None, False, False, wilStats, 20, wilPrimOweights, wilPrimDweights, wilSecOweights, wilSecDweights) #florina florinaPrimOweights = weights["florinaPrimOweights"] florinaPrimDweights = weights["florinaPrimDweights"] florinaSecOweights = None florinaSecDweights = None florinaStats = stats(17, 5, 7, 9, 7, 4, 4, 4, 7) florina = character("Florina", "PegKnight", slimLance, None, False, False, florinaStats, 17, florinaPrimOweights, florinaPrimDweights, florinaSecOweights, florinaSecDweights) #enemies #L1 Brigands L1BrigandPrimOweights = util.Counter() L1BrigandPrimDweights = util.Counter() L1BrigandSecOweights = None L1BrigandSecDweights = None L1BrigandStats = stats(20, 3, 1, 5, 0, 3, 0, 12, 5) brigand1 = character("Brig1", "Brigand", ironAxe, None, True, False, L1BrigandStats, 20, L1BrigandPrimOweights, L1BrigandPrimDweights, L1BrigandSecOweights, L1BrigandSecDweights) #L2 Brigands L2BrigandPrimOweights = util.Counter() L2BrigandPrimDweights = util.Counter() L2BrigandSecOweights = None L2BrigandSecDweights = None L2BrigandStats = stats(21, 4, 2, 5, 0, 3, 0, 12, 5) brigand2 = character("Brig2", "Brigand", ironAxe, None, True, False, L2BrigandStats, 21, L2BrigandPrimOweights, L2BrigandPrimDweights, L2BrigandSecOweights, L2BrigandSecDweights) brigand3 = character("Brig3", "Brigand", ironAxe, None, True, False, L2BrigandStats, 21, L2BrigandPrimOweights, L2BrigandPrimDweights, L2BrigandSecOweights, L2BrigandSecDweights) #Mercs mercPrimOweights = util.Counter() mercPrimDweights = util.Counter() mercSecOweights = None mercSecDweights = None mercenaryStats = stats(16, 4, 7, 5, 0, 3, 0, 9, 5) merc1 = character("Merc1", "Mercenary", ironSword, None, True, False, mercenaryStats, 16, mercPrimOweights, mercPrimDweights, mercSecOweights, mercSecDweights) merc2 = character("Merc2", "Mercenary", ironSword, None, True, False, mercenaryStats, 16, mercPrimOweights, mercPrimDweights, mercSecOweights, mercSecDweights) #Archers archerPrimOweights = util.Counter() archerPrimDweights = util.Counter() archerSecOweights = None archerSecDweights = None archerStats = stats(18, 1, 3, 3, 0, 3, 0, 7, 5) archer1 = character("Archer1", "Archer", ironBow, None, True, False, archerStats, 18, archerPrimOweights, archerPrimDweights, archerSecOweights, archerSecDweights) archer2 = character("Archer2", "Archer", ironBow, None, True, False, archerStats, 18, archerPrimOweights, archerPrimDweights, archerSecOweights, archerSecDweights) #Migal migalPrimOweights = util.Counter() migalPrimDweights = util.Counter() migalSecOweights = None migalSecDweights = None migalStats = stats(25, 7, 3, 5, 2, 5, 0, 12, 5) migal = character("Migal", "Brigand", steelAxe, None, True, True, migalStats, 25, migalPrimOweights, migalPrimDweights, migalSecOweights, migalSecDweights) #initialize characters on map mapCharacters[9][2] = kent mapCharacters[8][4] = sain mapCharacters[6][3] = lyn mapCharacters[6][5] = wil mapCharacters[4][4] = florina mapCharacters[7][8] = archer1 mapCharacters[4][8] = brigand2 mapCharacters[8][13] = brigand1 mapCharacters[3][11] = archer2 mapCharacters[2][12] = brigand3 mapCharacters[6][14] = merc1 mapCharacters[0][11] = merc2 mapCharacters[0][13] = migal return mapCharacters
def loginmenu(tuser): # loop through menu this many times dopasses = 0 while dopasses >= 0: # login prompt if tuser.getmode() == "login0": tuser.send("Login:"******"login1") # check login / get password elif tuser.getmode() == "login1": # store login name var tuser.setvar({"login": tuser.getlastinput()}) # new login name if not hub.accounts.exists(tuser.getvar("login")): tuser.send("Create new account? (y/n)") tuser.setmode("loginnew") return # else, login exists, query password tuser.send("Password:"******"loginverify") # verify username and password elif tuser.getmode() == "loginverify": #store password var tuser.setvar({"password": tuser.getlastinput()}) #check credential login = hub.accounts.dologin(tuser.getvar("login"), tuser.getvar("password")) # if login is valid if login != None: tuser.setmode("loginvalid") tuser.account = login print "%s logged in." % tuser.account.getuser() dopasses = 0 continue # if login is NOT valid else: tuser.send("Invalid login/password!\n") tuser.setmode("login0") dopasses = 0 continue # create new user query / password query elif tuser.getmode() == "loginnew": # new user confirmation, ask about new password try: if tuser.getlastinput().lower()[0] == "y": tuser.send("Enter new password:"******"loginnewpass") else: tuser.setmode("login0") continue # ERROR except: tuser.setmode("login0") dopasses = 0 continue # new account password / verify elif tuser.getmode() == "loginnewpass": tuser.setvar({"password": tuser.getlastinput()}) tuser.send("Enter new password again:") tuser.setmode("loginnewpass2") # new account password verify elif tuser.getmode() == "loginnewpass2": # if passwords do not match if tuser.getlastinput() != tuser.getvar("password"): tuser.send("Passwords do not match!\n") tuser.setmode("login0") dopasses = 1 # else passwords match, create account else: # create new account and login hub.accounts.add(tuser.getvar("login"), tuser.getvar("password")) newaccount = hub.accounts.dologin(tuser.getvar("login"), tuser.getvar("password")) # account creation was successful? if newaccount != None: print "Created new user account:%s" % newaccount.getuser() tuser.send("\nAccount created successfully.\n") # associate client with account tuser.account = newaccount tuser.setmode("loginvalid") # save accounts hub.accounts.save() continue # if not, start over else: print "Error creating user account:%s" % tuser.getvar( "login") tuser.setmode("login0") dopasses = 1 # login was valid, either create new character if necessary or goto game elif tuser.getmode() == "loginvalid": tuser.skip_input = 1 if tuser.account.getcharacterfile() == None: tuser.setmode("createchar1") else: tuser.setmode("loadchar") elif tuser.getmode() == "loadchar": if tuser.char == None: tuser.char = character.character(tuser.account) tuser.char.setclient(tuser) tuser.setmode("maingamestart") tuser.skip_input = 1 #decrement passes dopasses -= 1
def createchar(tuser): # loop through menu this many times dopasses = 0 while dopasses >= 0: # new character name if tuser.getmode() == "createchar1": tuser.send("New character name:") tuser.setmode("createchar2") # check char name valid / confirmation elif tuser.getmode() == "createchar2": cname = tuser.getlastinput() # check that name is valid for c in cname: if c < "a" or c > "z": if c < "A" or c > "Z": tuser.send( "That name is not valid, characters only, no spaces!\n" ) tuser.setmode("createchar1") continue # check that character name has not already been picked if fileExists(defs.CHARACTERS_PATH + cname + ".dat"): tuser.send( "That name already exists! Please choose a different name.\n" ) tuser.setmode("createchar1") continue # format name tempname = "" tempname += cname[0].upper() tempname += cname[1:].lower() cname = tempname # character name is availalble, prompt confirmation tuser.send( "You will be known as %s, create this character? (y/n)" % cname) tuser.setvar({"charname": cname}) tuser.setmode("createchar3") elif tuser.getmode() == "createchar3": if tuser.getlastinput().lower()[0] == "y": # create character tuser.account.data["characterfile"] = tuser.getvar( "charname") + ".dat" tuser.char = character.character(tuser.account, tuser.getvar("charname")) tuser.setmode("loadchar") tuser.skip_input = 1 else: tuser.setmode("createchar1") continue #decrement passes dopasses -= 1
def create_enemy(): x = random.randint(1, len(creatures) - 1) npc = character(creatures[x][0], creatures[x][1], creatures[x][2], creatures[x][3], creatures[x][4], creatures[x][5], creatures[x][6], creatures[x][7]) npc.set_commands() return npc
from app import app from flask import render_template,send_from_directory,request from random import randint from character import character characters = {}; GoT_Followers = 836664 char_file = open("char_data.txt","r") for char in char_file: c = character(char,GoT_Followers) characters[char.split(",")[0].replace(" ","_")]=c @app.route("/") @app.route("/index") def test(): char = open("char_data.txt","r") chars=[] for line in char: chars.append(line.split(",")[0].replace(" ","_")) return render_template("index.html",chars=chars) @app.route("/js/<path:path>") def send_js(path): return send_from_directory("/static/js",path) @app.route("/css/<path:path>") def send_css(path): return send_from_directory("/static/css",path) @app.route("/how-it-works") def send_how():
def enter(): global player,grass global enemy2,mop player = character() grass = Grass() mop = [Enemy2() for i in range(8)]
def create_player(): p = character(creatures[0][0], creatures[0][1], creatures[0][2], creatures[0][3], creatures[0][4], creatures[0][5], creatures[0][6], creatures[0][7]) p.set_commands() return p
from character import character char = character() print char.output()
def testSimulation(self): px = ["Start of combat!"] from collections import Counter interesting = [ "Attacks", "Attack Hits", "Paralysis", "Paralysis Hits", "Actions", "Damage Dealt", "Duration Paralyzed" ] stats = Counter({"turns": 0}) char_list = [character.character(), character.character()] for each in interesting: for every in char_list: stats[every.label + each] = 0 eng = initiative.InitiativeEngine() rolled_initiative = [False] ms = lambda a, b, c, d: logic.miss(a, b, c, d, printer=px) pz = lambda a, b, c, d: logic.paralysis( a, b, c, d, printer=px, label="paralyze") atk = lambda a, b, c: logic.attack(a, b, c, printer=px) actions = {"paralyze": pz, "attack": atk, "miss": ms} #Initialize the characters. This would be better done as a factory. for each in char_list: each.logic_table.update(actions) f = lambda x: x != each each.target_list = [x for x in filter(f, char_list)] def monitor(): for each in px: print(each) px.clear() for each in char_list: if each.hp < 1: return ("end", "kill") if not rolled_initiative[0]: rolled_initiative[0] = True for each in char_list: each.rollInitiative() eng.queuToUpdate(each, each.initiative + 20) eng.queuAtBack(countStats, len(eng)) eng.queuAtBack(resolveActions, len(eng)) def countStats(): if rolled_initiative[0]: rolled_initiative[0] = False stats["turns"] += 1 for each in char_list: for label, values in each.etable.items(): if label == "miss": if values[2] == "attack": stats[each.label + "Attacks"] += 1 if values[2] == "paralyze": stats[each.label + "Paralysis"] += 1 stats[each.label + "Actions"] += 1 if label == "attack": stats[values[1].label + "Attacks"] += 1 stats[values[1].label + "Attack Hits"] += 1 stats[values[1].label + "Actions"] += 1 stats[values[1].label + "Damage Dealt"] += values[0] if label == "paralyze": if each.canmove: stats[values[1].label + "Paralysis"] += 1 stats[each.label + "Duration Paralyzed"] += 1 stats[values[1].label + "Paralysis Hits"] += 1 stats[values[1].label + "Actions"] += 1 return "kill" def resolveActions(): for each in char_list: each.logic_table.checkCondition() return "kill" eng.append(monitor, 0) while len(eng): if not eng.paused: eng() else: eng.resume() loser = list(filter(lambda x: x.hp < 1, char_list))[0] winner = list(filter(lambda x: x.hp > 0, char_list))[0] print("The winner is {}, the loser is {}, after {} turns.".format( winner.label, loser.label, stats["turns"])) print("Statistics") for each, every in sorted(stats.items(), key=lambda x: winner.label in x[0]): print("{} -> {}".format(each, every))
def process(self,line): args = line.split() if args[0] == 'load': try: self.loadMaze(args[1]) except: self.maz = None elif args[0] == 'show': if self.maz == None: return chars = [] if self.exploring: xmin = max(0,self.ctr.x-5) xmax = min(self.maz.width,self.ctr.x+6) ymin = max(0,self.ctr.y-5) ymax = min(self.maz.height,self.ctr.y+6) else: xmin = 0 xmax = self.maz.width ymin = 0 ymax = self.maz.height for i in range(2*self.maz.width+1): chars.append([]) for j in range(2*self.maz.height+1): chars[i].append(' ') for i in range(self.maz.width): for j in range(self.maz.height): if not self.exploring or self.visible[i][j]: chars[2*i][2*j]='@' chars[2*i+2][2*j]='@' chars[2*i][2*j+2]='@' chars[2*i+2][2*j+2]='@' c = self.maz.cell(i,j) if c & ENTRANCE: chars[2*i+1][2*j+1]='I' if c & COFFERS: chars[2*i+1][2*j+1]='C' if self.exploring: if i == self.ctr.x and j == self.ctr.y: chars[2*i+1][2*j+1]='*' if c & WEST: chars[2*i][2*j+1]='@' if c & SOUTH: chars[2*i+1][2*j+2]='@' if c & EAST: chars[2*i+2][2*j+1]='@' if c & NORTH: chars[2*i+1][2*j]='@' outstr = '' if self.exploring: for y in range(2*(ymin-(self.ctr.y-5))): outstr+='\n' for y in range(2*ymin,2*ymax+1): if self.exploring: for x in range(2*(xmin-(self.ctr.x-5))): outstr += ' ' for x in range(2*xmin,2*xmax+1): outstr += chars[x][y] outstr+='\n' if self.exploring: for y in range(2*((self.ctr.y+6)-ymax)): outstr+='\n' self.conn.sendall(outstr) if self.exploring: descr = '' if self.ctr.x == self.maz.ix and self.ctr.y == self.maz.iy: descr += 'There is an exit here.\n' if self.ctr.x == self.maz.cx and self.ctr.y == self.maz.cy: descr += 'The coffers are located here\n' self.conn.sendall(descr) elif args[0] == 'help': self.conn.sendall(self.helpstr) elif args[0] == 'explore': if self.maz==None: return self.exploring = True if self.ctr == None: self.ctr = character.character() self.ctr.x = self.maz.ix self.ctr.y = self.maz.iy self.visible=[] for i in range(self.maz.width): self.visible.append([]) for j in range(self.maz.height): self.visible[i].append(False) self.visible[self.maz.ix][self.maz.iy]=True elif args[0] == 'n': if not self.exploring: return if self.maz.cell(self.ctr.x,self.ctr.y) & NORTH: return self.ctr.y-=1 self.visible[self.ctr.x][self.ctr.y]=True elif args[0] == 'e': if not self.exploring: return if self.maz.cell(self.ctr.x,self.ctr.y) & EAST: return self.ctr.x+=1 self.visible[self.ctr.x][self.ctr.y]=True elif args[0] == 's': if not self.exploring: return if self.maz.cell(self.ctr.x,self.ctr.y) & SOUTH: return self.ctr.y+=1 self.visible[self.ctr.x][self.ctr.y]=True elif args[0] == 'w': if not self.exploring: return if self.maz.cell(self.ctr.x,self.ctr.y) & WEST: return self.ctr.x-=1 self.visible[self.ctr.x][self.ctr.y]=True elif args[0] == 'n': if not self.exploring: return if self.maz.cell(self.ctr.x,self.ctr.y) & NORTH: return self.ctr.y-=1 self.visible[self.ctr.x][self.ctr.y]=True else: self.conn.sendall('What?\n')
import numpy as np import room import mapbuilding import actions import character np.random.seed(12345) # make the world newWorld = mapbuilding.mapOfWorld(8) newWorld.makeRandomMap() newWorld.addRoomsToWorld() # make characters jacob = character.character("jacob", 100, 20, "rain", "hello I am jacob", newWorld.worldRooms[0]) taco = character.character("taco", 30, 2, "rain", "I am a taco", newWorld.worldRooms[5]) # execute the move actions.moveCharacterUserDecision(newWorld, jacob)
def main(): #######################INICIALIZACION DE VARIABLES########################## ####### VARIABLES QUE DEFINEN LA PANTALLA DEL JUEGO FPS = 60 WIDTH = 800 HEIGHT = 600 filas = 13 # Numero de filas en las que se dividira el viewport columnas = 17 # Numero de columnas en los que se dividira el viewpoert # Matriz que guardara el estado del juego mEstadoJuego = [None] * filas for i in range(filas): mEstadoJuego[i] = [0] * columnas # Inicializacion de pygame y de opengl init(WIDTH, HEIGHT, "Super Bomberman Deluxe") # Se crea el reloj del juego clock = pygame.time.Clock() # Musica y sonidos pygame.mixer.music.load("Res/bgm.mp3") bombExp = pygame.mixer.Sound("Res/BOM_11_S.wav") bomSet = pygame.mixer.Sound("Res/BOM_SET.wav") goalSound = pygame.mixer.Sound("Res/GOAL.wav") itemGet = pygame.mixer.Sound("Res/ITEM_GET.wav") shiso = pygame.mixer.Sound("Res/SHISO.wav") pygame.mixer.music.play(-1,0) ####### VARIABLES QUE DEFINEN LOS ELEMENTOS EN PANTALLA vistaPrincipal = vista.vista() p1 = character.character(mPos(1, 1, WIDTH, HEIGHT, filas, columnas)) vistaPrincipal.personaje = p1 # Muros indestructibles for i in range(filas): vistaPrincipal.listaMuros.append(wall.wall(mPos(i, columnas - 1, WIDTH, HEIGHT, filas, columnas))) vistaPrincipal.listaMuros.append(wall.wall(mPos(i, 0, WIDTH, HEIGHT, filas, columnas))) mEstadoJuego[i][0] = -1 mEstadoJuego[i][columnas - 1] = -1 for i in range(columnas): vistaPrincipal.listaMuros.append(wall.wall(mPos(0, i, WIDTH, HEIGHT, filas, columnas))) vistaPrincipal.listaMuros.append(wall.wall(mPos(filas - 1, i, WIDTH, HEIGHT, filas, columnas))) mEstadoJuego[0][i] = -1 mEstadoJuego[filas - 1][i] = -1 for i in range(filas): for j in range(columnas): if i % 2 == 0 and j % 2 == 0: vistaPrincipal.listaMuros.append(wall.wall(mPos(i, j, WIDTH, HEIGHT, filas, columnas))) mEstadoJuego[i][j] = -1 # Escalamos los muros de forma correcta para la pantalla for i in vistaPrincipal.listaMuros: i.escalarCorrecto(WIDTH, HEIGHT, filas, columnas) # Muros destructibles # recorremos la matriz completa for q15 in range(filas): for p15 in range(columnas): # Donde exista un espacio libre if mEstadoJuego[q15][p15] == 0: azar = random.randint(0, 100) # Pared se generara azarosamente if not (q15 == 1 and p15 == 1) and not (q15 == 1 and p15 == 2) and not ( q15 == 2 and p15 == 1): # Fuera de las zonas principales if azar > 50: vistaPrincipal.listaDestructibles.append( destructibleWall.destructibleWall(mPos(q15, p15, WIDTH, HEIGHT, filas, columnas))) vistaPrincipal.listaDestructibles[-1].escalarCorrecto(WIDTH, HEIGHT, filas, columnas) mEstadoJuego[q15][p15] = 1 # recorremos la matriz completa for q16 in range(filas): for p16 in range(columnas): # Detras de una pared if mEstadoJuego[q16][p16] == 1: azar2 = random.randint(0, 100) # Pared se generara azarosamente if 0 < azar2 < 10: vistaPrincipal.listaPowerUp1.append( PowerUP1.powerUP1(mPos(q16, p16, WIDTH, HEIGHT, filas, columnas))) if 10 < azar2 < 20: vistaPrincipal.listaPowerUp2.append( PowerUP2.powerUP2(mPos(q16, p16, WIDTH, HEIGHT, filas, columnas))) if 20 < azar2 < 30: vistaPrincipal.listaPowerUp3.append( PowerUP3.powerUP3(mPos(q16, p16, WIDTH, HEIGHT, filas, columnas))) # Anadimos algunos enemigos a la escena (en particular 4) nEnemigos = 0 while True: px = random.randint(0, filas - 1) py = random.randint(0, columnas - 1) if not (px == 1 and py == 1) and not (px == 1 and py == 2) and not (px == 2 and py == 1): if nEnemigos == 0 or nEnemigos == 1: if mEstadoJuego[px][py] == 0: vistaPrincipal.listaEnemigos.append(enemy.enemy(mPos(px, py, WIDTH, HEIGHT, filas, columnas))) nEnemigos += 1 elif nEnemigos == 2 or nEnemigos == 3: if mEstadoJuego[px][py] == 0: vistaPrincipal.listaEnemigos.append(enemy2.enemy2(mPos(px, py, WIDTH, HEIGHT, filas, columnas))) nEnemigos += 1 if nEnemigos == 4: break # Annadimos la salida en una posicion aleatoria while True: px = random.randint(0, filas - 1) py = random.randint(0, columnas - 1) if mEstadoJuego[px][py] == 1: salida = Salida.Salida(mPos(px, py, WIDTH, HEIGHT, filas, columnas)) vistaPrincipal.salida = salida break ###### VARIABLES QUE SIRVEN PARA LA LOGICA DEL JUEGO maxBombas = 3 alcance = 1 keyToExplode = False #######################COMIENZO DEL BUCLE########################## run = True while run: clock.tick(FPS) #######################ANALISIS DE EVENTOS########################## for event in pygame.event.get(): if event.type == QUIT: exit() if event.type == KEYDOWN: # colocar bomba if event.key == K_a: (i, j) = p1.indices(filas, columnas, WIDTH, HEIGHT) if mEstadoJuego[i][j] == 0 and len(vistaPrincipal.listaBombas) < maxBombas: bomb = bomba.bomba(mPos(i, j, WIDTH, HEIGHT, filas, columnas)) bomb.setTiempoInicial(time.get_ticks()) bomb.alcance = alcance vistaPrincipal.listaBombas.append(bomb) mEstadoJuego[i][j] = 2 bomSet.play() # explotar las bombas if event.key == K_s and keyToExplode: if len(vistaPrincipal.listaBombas) > 0: bombExp.play() bomb = vistaPrincipal.listaBombas[0] bomb.explotar(mEstadoJuego, filas, columnas, WIDTH, HEIGHT, vistaPrincipal) ######################LOGICA DEL JUEGO################################ keys = pygame.key.get_pressed() if keys[K_LEFT]: if p1.checkLista(Vector(-1, 0) * p1.velocidad, vistaPrincipal.listaMuros + vistaPrincipal.listaDestructibles): if checkBombAtravesable(Vector(-1, 0), p1, vistaPrincipal.listaBombas): p1.mover(Vector(-1, 0) * p1.velocidad) if keys[K_UP]: if p1.checkLista(Vector(0, 1) * p1.velocidad, vistaPrincipal.listaMuros + vistaPrincipal.listaDestructibles): if checkBombAtravesable(Vector(0, 1), p1, vistaPrincipal.listaBombas): p1.mover(Vector(0, 1) * p1.velocidad) if keys[K_RIGHT]: if p1.checkLista(Vector(1, 0) * p1.velocidad, vistaPrincipal.listaMuros + vistaPrincipal.listaDestructibles): if checkBombAtravesable(Vector(1, 0), p1, vistaPrincipal.listaBombas): p1.mover(Vector(1, 0) * p1.velocidad) if keys[K_DOWN]: if p1.checkLista(Vector(0, -1) * p1.velocidad, vistaPrincipal.listaMuros + vistaPrincipal.listaDestructibles): if checkBombAtravesable(Vector(0, -1), p1, vistaPrincipal.listaBombas): p1.mover(Vector(0, -1) * p1.velocidad) # Cambiamos estado de las bombas si dejamos de tocarlas for bomb in vistaPrincipal.listaBombas: if not (bomb.rect.colliderect(p1.rect)): bomb.atravesable = False # explocion de una bomba for bomb in vistaPrincipal.listaBombas: if time.get_ticks() - bomb.tiempoInicial > 3000: bombExp.play() bomb.explotar(mEstadoJuego, filas, columnas, WIDTH, HEIGHT, vistaPrincipal) # Quitar la explocion de la bomba for bomb in vistaPrincipal.listaExplociones: if time.get_ticks() - bomb.tiempoExplotada > 1300: # Quitamos elementos de la vista y de las listas vistaPrincipal.listaExplociones.pop(0) # Verificar si esta chocando con una explocion for bombExploted in vistaPrincipal.listaExplociones: for rec in bombExploted.rectList: if rec.collidepoint(p1.rect.center): # Aqui hay que quitar el juego print "Has perdido" run = False # Verificar los power ups for pup in vistaPrincipal.listaPowerUp1: if p1.rect.colliderect(pup.rect): itemGet.play() p1.aumentarVelocidad(1) vistaPrincipal.listaPowerUp1.pop(vistaPrincipal.listaPowerUp1.index(pup)) for pup in vistaPrincipal.listaPowerUp2: if p1.rect.colliderect(pup.rect): itemGet.play() alcance += 1 vistaPrincipal.listaPowerUp2.pop(vistaPrincipal.listaPowerUp2.index(pup)) for pup in vistaPrincipal.listaPowerUp3: if p1.rect.colliderect(pup.rect): itemGet.play() keyToExplode = True vistaPrincipal.listaPowerUp3.pop(vistaPrincipal.listaPowerUp3.index(pup)) # Movimiento de los enemigos for enem in vistaPrincipal.listaEnemigos: chocaFuego = False for i in vistaPrincipal.listaExplociones: enem.mover(enem.direccion * enem.velocidad) for rect in i.rectList: if enem.rect.colliderect(rect): chocaFuego = True enem.mover(enem.direccion * enem.velocidad * -1) if not (enem.checkLista(enem.direccion * enem.velocidad, vistaPrincipal.listaDestructibles + vistaPrincipal.listaMuros)) or not ( checkBombAtravesable(enem.direccion, enem, vistaPrincipal.listaBombas)): enem.rotar() elif chocaFuego: enem.rotar() else: enem.mover(enem.direccion * enem.velocidad) # Matar enemigos si chocan con fuego for enem in vistaPrincipal.listaEnemigos: for bombExploted in vistaPrincipal.listaExplociones: for rec in bombExploted.rectList: if rec.collidepoint(enem.rect.center): shiso.play() vistaPrincipal.listaEnemigos.pop(vistaPrincipal.listaEnemigos.index(enem)) # Cerrar el juego si choca con enemigo for enem in vistaPrincipal.listaEnemigos: if enem.rect.colliderect(p1.rect): # Aqui hay que quitar el juego print "Has perdido" run = False # Ganar si llega hasta la salida if p1.rect.colliderect(salida.rect): goalSound.play() print "Has ganado" run = False #######################DIBUJO DE LAS VISTAS########################## vistaPrincipal.dibujar() # Actualizamos la pantalla pygame.display.flip()
import character as ch player_bstat = ch.basic_stat(acc=3, jump_power=10, max_speed=10, max_hp=100, max_mp=100) player_phstat = ch.physics_stat(width=20, height=20, air_drag=0.2) player = ch.player("1P", (500, 400), player_bstat, player_phstat) #-- MAPS FOR USE ------------------------------------------------------------------------------# maps = {} # TEST MAP (test_map) test_map = mapping.mapping((40, 24)) test_map_chars = [] temp = ch.character("HEOSU", (600, 300), player_bstat, player_phstat) temp.set_map(test_map) test_map_chars.append(temp) test_map.map_setting(mapping.map_temp, {'start': (50, 300)}, test_map_chars) test_map.background_setting(pygame.image.load("img/map/test_map_bg.png")) test_map.add_block( entity.eventblock( test_map, (5, 5), entity.PLAYER_COLLIDE, lambda: test_map.player.harms.append(attack.damage(5, False)))) test_map.add_block( entity.eventblock(test_map, (10, 5), entity.PLAYER_COLLIDE, lambda: test_map.player.set_acc((3, 3), 10))) test_map.add_block( entity.eventblock(test_map, (15, 5), entity.PLAYER_COLLIDE, lambda: test_map.player.set_controlled('stunned', 30)))
lastNames = [] for i in f: lastNames.append(i.strip('\n')) f.close() f = open("assets/proc/profession.txt",'r') professionList = [] for i in f: professionList.append(i.strip('\n')) f.close() for i in range(10): #Create 10 characters first = firstNames[random.randint(0,len(firstNames)-1)] last = lastNames[random.randint(0,len(lastNames)-1)] profession = professionList[random.randint(0,len(professionList)-1)] home = settlementList[random.randint(0,len(settlementList)-1)].getName() characterList.append(character.character(first,last,profession,home)) characterList[-1].setSprite(pygame.image.load("assets/character.png")) print characterList[-1].getDetails() titleFont = pygame.font.SysFont(None,72) textFont = pygame.font.SysFont(None,30) title = titleFont.render("Sussex Smuggler",True,(45,46,40)) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: pygame.quit() sys.exit()
import character as ch import random import Items true = True; false = False; debugList=[]; #Format: Name, max hp, strength, resistance, accuracy, evasion, type Xanu = ch.character("Xanu", 220, 175, 1.2, 90, 1.1, ch.charType.attack); Sepha = ch.character("Sepha", 150, 80, 1, 80, 1.7, ch.charType.healer); Kitzurea = ch.character("Kitzurea", 230, 125, 1.5, 85, 0.75, ch.charType.tank); Xanu.aggro+=25; Sepha.aggro+=25; Kitzurea.aggro+=25; allies = [Xanu, Sepha, Kitzurea]; Fauron = ch.character("Fauron", 250, 145, 1.2, 85, 1.2, ch.charType.attack); Loranu = ch.character("Loranu", 200, 85, 1, 80, 1.5, ch.charType.healer); Hisipha = ch.character("Hisipha", 270, 120, 1.4, 90, 0.9, ch.charType.tank); enemies = [Fauron, Loranu, Hisipha]; itemList = [Items.potion(1), Items.potion(Items.liquid.healthPotion), Items.potion(Items.liquid.water)]; def gameOverCheck(): isOver = true; for ally in allies: if(ally.isConscious): isOver = false;
lastNames.append(i.strip('\n')) f.close() f = open("assets/proc/profession.txt", 'r') professionList = [] for i in f: professionList.append(i.strip('\n')) f.close() for i in range(10): #Create 10 characters first = firstNames[random.randint(0, len(firstNames) - 1)] last = lastNames[random.randint(0, len(lastNames) - 1)] profession = professionList[random.randint(0, len(professionList) - 1)] home = settlementList[random.randint(0, len(settlementList) - 1)].getName() characterList.append(character.character(first, last, profession, home)) characterList[-1].setSprite(pygame.image.load("assets/character.png")) print characterList[-1].getDetails() titleFont = pygame.font.SysFont(None, 72) textFont = pygame.font.SysFont(None, 30) title = titleFont.render("Sussex Smuggler", True, (45, 46, 40)) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: pygame.quit() sys.exit()
def setUp(self): self.c1 = character(10,"bob",100) self.c2 = character(15,"john",500)
def create_player(): p = character(creatures[0][0], creatures[0][1], creatures[0][2], creatures[0][3], creatures[0][4], creatures[0][5], creatures[0][6], creatures[0][7]) return p
print("Today is day {}".format(inEnv.day)) print("Player: {} \nhp: {}".format(inCharacter.name, inCharacter.hp)) def doDamage(aAtk, bDeff): damage = aAtk * random.randint(1, 2) - bDeff if damage <= 0: return 0 else: return damage # varibal list ==================================== gameOver = False player = ch.character(ch.chData["mainCharacter"]) littleZombie = ch.character(ch.chData["littleZombie"]) env = env.environment() # varibal list ==================================== while not gameOver: showState(player, env) if env.isBloodMoon(): print("\nToday is BLOODMOON!!!\n") while player.hp > 0 and littleZombie.hp > 0: print("There is a little zombie in your house") print("little zombie HP:{}".format(littleZombie.hp)) print("your HP:{}".format(player.hp))
def generateCharacters(self, mapName): mapCharacters = [[]] if mapName == "bom": mapCharacters = [[None for i in xrange(15)] for j in xrange(10)] self.mapLords = 1 #weapons in map ironAxe = weapon("Iron Axe", "axe", 8, 75, 0, 1, 10) steelAxe = weapon("Steel Axe", "axe", 11, 65, 0, 1, 15) ironSword = weapon("Iron Sword", "sword", 5, 90, 0, 1, 5) maniKatti = weapon("Mani Katti", "sword", 8, 80, .20, 1, 3) slimLance = weapon("Slim Lance", "lance", 4, 85, .05, 1, 4) ironLance = weapon("Iron Lance", "lance", 7, 80, 0, 1, 8) ironBow = weapon("Iron Bow", "bow", 6, .85, 0, 2, 5) #characters #lyn lynPrimOweights = util.Counter() lynPrimDweights = util.Counter() lynSecOweights = None lynSecDweights = None # offensive (normal) weights lynPrimOweights["terrainDefBonus"] = 1.0 lynPrimOweights["terrainAvoidBonus"] = 1.0 lynPrimOweights["expectedDeath"] = -500.0 lynPrimOweights["expectedKill"] = 5.0 lynPrimOweights["damageGiven"] = 1.0 lynPrimOweights["damageTaken"] = -3.0 lynPrimOweights["bossDead"] = 50.0 lynPrimOweights["allEnemiesDead"] = 100.0 lynPrimOweights["numArchersInRange"] = -.5 lynPrimOweights["numAxeUsersInRange"] = 1.0 lynPrimOweights["numLanceUsersInRange"] = -1.0 lynPrimOweights["numSwordUsersInRange"] = 0 lynPrimOweights["bossInRangeWhileEnemiesStillAlive"] = -5.0 lynPrimOweights["bossInRangeWhileEnemiesAllDead"] = 1.0 lynPrimOweights["inRangeOfOneUnit"] = 2.0 lynPrimOweights["inRangeOfTwoUnits"] = 1.0 lynPrimOweights["inRangeOfThreeUnits"] = -1.0 lynPrimOweights["inRangeOfFourUnits"] = -5.0 lynPrimOweights["inRangeOfFiveUnitsOrMore"] = -10.0 lynPrimOweights["nearestEnemyDistance"] = -2.0 lynPrimOweights["adjacentToEnemy"] = -500.0 # defensive weights lynPrimDweights["terrainDefBonus"] = 5.0 lynPrimDweights["terrainAvoidBonus"] = 5.0 lynPrimDweights["expectedDeath"] = -500.0 lynPrimDweights["expectedKill"] = 1.0 lynPrimDweights["damageGiven"] = 1.0 lynPrimDweights["damageTaken"] = -5.0 lynPrimDweights["bossDead"] = 50.0 lynPrimDweights["allEnemiesDead"] = 100.0 lynPrimDweights["numArchersInRange"] = -2.5 lynPrimDweights["numAxeUsersInRange"] = -.1 lynPrimDweights["numLanceUsersInRange"] = -5.0 lynPrimDweights["numSwordUsersInRange"] = -1.0 lynPrimDweights["bossInRangeWhileEnemiesStillAlive"] = -10.0 lynPrimDweights["bossInRangeWhileEnemiesAllDead"] = 2.0 lynPrimDweights["inRangeOfOneUnit"] = -.2 lynPrimDweights["inRangeOfTwoUnits"] = -3.0 lynPrimDweights["inRangeOfThreeUnits"] = -4.0 lynPrimDweights["inRangeOfFourUnits"] = -4.0 lynPrimDweights["inRangeOfFiveUnitsOrMore"] = -5.0 lynPrimDweights["nearestEnemyDistance"] = 1.0 lynStats = stats(19, 5, 10, 12, 8, 2, 1, 5, 5) lyn = character("Lyn", "Lord", maniKatti, None, False, False, lynStats, 19, lynPrimOweights, lynPrimDweights, lynSecOweights, lynSecDweights) #kent kentPrimOweights = util.Counter() kentPrimDweights = util.Counter() kentSecOweights = util.Counter() kentSecDweights = util.Counter() # offensive (normal) weights (primary weapon - lance) kentPrimOweights["terrainDefBonus"] = 1.0 kentPrimOweights["terrainAvoidBonus"] = 1.0 kentPrimOweights["expectedDeath"] = -500.0 kentPrimOweights["expectedKill"] = 5.0 kentPrimOweights["damageGiven"] = 1.0 kentPrimOweights["damageTaken"] = -1.0 kentPrimOweights["bossDead"] = 50.0 kentPrimOweights["allEnemiesDead"] = 100.0 kentPrimOweights["numArchersInRange"] = 1.0 kentPrimOweights["numAxeUsersInRange"] = -1.0 kentPrimOweights["numLanceUsersInRange"] = .8 kentPrimOweights["numSwordUsersInRange"] = 1.0 kentPrimOweights["bossInRangeWhileEnemiesStillAlive"] = -5.0 kentPrimOweights["bossInRangeWhileEnemiesAllDead"] = -2.0 kentPrimOweights["inRangeOfOneUnit"] = 4.0 kentPrimOweights["inRangeOfTwoUnits"] = 4.0 kentPrimOweights["inRangeOfThreeUnits"] = 2.0 kentPrimOweights["inRangeOfFourUnits"] = 1.0 kentPrimOweights["inRangeOfFiveUnitsOrMore"] = -2.0 kentPrimOweights["nearestEnemyDistance"] = -2.0 # defensive weights (primary weapon) kentPrimDweights["terrainDefBonus"] = 3.0 kentPrimDweights["terrainAvoidBonus"] = 3.0 kentPrimDweights["expectedDeath"] = -500.0 kentPrimDweights["expectedKill"] = 1.0 kentPrimDweights["damageGiven"] = 1.0 kentPrimDweights["damageTaken"] = -5.0 kentPrimDweights["bossDead"] = 50.0 kentPrimDweights["allEnemiesDead"] = 100.0 kentPrimDweights["numArchersInRange"] = -2.5 kentPrimDweights["numAxeUsersInRange"] = -4.0 kentPrimDweights["numLanceUsersInRange"] = -1.0 kentPrimDweights["numSwordUsersInRange"] = -1.0 kentPrimDweights["bossInRangeWhileEnemiesStillAlive"] = -10.0 kentPrimDweights["bossInRangeWhileEnemiesAllDead"] = 5.0 kentPrimDweights["inRangeOfOneUnit"] = -.2 kentPrimDweights["inRangeOfTwoUnits"] = -1.0 kentPrimDweights["inRangeOfThreeUnits"] = -3.0 kentPrimDweights["inRangeOfFourUnits"] = -4.0 kentPrimDweights["inRangeOfFiveUnitsOrMore"] = -5.0 kentPrimDweights["nearestEnemyDistance"] = 1.0 # secondary weapon # offensive (normal) weights (secondary weapon) kentSecOweights["terrainDefBonus"] = 1.0 kentSecOweights["terrainAvoidBonus"] = 1.0 kentSecOweights["expectedDeath"] = -500.0 kentSecOweights["expectedKill"] = 5.0 kentSecOweights["damageGiven"] = 1.0 kentSecOweights["damageTaken"] = -1.0 kentSecOweights["bossDead"] = 50.0 kentSecOweights["allEnemiesDead"] = 100.0 kentSecOweights["numArchersInRange"] = 1.0 kentSecOweights["numAxeUsersInRange"] = 3.0 kentSecOweights["numLanceUsersInRange"] = -1.0 kentSecOweights["numSwordUsersInRange"] = 1.0 kentSecOweights["bossInRangeWhileEnemiesStillAlive"] = -5.0 kentSecOweights["bossInRangeWhileEnemiesAllDead"] = 2.0 kentSecOweights["inRangeOfOneUnit"] = 4.0 kentSecOweights["inRangeOfTwoUnits"] = 3.0 kentSecOweights["inRangeOfThreeUnits"] = 1.5 kentSecOweights["inRangeOfFourUnits"] = .5 kentSecOweights["inRangeOfFiveUnitsOrMore"] = -2.0 kentSecOweights["nearestEnemyDistance"] = -2.0 # defensive weights (secondary weapon) kentSecDweights["terrainDefBonus"] = 5.0 kentSecDweights["terrainAvoidBonus"] = 5.0 kentSecDweights["expectedDeath"] = -500.0 kentSecDweights["expectedKill"] = 1.0 kentSecDweights["damageGiven"] = 1.0 kentSecDweights["damageTaken"] = -5.0 kentSecDweights["bossDead"] = 50.0 kentSecDweights["allEnemiesDead"] = 100.0 kentSecDweights["numArchersInRange"] = -2.5 kentSecDweights["numAxeUsersInRange"] = -.1 kentSecDweights["numLanceUsersInRange"] = -4.0 kentSecDweights["numSwordUsersInRange"] = -1.0 kentSecDweights["bossInRangeWhileEnemiesStillAlive"] = -10.0 kentSecDweights["bossInRangeWhileEnemiesAllDead"] = -2.0 kentSecDweights["inRangeOfOneUnit"] = -.2 kentSecDweights["inRangeOfTwoUnits"] = -2.0 kentSecDweights["inRangeOfThreeUnits"] = -3.0 kentSecDweights["inRangeOfFourUnits"] = -4.0 kentSecDweights["inRangeOfFiveUnitsOrMore"] = -5.0 kentSecDweights["nearestEnemyDistance"] = 1.0 kentStats = stats(22, 6, 6, 8, 3, 5, 1, 9, 7) kent = character("Kent", "Cavalier", ironSword, ironLance, False, False, kentStats, 22, kentPrimOweights, kentPrimDweights, kentSecOweights, kentSecDweights) #sain sainPrimOweights = kentPrimOweights sainPrimDweights = kentPrimDweights sainSecOweights = kentSecOweights sainSecDweights = kentSecDweights sainStats = stats(21, 9, 4, 8, 4, 7, 1, 9, 7) sain = character("Sain", "Cavalier", ironSword, ironLance, False, False, sainStats, 21, sainPrimOweights, sainPrimDweights, sainSecOweights, sainSecDweights) #wil wilPrimOweights = util.Counter() wilPrimDweights = util.Counter() wilSecOweights = None wilSecDweights = None # offensive (normal) weights wilPrimOweights["terrainDefBonus"] = 1.0 wilPrimOweights["terrainAvoidBonus"] = 1.0 wilPrimOweights["expectedDeath"] = -500.0 wilPrimOweights["expectedKill"] = 5.0 wilPrimOweights["damageGiven"] = 2.0 wilPrimOweights["damageTaken"] = -1.5 wilPrimOweights["bossDead"] = 50.0 wilPrimOweights["allEnemiesDead"] = 100.0 wilPrimOweights["numArchersInRange"] = 1.0 wilPrimOweights["numAxeUsersInRange"] = -.5 wilPrimOweights["numLanceUsersInRange"] = -.5 wilPrimOweights["numSwordUsersInRange"] = -.5 wilPrimOweights["bossInRangeWhileEnemiesStillAlive"] = -5.0 wilPrimOweights["bossInRangeWhileEnemiesAllDead"] = 1.0 wilPrimOweights["inRangeOfOneUnit"] = 1.0 wilPrimOweights["inRangeOfTwoUnits"] = -.2 wilPrimOweights["inRangeOfThreeUnits"] = -4.0 wilPrimOweights["inRangeOfFourUnits"] = -5.0 wilPrimOweights["inRangeOfFiveUnitsOrMore"] = -7.0 wilPrimOweights["adjacentToEnemy"] = -5000.0 wilPrimOweights["nearestEnemyDistance"] = -.5 # defensive weights wilPrimDweights["terrainDefBonus"] = 5.0 wilPrimDweights["terrainAvoidBonus"] = 5.0 wilPrimDweights["expectedDeath"] = -500.0 wilPrimDweights["expectedKill"] = 1.0 wilPrimDweights["damageGiven"] = 1.0 wilPrimDweights["damageTaken"] = -5.0 wilPrimDweights["bossDead"] = 50.0 wilPrimDweights["allEnemiesDead"] = 100.0 wilPrimDweights["numArchersInRange"] = -.2 wilPrimDweights["numAxeUsersInRange"] = -10.0 wilPrimDweights["numLanceUsersInRange"] = -10.0 wilPrimDweights["numSwordUsersInRange"] = -10.0 wilPrimDweights["bossInRangeWhileEnemiesStillAlive"] = -10.0 wilPrimDweights["bossInRangeWhileEnemiesAllDead"] = 5.0 wilPrimDweights["inRangeOfOneUnit"] = -.2 wilPrimDweights["inRangeOfTwoUnits"] = -3.0 wilPrimDweights["inRangeOfThreeUnits"] = -5.0 wilPrimDweights["inRangeOfFourUnits"] = -6.0 wilPrimDweights["inRangeOfFiveUnitsOrMore"] = -8.0 wilPrimDweights["adjacentToEnemy"] = -100.0 wilPrimDweights["nearestEnemyDistance"] = -.2 wilStats = stats(20, 6, 5, 5, 6, 5, 0, 6, 5) wil = character("Wil", "Archer", ironBow, None, False, False, wilStats, 20, wilPrimOweights, wilPrimDweights, wilSecOweights, wilSecDweights) #florina florinaPrimOweights = util.Counter() florinaPrimDweights = util.Counter() florinaSecOweights = None florinaSecDweights = None # offensive (normal) weights florinaPrimOweights["terrainDefBonus"] = 1.0 florinaPrimOweights["terrainAvoidBonus"] = 1.0 florinaPrimOweights["expectedDeath"] = -500.0 florinaPrimOweights["expectedKill"] = 5.0 florinaPrimOweights["damageGiven"] = 1.0 florinaPrimOweights["damageTaken"] = -2.0 florinaPrimOweights["bossDead"] = 50.0 florinaPrimOweights["allEnemiesDead"] = 100.0 florinaPrimOweights["numArchersInRange"] = -500.0 florinaPrimOweights["numAxeUsersInRange"] = -2.0 florinaPrimOweights["numLanceUsersInRange"] = 0 florinaPrimOweights["numSwordUsersInRange"] = 1.0 florinaPrimOweights["bossInRangeWhileEnemiesStillAlive"] = -6.0 florinaPrimOweights["bossInRangeWhileEnemiesAllDead"] = -.1 florinaPrimOweights["inRangeOfOneUnit"] = .2 florinaPrimOweights["inRangeOfTwoUnits"] = -2.0 florinaPrimOweights["inRangeOfThreeUnits"] = -3.0 florinaPrimOweights["inRangeOfFourUnits"] = -5.0 florinaPrimOweights["inRangeOfFiveUnitsOrMore"] = -10.0 florinaPrimOweights["nearestEnemyDistance"] = -.2 # defensive weights florinaPrimDweights["terrainDefBonus"] = 5.0 florinaPrimDweights["terrainAvoidBonus"] = 5.0 florinaPrimDweights["expectedDeath"] = -500.0 florinaPrimDweights["expectedKill"] = 1.0 florinaPrimDweights["damageGiven"] = 1.0 florinaPrimDweights["damageTaken"] = -5.0 florinaPrimDweights["bossDead"] = 50.0 florinaPrimDweights["allEnemiesDead"] = 100.0 florinaPrimDweights["numArchersInRange"] = -20.0 florinaPrimDweights["numAxeUsersInRange"] = -3.0 florinaPrimDweights["numLanceUsersInRange"] = -1.0 florinaPrimDweights["numSwordUsersInRange"] = -.2 florinaPrimDweights["bossInRangeWhileEnemiesStillAlive"] = -10.0 florinaPrimDweights["bossInRangeWhileEnemiesAllDead"] = -5.0 florinaPrimDweights["inRangeOfOneUnit"] = -1.0 florinaPrimDweights["inRangeOfTwoUnits"] = -3.0 florinaPrimDweights["inRangeOfThreeUnits"] = -5.0 florinaPrimDweights["inRangeOfFourUnits"] = -6.0 florinaPrimDweights["inRangeOfFiveUnitsOrMore"] = -15.0 florinaPrimDweights["nearestEnemyDistance"] = 1.0 florinaStats = stats(17, 5, 7, 9, 7, 4, 4, 4, 7) florina = character("Florina", "PegKnight", slimLance, None, False, False, florinaStats, 17, florinaPrimOweights, florinaPrimDweights, florinaSecOweights, florinaSecDweights) #enemies #L1 Brigands L1BrigandPrimOweights = util.Counter() L1BrigandPrimDweights = util.Counter() L1BrigandSecOweights = None L1BrigandSecDweights = None L1BrigandStats = stats(20, 3, 1, 5, 0, 3, 0, 12, 5) brigand1 = character("Brig1", "Brigand", ironAxe, None, True, False, L1BrigandStats, 20, L1BrigandPrimOweights, L1BrigandPrimDweights, L1BrigandSecOweights, L1BrigandSecDweights) #L2 Brigands L2BrigandPrimOweights = util.Counter() L2BrigandPrimDweights = util.Counter() L2BrigandSecOweights = None L2BrigandSecDweights = None L2BrigandStats = stats(21, 4, 2, 5, 0, 3, 0, 12, 5) brigand2 = character("Brig2", "Brigand", ironAxe, None, True, False, L2BrigandStats, 21, L2BrigandPrimOweights, L2BrigandPrimDweights, L2BrigandSecOweights, L2BrigandSecDweights) brigand3 = character("Brig3", "Brigand", ironAxe, None, True, False, L2BrigandStats, 21, L2BrigandPrimOweights, L2BrigandPrimDweights, L2BrigandSecOweights, L2BrigandSecDweights) #Mercs mercPrimOweights = util.Counter() mercPrimDweights = util.Counter() mercSecOweights = None mercSecDweights = None mercenaryStats = stats(16, 4, 7, 5, 0, 3, 0, 9, 5) merc1 = character("Merc1", "Mercenary", ironSword, None, True, False, mercenaryStats, 16, mercPrimOweights, mercPrimDweights, mercSecOweights, mercSecDweights) merc2 = character("Merc2", "Mercenary", ironSword, None, True, False, mercenaryStats, 16, mercPrimOweights, mercPrimDweights, mercSecOweights, mercSecDweights) #Archers archerPrimOweights = util.Counter() archerPrimDweights = util.Counter() archerSecOweights = None archerSecDweights = None archerStats = stats(18, 1, 3, 3, 0, 3, 0, 7, 5) archer1 = character("Archer1", "Archer", ironBow, None, True, False, archerStats, 18, archerPrimOweights, archerPrimDweights, archerSecOweights, archerSecDweights) archer2 = character("Archer2", "Archer", ironBow, None, True, False, archerStats, 18, archerPrimOweights, archerPrimDweights, archerSecOweights, archerSecDweights) #Migal migalPrimOweights = util.Counter() migalPrimDweights = util.Counter() migalSecOweights = None migalSecDweights = None migalStats = stats(25, 7, 3, 5, 2, 5, 0, 12, 5) migal = character("Migal", "Brigand", steelAxe, None, True, True, migalStats, 25, migalPrimOweights, migalPrimDweights, migalSecOweights, migalSecDweights) #initialize characters on map mapCharacters[9][2] = kent mapCharacters[8][4] = sain mapCharacters[6][3] = lyn mapCharacters[6][5] = wil mapCharacters[4][4] = florina mapCharacters[7][8] = archer1 mapCharacters[4][8] = brigand2 mapCharacters[8][13] = brigand1 mapCharacters[3][11] = archer2 mapCharacters[2][12] = brigand3 mapCharacters[6][14] = merc1 mapCharacters[0][11] = merc2 mapCharacters[0][13] = migal return mapCharacters
from password import password import pygame.mixer from pygame.mixer import Sound from signal import pause pygame.mixer.init() pot = MCP3008(channel=0) u_line = LED(23) l_line = LED(22) s_line = Button(17) m_line = Button(27) unlock = Sound("samples/drum_roll.wav") lock = Sound("samples/misc_burp.wav") c = character('A', 4.0) p1 = password([]) p1.add_character(c) c = character('C', 3.0) p1.add_character(c) c = character('A', 3.0) p1.add_character(c) print("****** twiddle lock ******") mode = 'S' while True: if m_line.is_active: if mode == 'U': mode = 'S' elif mode == 'S': mode = 'U'
def gameLoop(): #Initialize gameQuit boolean that breaks the loop gameQuit = False while not gameQuit: level = 1 reset = False global generated global player r_down = False while not reset: reset = False events = pygame.event.get() for event in events: if event.type == pygame.QUIT or ( event.type == pygame.KEYDOWN and event.key == pygame.K_F4 and (pygame.K_LALT or pygame.K_RALT)): pygame.quit() os._exit(1) if platform == 'linux': keys = { pygame.K_UP: (player.y - 1, player.x), pygame.K_DOWN: (player.y + 1, player.x), pygame.K_LEFT: (player.y, player.x - 1), pygame.K_RIGHT: (player.y, player.x + 1) } elif platform == 'win32': keys = { pygame.K_UP: (player.y - 1, player.x), pygame.K_DOWN: (player.y + 1, player.x), pygame.K_LEFT: (player.y, player.x - 1), pygame.K_RIGHT: (player.y, player.x + 1) } for key, cont in keys.items(): y, x = cont if event.type == pygame.KEYDOWN and event.key == key and const.mape[ y][x]: player.move(x, y) player.tile.discover() if player.tile.content == "Boss": rom1.boss(level) player.tile.content = "Defeated_Boss" if player.tile.content == "Mob": rom1.mob(level) player.tile.content = None if event.type == pygame.KEYDOWN and event.key == pygame.K_r: clrMap() level = 1 del player player = ch.character() reset = True if player.tile: if player.tile.content: if event.type == pygame.KEYDOWN and event.key == pygame.K_e: if player.tile.content == "Defeated_Boss": level += 1 player.move(14, 7) clrMap() if level == 4: rom1.boss(level) if player.tile.content == "Shop": menuMarchand(player) if player.tile.content == "Blacksmith": menuForgeron(player) if not (generated or level == 4): generateMap(level) draw() if level == 4: gameQuit = True reset = True clrMap()
import store, character, item potion = item.item(name='potion', value=10, health_up=5) super_potion = item.item(name='super_potion', value=20, health_up=10) player_inventory = {potion: 2, super_potion: 2} store_inventory = {potion: 10, super_potion: 10} player = character.character(name="Bob", max_health=20, inventory=player_inventory, stat_attack=3, stat_defence=1, gold=20) wraith = character.character(name="Wraith", max_health=10, inventory=player_inventory, stat_attack=2, stat_defence=1, gold=5) mouse = character.character(name="mouse", max_health=1, inventory=player_inventory, stat_attack=1, stat_defence=0, gold=0) rat = character.character(name="rat", max_health=3,