示例#1
0
def get():
    """
	Return the next character in textFile.
	"""
    global lastIndex, sourceIndex, lineIndex, colIndex

    sourceIndex += 1  # increment the index in textFile

    # maintain the line count
    if sourceIndex > 0:
        if textFile[sourceIndex - 1] == "\n":

            # The previous character in textFile was a newline
            # character.  So... we're starting a new line.
            # Increment lineIndex and reset colIndex.

            lineIndex += 1
            colIndex = -1

    colIndex += 1

    if sourceIndex > lastIndex:
        # We've read past the end of textFile.
        # Return the ENDMARK character.
        char = Character(ENDMARK, lineIndex, colIndex, sourceIndex, textFile)
    else:
        c = textFile[sourceIndex]
        char = Character(c, lineIndex, colIndex, sourceIndex, textFile)

    return char
示例#2
0
    def get(self):
        """
        Return the next character in sourceText.
        """
        global lastIndex, sourceIndex, lineIndex, colIndex

        sourceIndex += 1  # increment the index in sourceText

        # maintain the line count
        if sourceIndex > 0:
            if sourceText[sourceIndex - 1] == "\n":
                #-------------------------------------------------------
                # The previous character in sourceText was a newline
                # character.  So... we're starting a new line.
                # Increment lineIndex and reset colIndex.
                #-------------------------------------------------------
                lineIndex += 1
                colIndex = -1

        colIndex += 1

        if sourceIndex > lastIndex:
            # We've read past the end of sourceText.
            # Return the ENDMARK character.
            char = Character(self.ENDMARK, lineIndex, colIndex, sourceIndex,
                             sourceText)
        else:
            c = sourceText[sourceIndex]
            char = Character(c, lineIndex, colIndex, sourceIndex, sourceText)

        return char
示例#3
0
    def map(self):
        """
            Create map
        """
        with open("land.txt", "r") as f:
            i = 0
            for line in f.readlines():
                j = 0
                for x in range(15):
                    self.tab_land[(i, j)] = line[x]
                    if line[x] == 'S':
                        character = Character(self.window)
                        character.macgiver(j, i)
                        position_mg = [j, i]
                    if line[x] == 'E':
                        characters = Character(self.window)
                        characters.guardian(j, i)
                        self.guard_position = (j, i)
                    if line[x] == 'W':
                        self.walls(j, i)
                    if line[x] == 'P':
                        self.path_array.append((j * 20, i * 20))
                    j += 1

                i += 1
        self.generate_object()
        return position_mg
示例#4
0
    def __init__(self,algorithm):
        '''

        :param path: directory path for each character
        :param algorithm: otsu or adaptative
        '''
        #list of characters containing a list of each photo example
        self.models=[]

        for subdir, dirs, files in os.walk('modelos'):
            for file in files:
                name= os.path.split(subdir)[1]
                if name =='K':
                    self.models.append(Character(10, os.path.join(subdir, file), algorithm))
                else:
                    self.models.append(Character(int(name), os.path.join(subdir, file), algorithm))
示例#5
0
 def __init__(self, objects, characterSpawn, size, background, filename):
     self.objects = objects
     self.filename = filename
     self.character = Character(characterSpawn)  # TODO: use characterSpawn
     self.objects.append(self.character)
     self.camera = Camera(size * 24, background)
     self.camera.moveToCenter(self.character.hitBox.center)
示例#6
0
def appStarted(app):
    app.gameStatus = 'start'
    app.ff = Character()
    (app.width, app.height) = (960, 720)
    app.platforms = []
    app.enemies = []
    app.bots = []
    splashScreen(app)
    generateMap(app, app.width / 2, 300)
    app.projectiles = []
    app.mouseAng = 0
    app.charData = []
    app.chaserData = []
    splashScreen(app)
    app.bestScore = 0
    characterPage(app)
    app.gameCounter = 0
    app.rp = app.hpE.lv + app.regenE.lv + app.dmgE.lv + app.ammoE.lv + app.grenadeE.lv
    gameOverPage(app)
    createChaser(app)

    for i in range(0, 20):
        app.bots.append(Bot(500, 800 + i * 600))
    app.ff.hp = 100 + 30 * app.hpE.lv
    app.ff.regen = 0 + 3 * app.regenE.lv
    app.ff.dmg = 10 + 3 * app.dmgE.lv
    app.ff.ammoCount = 30 + 12 * app.ammoE.lv
    app.ff.grenadeCount = 5 + 2 * app.grenadeE.lv
示例#7
0
    def __init__(self):
        self.screen = pg.display.set_mode((W, H))
        self.camera = Camera(map_x_size, map_y_size)  # Luego sustituir cons self.map.width, self.map.height

        # We create the sprite groups for the specific level and add our character and enemy class to it
        self.all_sprites = pg.sprite.Group(); self.events = pg.sprite.Group(); self.objects = pg.sprite.Group()
        self.platforms = pg.sprite.Group(); self.characters = pg.sprite.Group(); self.enemies = pg.sprite.Group()

        self.character = Character(); self.enemy_wolf = Wolf();
        self.all_sprites.add(self.character, self.enemy_wolf)
        self.characters.add(self.character); self.enemies.add(self.enemy_wolf);

        # We add each object that will appear on the map

        for i in Floor:
            map_floor = CreateFloor(*i)
            self.platforms.add(map_floor)
            self.all_sprites.add(map_floor)

        for i in Fireballs:
            fireball = CreateFireball(*i)
            self.events.add(fireball)

        for i in Platforms:
            platform = CreatePlatform(*i)
            self.platforms.add(platform)

        for i in Objects:
            fb_exit = CreateFireballExit(*i)
            self.objects.add(fb_exit)
示例#8
0
def main():
    N = eval(input("Please enter the dimensions for your maze (Your maze will be N x N) "))
    myMaze = Maze(N)

    print("The Red Square is the start")
    print("The Yellow Square is the key")
    print("The Green Square is the end")
    print("The Blue Circles represent the path to the key")
    print("The Black Circles represent the path to the end")
    print("The top left Cell is (0,0), x increases as you move right and y increases as you move down")
    print("The top left Cell is (0,0), x increases as you move right and y increases as you move down")

    myMaze.generateMaze()
    myMaze.explore(myMaze.entrance[0],myMaze.entrance[1])
    #myMaze.printSolution()
    myMaze.Draw()

    myCharacter = Character(myMaze)
    print("You have " + str(len(myMaze.SolutionStack)-2) + " steps to reach the ending")
    print("You are the pink circle, you may use the arrow keys to move")
    gameLoop(myMaze,myCharacter)

    replay = input("Would you like to play again (Y/N)")
    if replay == "Y":
        myMaze.win.close()
        main()
    elif replay == "N":
        myMaze.win.close()
        quit()
    myMaze.win.close()
示例#9
0
 def play(self, ai, difficult=False):
     self.easyAI.destroy()
     self.hardAI.destroy()
     self.ai = None
     self.cTrav = CollisionTraverser()
     self.coll = CollisionHandlerEvent()
     self.coll.addInPattern("%fn-into-%in")
     self.clock = ClockObject()
     terrain = GeoMipTerrain("worldTerrain")
     terrain.setHeightfield("heightMap.png")
     terrain.setColorMap("colormap.png")
     terrain.setBruteforce(True)
     root = terrain.getRoot()
     root.reparentTo(self.render)
     root.setSz(1)
     terrain.generate()
     self.player = Character("models/panda-model", 0.05, (300, 300, 0),
                             self.render, {"walk": "models/panda-walk4"},
                             self, self.path, 200, "player")
     self.addControls()
     self.loadUI()
     self.startTasks()
     self.accept("proj-into-player", self.player.changeLife, [-1])
     self.others = dict()
     self.roundOv = False
     self.taskMgr.add(self.update, "Update")
     self.gameOver = False
     if ai:
         self.aiBattle(difficult)
    def gameInit(self):
        # make game board 0~16
        self.boards.append(Board(0, 1, "정문", self.texArr))
        self.boards.append(Board(1, 0, "넉터", self.texArr))
        self.boards.append(Board(2, 0, "제6 공학관", self.texArr))
        self.boards.append(Board(3, 0, "인문관", self.texArr))
        self.boards.append(Board(4, 0, "대학본부", self.texArr))
        self.boards.append(Board(5, 0, "제2 공학관", self.texArr))
        self.boards.append(Board(6, 0, "문창회관", self.texArr))
        self.boards.append(Board(7, 0, "자연대 연구실험동", self.texArr))
        self.boards.append(Board(8, 0, "새벽벌도서관", self.texArr))
        self.boards.append(Board(9, 0, "사회관", self.texArr))
        self.boards.append(Board(10, 0, "금정회관", self.texArr))
        self.boards.append(Board(11, 0, "법학관", self.texArr))
        self.boards.append(Board(12, 0, "테니스장", self.texArr))
        self.boards.append(Board(13, 0, "제 1도서관", self.texArr))
        self.boards.append(Board(14, 0, "무지개문", self.texArr))
        self.boards.append(Board(15, 0, "건설관", self.texArr))

        self.dice = Dice(self.texArr)

        # player setting
        for player_no in range(4):
            self.player.append(Player(player_no))

        # character setting
        for player_no in range(4):
            self.characters.append(Character(self, player_no, player_no))

        for build_no in range(16):
            self.buildings.append((Building(build_no, self.texArr)))
示例#11
0
def load_user(name: str) -> Character:
    """
    Load the saved file for old user

    PARAM: name, string
    PRE CONDITION: User must have saved character file
    POST CONDITION: Succesfully load json file
    RETURN: Returns character that contains character information
    """

    user_continue = True

    while user_continue is True:

        try:
            filename = name + ".json"
            with open(filename, 'r') as f_obj:
                user = json.load(f_obj)

        except FileNotFoundError:
            return generate_character()
        else:
            player_character = Character.Character(user["name"], user["x_coord"], user["y_coord"])
            player_character.set_hp(user["hp"])
            print("Welcome Back!", user["name"], "hope you are ready!!!!")
            return player_character
示例#12
0
 def defineCharacter(self,num):
     if num == 1:
         self.jugador = JugadorAdapter()
         return self.jugador
     elif num == 2:
         self.charac = Character()
         return self.charac
示例#13
0
    def singlePlayerInit(self):
        self.score += 1
        self.scoreText = self.font.render("Score: " + str(self.score), True,
                                          (255, 255, 255))
        # self.scoreSurface = pygame.Surface((280, 60))
        # pygame.draw.rect(self.scoreSurface, (255, 255, 255), (0,0,280,60), 2)
        # self.scoreSurface.blit(self.scoreText, (6, 6))
        self.scoreSurfaceRect = (1000, 600)

        self.maze = MazeRecursive(9, 16)
        row = random.randint(0, len(self.maze.board) - 1)
        col = random.randint(0, len(self.maze.board[0]) - 1)

        self.player = Character(row, col, self.maze.cellSize)
        self.playerGroup = pygame.sprite.GroupSingle(self.player)

        rowPsyco = random.randint(0, len(self.maze.board) - 1)
        colPsyco = random.randint(0, len(self.maze.board[0]) - 1)

        self.psycopath = Psycopath(rowPsyco, colPsyco, self.maze.cellSize,
                                   self.player, self.maze, "singlePlayer")
        self.psycopathGroup = pygame.sprite.GroupSingle(self.psycopath)

        self.darknessOn = True
        self.darkness = pygame.image.load("Resources/Darkness.png")
        w, h = self.darkness.get_size()
        self.darkness = pygame.transform.scale(self.darkness, (w * 2, h * 2))
        self.darknessRect = None
        self.darknessRectUpdate()
示例#14
0
    def __init__ (self):
        # Config
        self.tps_max = 100.0
        
        # Inicialization
        pygame.init()
        self.screen = pygame.display.set_mode((1280,720))
     
        self.tps_clock = pygame.time.Clock()
        self.tps_delta = 0.0

        self.player =  Character(self)

        while True:
            #Handle events
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit(0)
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    sys.exit(0)

            # Ticking:
            self.tps_delta += self.tps_clock.tick()/1000.0 # w sekundach 
            while self.tps_delta > 1/self.tps_max: # to w srodku wykonuje sie gdy minie 1/max_tps
                self.tps_delta -= 1/self.tps_max
                self.tick() #wywolanie tej funkcji nizej

            # Drawing:
            self.screen.fill((0,0,0))
            self.draw()    
            pygame.display.flip()
示例#15
0
    def update(self, task):
        self.lifeBar['value'] = self.player.currLife
        self.lifeBar.setValue()
        if self.ai is not None:
            self.aiLifebar['value'] = self.ai.currLife
            self.aiLifebar.setValue()
        while serverMsg.qsize() > 0:
            msg = serverMsg.get(False)
            try:
                print("received: ", msg, "\n")
                msg = msg.split()
                command = msg[0]
                if command == "myIDis":
                    self.myPID = msg[1]

                elif command == "newPlayer":
                    n = msg[1]
                    self.others[n] = Character("models/panda-model", 0.05, (300, 300, 0),
                                               self.render,
                                               {"walk": "models/panda-walk4"}, self,
                                               self.path, 200, "play2")
                    self.taskMgr.add(self.others[n].move, "Move" + n)
                elif command == "moved":
                    PID = msg[1]
                    if msg[2] == "y":
                        self.others[PID].moveY(int(msg[3]))
                    else:
                        self.others[PID].moveZ(int(msg[3]))
                elif command == "fired":
                    PID = msg[1]
                    self.others[PID].fire()
            except:
                print("rip")
            serverMsg.task_done()
        return Task.cont
示例#16
0
    def run(self, screen, snds, textures, fonts):
        self.barry = barry = Character(self.character, barry, textures, snds)

        self.sounds = sounds
        self.textures = textures
        clock = time.Clock()

        self.barry.game = self

        running = True
        while running:
            currTime = cTime()
            keys = key.get_pressed()

            for e in event.get():
                if e.type == QUIT:
                    quit()
                if e.type == KEYDOWN:
                    if e.key == K_ESCAPE:
                        running = False
                # 	if e.key == K_SPACE:
                # 		self.propel()
            screen.fill((0, 0, 0))
            if keys[K_SPACE]:
                self.up = True
            self.move()

        display.flip()
        clock.tick(60)
示例#17
0
def spawnHero(heroCoords=None):
    global hero, heroChar, heroBox, heroSpawned, inventorySpawned

    if heroCoords != None:
        hero.moveToFront()
        hero.x = heroCoords[0]
        hero.y = heroCoords[1]
    else:
        hero = sprite(charWalkCycleRight[0], 700, 453, "hero")
    hero.setHP(100)
    heroSpawned = True
    inventorySpawned = True

    if 'heroChar' in globals() or 'heroChar' in locals():
        pass
    else:
        heroChar = Character.Character()
        Sword = Weapon.Weapon("Sword", 260, 905,
                              "Sprites/BlueHairedHero/sword.png", "Weapon")
        Sword.assignInvSlot(1)
        heroChar.addDimensions(Sword.spriteImage.width,
                               Sword.spriteImage.height,
                               heroChar.availableSlot)
        heroChar.addToInventory(Sword)
        Sword.pickedUp = True
        itemList.append(Sword)
示例#18
0
        def page1_result(n_clicks, input_1, input_2, input_3, input_4, input_5,
                         input_6, input_7, input_8, input_9, input_10,
                         input_11):

            if 0 < n_clicks:
                tags_id = [
                    input_1, input_2, input_3, input_4, input_5, input_6,
                    input_7, input_8, input_9, input_10, input_11
                ]
                character = Character.Character(tags_id)
                output = app.layout.children[-1].children[-1]
                if character.empty_check():
                    answer, df = character.predict()
                    result = '당신은 {0}형 투자자입니다. 당신에게 맞는 포트폴리오를 확인해 보세요'.format(
                        answer)
                    pie = px.pie(df,
                                 names=df.columns[-1],
                                 values=df.columns[0])
                    output.children[0].children = result
                    if len(output.children) < 3:
                        fig = dcc.Graph(id='pie-chart')
                        fig.figure = pie
                        fig.figure.layout.paper_bgcolor = style[
                            'pie_chart_style']['backgroundColor']
                        output.children.append(fig)
                    output.style = style['pie_chart_style']
                    return output

                warning = '비어있는 항목이 있습니다! 전부 체크해 주세요'
                if 2 < len(output.children):
                    output.children = output.children[:-1]
                output.children[0].children = warning
                output.style = style['pie_chart_style']
                return output
示例#19
0
    def __init__(self):
        pathWork = os.getcwd()
        pathImg  = os.path.join(pathWork, "images")
        background = os.path.join(pathImg, "bg.jpg")
        self.background = pygame.image.load(background)
        self.View = Camera.View()
        self.bg = self.View.bgCropped
        self.myFont = pygame.font.SysFont("Calibri", 14)
        self.fpsSprite = pygame.sprite.Sprite()
        self.killSprite = pygame.sprite.Sprite()
        self.group = pygame.sprite.RenderUpdates(self.fpsSprite, self.killSprite)
        self.Clock = pygame.time.Clock()
        self.fpsTime = 0

        self.Character = Character.Character()
        self.charSprite = pygame.sprite.Sprite()
        self.charGroup = pygame.sprite.RenderUpdates(self.charSprite)
        self.kills = 0

        self.shooting = False
        self.mouse = (0,0)
        self.Shoot = Shots.Shoot()
        self.shotsGroup = pygame.sprite.RenderUpdates()

        self.Zombies = Zombies.Zombies()
        self.zombieGroup = pygame.sprite.RenderUpdates()

        self.Objects = Objects.Objects()
        self.objectgroup = pygame.sprite.RenderUpdates()

        self.moveTime = 0

        self.mouseSprite = pygame.sprite.Sprite()
        self.mouseSprite.image = pygame.image.load(os.path.join(pathImg, "crosshair.png"))
        self.mouseGroup = pygame.sprite.RenderUpdates(self.mouseSprite)
示例#20
0
def timeit():
    filename='test.dat'
    try:
        with open(filename, 'rb') as in_s:
            try:
                print "Read data from file"
                combat=pickle.load(in_s)
                char=combat.char
                mon=combat.mons
            except EOFError:
                pass
            else:
                pass#print 'READ: %s (%s)' % (o.name, o.name_backwards)
    except IOError:
        char=Character("Dingziran")
        mon=Monster("Goblin",10,1,1,1,1)
        combat=CombatSys(char,mon)
    finally:
        if in_s:
            in_s.close()
    n=10000
    t=clock()
    for _ in xrange(n):
        combat.combat()
        mon.spawn()
    t=clock()-t
    print '%ds combat using %f second'%(n,t)
示例#21
0
def main():
    check = 1
    still_enemies = True
    enemy_list = slime_generator()  # generate slime enemies
    n_enemies = len(enemy_list)

    # create player character
    p_name = input("Enter your name: ")
    player = Character.Character(p_name, 20)

    # opening messages
    print()
    print("Welcome, {}. You have {} health. Type 'Help' for commands.".format(
        player.name, player.c_health))
    print()

    if n_enemies == 1:
        print("Oh no! A slime has appeared!")
    else:
        print("Oh no! {} slimes have invaded!".format(n_enemies))

    # main game while loop
    while check != 0:
        # check if all enemies have been defeated
        if len(enemy_list) == 0:
            print("You win! All enemies have been defeated.")
            break

        for e in enemy_list:
            print("{},".format(e.name), "HP = {}".format(e.c_health))
        # request user input
        p_in = input("What would you like to do? ")
        check = command_checker(p_in.lower(), player, enemy_list)

        # test of Character methods
        """
        player.damage(21)
        player.healing(20)

        player.damage(40)
        player.healing(20) # should fail to heal
        player.revive(20)
        """

        # have enemies attack if player entered in valid input
        if check == 3:
            for e in enemy_list:
                e.normal_attack(
                    player
                )  # FIXME: will want to change to random move with diff enemies
                if player.knockout:
                    print("You blacked out!"
                          )  # FIXME: change to 'your team' later on
                    return
                else:
                    print("{} has {} health. \n".format(
                        player.name, player.c_health))

    return
示例#22
0
def enter():
    global character, mouse, map, monsters
    global items
    character = Character.Character()
    mouse = Mouse.Mouse()
    map = Map.Map()
    monsters = [Monster.Monster() for i in range(60)]
    items = [Item.Item() for i in range(2)]
示例#23
0
async def dnd(ctx, param):
    print('testing dnd')
    if param == 'party':
        #  for c in CON.CHARACTERS:
        
        c = CON.DYLON
        print('testing party')
        char = Character.Character(c)
    def init_data(self):
        self.characters = [Character(), Character(), Character()]
        self.characters[0].name = "Kerry"
        self.characters[1].name = "Jonothan"
        self.characters[
            2].name = "Azaroth, Destroyer of Gods and Devourer of Worlds"

        self.characters[0].player = "Liam"
        self.characters[1].player = "Travis"
        self.characters[2].player = "Tom"

        self.characters[0].level = 1
        self.characters[1].level = 6
        self.characters[2].level = 14

        self.characters[0].attr.str = 3
        self.characters[0].attr.dex = 17
示例#25
0
 def setUp(self):
     self.c = Character("bob")
     self.bar = Bar("Test")
     self.bar.add_box(Box(1))
     self.bar.add_box(Box(2))
     self.bar.add_box(Box(3))
     self.bar.add_box(Box(4))
     self.c.add_bar(self.bar)
示例#26
0
def run():
    pygame.init()    
    screen = pygame.display.set_mode(SCREEN_SIZE, 0,32)
    clock=pygame.time.Clock()
    round=0
    if len(sys.argv)!=1:
        filename= sys.argv[1]
        try:
            with open(filename, 'rb') as in_s:
                try:
                    #char = pickle.load(in_s)
                    #mon = pickle.load(in_s)
                    print "Read data from file"
                    combat=pickle.load(in_s)
                    combat.total=0
                    combat.win=0
                except EOFError:
                    pass
                else:
                    pass#print 'READ: %s (%s)' % (o.name, o.name_backwards)
        except IOError:
            char=Character("Dingziran")
            mon=M1(1)
            combat=CombatSys(char,mon)
    else:
        char=Character("Dingziran")
        mon=M1(1)
        combat=CombatSys(char,mon)
    while True:
        for event in pygame.event.get():
            if event.type ==QUIT:
                with open(filename,'wb') as out_s:
                    pickle.dump(combat,out_s)
                return
        time_passed=clock.tick(30)
        screen.fill((255, 255, 255))
        if round==3:
            round=0
            combat.combat()
        
        combat.render(screen)
        chooseMons(combat,screen)
        pygame.display.update()
        #combat.mons.spawn()
        round+=1
示例#27
0
 def __init__(self):
     self.screen = pygame.display.set_mode((800, 600))
     self.back = None
     self.player = Character.Character()
     self.font = pygame.font.SysFont('Comic Sans MS', 48)
     self.enemy = None
     self.clock = pygame.time.Clock()
     self.FPS = 30
     self.play_time = 0.0
示例#28
0
    def __init__(self):

        pygame.init()
        self.running = True
        self.screen = pygame.display.set_mode((width, height))
        self.graph = Graph(gridWidth, gridHeight)
        self.player = Character("placeholder name")
        pygame.display.set_caption("2047")
        self.savefile = shelve.open('savefile')
 def generate_characters(self):
     for i in self.preset_dic:
         name = i
         width = self.preset_dic[i][1]
         height = self.preset_dic[i][2]
         topleft = self.preset_dic[i][0]
         character = Character.Character(name, width, height, topleft, self._bl)
         self.characters.append(character)
         self.deploy(character)
示例#30
0
 def __init__(self, objects, characterSpawn, size, background):
     self.objects = objects
     self.characterSpawn = characterSpawn * 24
     self.character = Character(self.characterSpawn)
     self.objects.append(self.character)
     self.size = size * 24
     self.camera = Camera(self.size, background)
     self.camera.moveToCenter(self.character.hitBox.center)
     self.gameOver = False