示例#1
0
def select_all():
    pokemons = []
    sql = "SELECT * FROM pokemons"
    results = run_sql(sql)
    for row in results:
        nurse = nurse_repository.select(row['nurse_id'])
        trainer = trainer_repository.select(row['trainer_id'])
        pokemon = Pokemon(row['nickname'], row['species'], row['type'],
                          row['dob'], trainer, row['status'], row['id'])
        pokemon.assign_nurse(nurse)
        pokemons.append(pokemon)
    return (pokemons)
def update_pokemon(id):
    pokemon = pokemon_repository.select(id)
    name = request.form["name"]
    trainer = request.form['trainer']
    species = request.form['species']
    hatched = request.form['hatched']
    nurse_id = request.form['nurse_id']
    nurse = nurse_repository.select(nurse_id)
    notes = request.form['notes']
    pokemon = Pokemon(name, trainer, species, hatched, nurse, notes)
    pokemon.id = id
    pokemon_repository.update(pokemon)
    return redirect("/pokemons/index")
示例#3
0
def select(id):
    pokemon = None
    sql = "SELECT * FROM pokemons WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        nurse = nurse_repository.select(result['nurse_id'])
        trainer = trainer_repository.select(result['trainer_id'])
        pokemon = Pokemon(result['nickname'], result['species'],
                          result['type'], result['dob'], trainer,
                          result['status'], result['id'])
        pokemon.assign_nurse(nurse)
    return pokemon
示例#4
0
def create_db():
    data_filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 "pokemondata.json")
    if not os.path.exists(data_filepath):
        return "Pokemon datafile is not present"

    # Data to initialize database with
    with open(data_filepath, 'r') as f:
        pokemon_data = json.load(f)

    # Delete database file if it exists currently
    if os.path.exists("pokemon.sqlite"):
        os.remove("pokemon.sqlite")

    # Create the database
    db.create_all()

    # iterate over the pokemons and populate the database
    for pokemon in pokemon_data:
        p = Pokemon(name=pokemon.get("name"),
                    id=pokemon.get("id"),
                    image=pokemon.get("image"))

        # Add the types for the pokemon
        for pokemon_type in pokemon.get("types"):
            t = PokemonType.query.filter(
                PokemonType.p_type == pokemon_type).one_or_none()
            if t is None:
                t = PokemonType(p_type=pokemon_type)
            p.types.append(t)
        db.session.add(p)

    db.session.commit()
示例#5
0
def edit_pokemon(id):
    nickname = request.form['nickname']
    species = request.form['species']
    type = request.form['type']
    dob = request.form['dob']
    trainer_id = request.form['trainer_id']
    status = request.form['status']
    nurse_id = request.form['nurse_id']

    trainer = trainer_repository.select(trainer_id)
    nurse = nurse_repository.select(nurse_id)
    pokemon = Pokemon(nickname, species, type, dob, trainer, status, id)
    pokemon.assign_nurse(nurse)

    pokemon_repository.update(pokemon)
    return redirect('/pokemon')
示例#6
0
def select(id):
    pokemon = None
    sql = "SELECT * FROM pokemons WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        pokemon = Pokemon(result['name'], result['trainer'], result['species'], result['hatched'], result['nurse_id'], result['notes'], result['id'])
    return pokemon 
示例#7
0
def select_all():
    pokemons = []

    sql = "SELECT * FROM pokemons"
    results = run_sql(sql)
    for row in results:
        nurse = nurse_repository.select(row['nurse_id'])
        pokemon = Pokemon(row['name'], row['trainer'], row['species'], row['hatched'], nurse, row['notes'], row['id'])
        pokemons.append(pokemon)
    return pokemons
示例#8
0
def search(category, search):
    pokemons = []
    if category == "nickname":
        sql = "SELECT * FROM pokemons WHERE nickname = %s"
    elif category == "type":
        sql = "SELECT * FROM pokemons WHERE type = %s"
    elif category == "species":
        sql = "SELECT * FROM pokemons WHERE species = %s"
    elif category == "status":
        sql = "SELECT * FROM pokemons WHERE status = %s"
    values = [search]
    results = run_sql(sql, values)
    for row in results:
        nurse = nurse_repository.select(row['nurse_id'])
        trainer = trainer_repository.select(row['trainer_id'])
        pokemon = Pokemon(row['nickname'], row['species'], row['type'],
                          row['dob'], trainer, row['status'], row['id'])
        pokemon.assign_nurse(nurse)
        pokemons.append(pokemon)
    return pokemons
def create_pokemon():
    name = request.form["name"]
    trainer = request.form["trainer"]
    species = request.form["species"]
    hatched = request.form["hatched"]
    nurse_id = request.form["nurse_id"]
    nurse = nurse_repository.select(nurse_id)
    notes = request.form["notes"]
    new_pokemon = Pokemon(name, trainer, species, hatched, nurse, notes)
    pokemon_repository.save(new_pokemon)
    return redirect('/pokemons/index')
示例#10
0
    def generate(self, page_num):
        pokemon_list = []

        for i in range(1, self.page_limit + 1):
            multiplier = int(page_num) - 1
            pokemon = i + (multiplier * self.page_limit)
            pokemon_list.append(Pokemon().set_pokemon(pokemon))

            if pokemon == self.last_pokemon_id:
                break

        return pokemon_list
示例#11
0
class TestPokemon(unittest.TestCase):
    def setUp(self):
        trainer = Trainer("Ash", 259)
        self.pokemon = Pokemon("Seed Backman", "Bulbasaur", "Grass",
                               "25/09/1990", trainer, 'burned')

    def test_pokemon_has_nickname(self):
        self.assertEqual("Seed Backman", self.pokemon.nickname)

    def test_pokemon_has_species(self):
        self.assertEqual("Bulbasaur", self.pokemon.species)

    def test_pokemon_has_type(self):
        self.assertEqual("Grass", self.pokemon.type)

    def test_pokemon_has_dob(self):
        self.assertEqual("25/09/1990", self.pokemon.dob)

    def test_pokemon_has_trainer_name(self):
        self.assertEqual("Ash", self.pokemon.trainer.name)

    def test_pokemon_has_trainer_number(self):
        self.assertEqual(259, self.pokemon.trainer.number)

    def test_pokemon_has_status(self):
        self.assertEqual('burned', self.pokemon.status)

    def test_pokemon_before_nurse(self):
        self.assertEqual(None, self.pokemon.nurse)

    def test_assign_nurse(self):
        nurse = Nurse('Joy', 'fire')
        self.pokemon.assign_nurse(nurse)
        self.assertEqual(nurse, self.pokemon.nurse)

    def test_get_nurse_name(self):
        nurse = Nurse('Joy', 'fire')
        self.pokemon.assign_nurse(nurse)
        self.assertEqual('Joy', self.pokemon.nurse.name)
示例#12
0
    def get_method_one_pokemon(self, frame) -> Pokemon:
        if frame in self.cached_method_1:
            return self.cached_method_1[frame]

        current_frame = frame
        first_call = self.call(current_frame)
        current_frame += 1
        second_call = self.call(current_frame)
        current_frame += 1
        third_call = self.call(current_frame)
        current_frame += 1
        fourth_call = self.call(current_frame)

        pid = second_call + first_call

        nature_value = int(pid, 16) % 25

        while nature_value > 24:
            nature_value -= 25

        nature = [
            "Hardy", "Lonely", "Brave", "Adamant", "Naughty", "Bold", "Docile",
            "Relaxed", "Impish", "Lax", "Timid", "Hasty", "Serious", "Jolly",
            "Naive", "Modest", "Mild", "Quiet", "Bashful", "Rash", "Calm",
            "Gentle", "Sassy", "Careful", "Quirky"
        ][nature_value]

        ability = int(pid, 16) % 2

        big_hex = third_call + fourth_call
        big_binary = bin(int(big_hex, 16))[2:].zfill(32)

        def_iv = int(big_binary[1:6], 2)
        atk_iv = int(big_binary[6:11], 2)
        hp_iv = int(big_binary[11:16], 2)
        spdef_iv = int(big_binary[17:22], 2)
        spatk_iv = int(big_binary[22:27], 2)
        spe_iv = int(big_binary[27:32], 2)

        ivs = (hp_iv, atk_iv, def_iv, spatk_iv, spdef_iv, spe_iv)

        determinator = int(pid[-2:], 16)

        new_pokemon = Pokemon(frame, pid, ability, ivs, nature, determinator,
                              frame + 4, 0)

        self.cached_method_1[frame] = new_pokemon

        return new_pokemon
示例#13
0
 def createEntrenador(self, form):
     try:
         params = {"name": form["name"], "pokemons": form["pokemons"]}
     except Exception as e:
         return {
             "status": 400,
             "message": "Bad request, invalid parameters"
         }
     insert = {}
     insert["pokemons"] = {}
     poke = Pokemon()
     for x in range(1, int(params["pokemons"])):
         pokemon = poke.getPokemonApi()
         insert["pokemons"][str(pokemon["id"])] = {}
         insert["pokemons"][str(pokemon["id"])]["name"] = pokemon["name"]
         insert["pokemons"][str(
             pokemon["id"])]["experience"] = pokemon["base_experience"]
     insert["name"] = params["name"]
     save = self.db.db["entrenadores"].insert_one(insert)
     return {
         "status": 200,
         "message": "Coach and pokemons created",
         "id": str(save.inserted_id)
     }
示例#14
0
def generate_pokedex(file_name: str):
    """
    Load json and generate all class.

    :type file_name: pokedex json filepath
    """
    with open(file_name) as json_file:
        datas = json.load(json_file)
        print(datas)
        for pokemon_obj in datas:
            pokedex.add_pokemon(
                Pokemon(pokemon_obj['id'], pokemon_obj['identifier'],
                        pokemon_obj['height'], pokemon_obj['weight'],
                        pokemon_obj['order']))
    print("Pokedex loaded successfully !")
 def __nuevoPokemon(self, id, pokemonParams):
     pokemon = Pokemon(id, pokemonParams["nombre"], pokemonParams["tipo"],
                       pokemonParams["subtipo"], pokemonParams["habitad"],
                       pokemonParams["nivel"], pokemonParams["habilidades"])
     return pokemon
示例#16
0
    def get_method_j_pokemon(
            self,
            frame,
            encounter_area: int,
            synchronize_nature: str = None) -> Tuple[Pokemon, int] or None:
        current_frame = frame

        if encounter_area >= 1:
            encounter_call = int(self.call(current_frame), 16)
            if encounter_area == 1:
                target_slots = [60, 90, 95, 99, 100]
            elif encounter_call / 656 >= (encounter_area - 1) * 25:
                return None
            else:
                if encounter_area >= 3:
                    target_slots = [40, 80, 95, 99, 100]
                else:
                    target_slots = [60, 90, 95, 99, 100]
        else:
            target_slots = [20, 40, 50, 60, 70, 80, 85, 90, 94, 98, 99, 100]

        slot = 255

        if encounter_area >= 2:
            slots_call = int(self.call(current_frame + 1), 16)
        else:
            slots_call = int(self.call(current_frame), 16)

        for x in range(0, len(target_slots)):
            if slots_call / 656 < target_slots[x]:
                slot = x
                break

        if encounter_area >= 1:
            current_frame += 1

        if encounter_area >= 2:
            current_frame += 1

        current_frame += 1

        call = self.call(current_frame)

        if synchronize_nature is not None:
            if int(call, 16) >> 15 == 0:
                nature_value = [
                    "Hardy", "Lonely", "Brave", "Adamant", "Naughty", "Bold",
                    "Docile", "Relaxed", "Impish", "Lax", "Timid", "Hasty",
                    "Serious", "Jolly", "Naive", "Modest", "Mild", "Quiet",
                    "Bashful", "Rash", "Calm", "Gentle", "Sassy", "Careful",
                    "Quirky"
                ].index(synchronize_nature)
            else:
                current_frame += 1
                call = self.call(current_frame)
                nature_value = int(call, 16) // 0xA3E
        else:
            nature_value = int(call, 16) // 0xA3E

        nature = [
            "Hardy", "Lonely", "Brave", "Adamant", "Naughty", "Bold", "Docile",
            "Relaxed", "Impish", "Lax", "Timid", "Hasty", "Serious", "Jolly",
            "Naive", "Modest", "Mild", "Quiet", "Bashful", "Rash", "Calm",
            "Gentle", "Sassy", "Careful", "Quirky"
        ][nature_value]

        call_1 = current_frame + 1
        call_2 = current_frame + 2

        pid = int(self.call(call_2), 16) << 16 | int(self.call(call_1), 16)

        while pid % 25 != nature_value:
            call_1 += 2
            call_2 += 2

            pid = int(self.call(call_2), 16) << 16 | int(self.call(call_1), 16)

        pid = hex(pid)[2:]

        ability = int(pid, 16) % 2

        while len(pid) < 8:
            pid = "0" + pid

        item_determinator = int(pid[-2:], 16)

        big_hex = self.call(call_1 + 2) + self.call(call_2 + 2)
        big_binary = bin(int(big_hex, 16))[2:].zfill(32)

        def_iv, atk_iv, hp_iv = int(big_binary[1:6],
                                    2), int(big_binary[6:11],
                                            2), int(big_binary[11:16], 2)
        spdef_iv, spatk_iv, spe_iv = int(big_binary[17:22],
                                         2), int(big_binary[22:27],
                                                 2), int(big_binary[27:32], 2)

        ivs = (hp_iv, atk_iv, def_iv, spatk_iv, spdef_iv, spe_iv)

        occid = call_1

        method_one = self.get_method_one_pokemon(occid)

        while method_one.nature != nature:
            occid += 1
            method_one = self.get_method_one_pokemon(occid)

        occid_item = occid + 4

        return Pokemon(frame, pid, ability, ivs, nature, item_determinator,
                       occid,
                       int(self.call(occid_item), 16) % 100), slot
示例#17
0
        while self.loop:
            if self.page is None:
                self.page = self.allPages['Menu']
            self.page.draw()

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    gamequit()
                elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 3:
                    print(event.pos)
                elif event.type == CHANGEPAGE:
                    self.page = self.allPages[event.page]
                    self.page.last_page = event.source
                else:
                    self.page.event(event)

            self.page.update()

            # Ajout du fond dans la fenêtre
            self.page.display(self.screen)
            # Actualisation de l'affichage
            pygame.display.update()
            # 10 fps
            clock.tick(10)


if __name__ == '__main__':
    Pokemon.init_class()
    game = Game('Poké-KAIRA')
    game.infinite_loop()
示例#18
0
 def setUp(self):
     self.pokemon_1 = Pokemon('Sparky', 'Ritchie', 'Pikachu', '15/6/2017')
示例#19
0
 def setUp(self):
     trainer = Trainer("Ash", 259)
     self.pokemon = Pokemon("Seed Backman", "Bulbasaur", "Grass",
                            "25/09/1990", trainer, 'burned')
示例#20
0
 def get_pokemon(self, id):
     return Pokemon().set_pokemon(id)
示例#21
0
from models.trainer import Trainer
from models.nurse import Nurse

import repositories.pokemon_repository as pokemon_repository
import repositories.trainer_repository as trainer_repository
import repositories.nurse_repository as nurse_repository

pokemon_repository.delete_all()
nurse_repository.delete_all()
# trainer_repository.delete_all()

# trainer_1 = Trainer('Ash', '2 Pallet Town', 32356)
# trainer_2 = Trainer('Misty', 'Cerulean Gym', 78232)
nurse_1 = Nurse('Joy')
nurse_2 = Nurse('Joye')
pokemon_1 = Pokemon('Sparky', 'trainer_1', 'Pikachu', '15/6/2017', nurse_1,
                    "Crushed by Snorlax")
pokemon_2 = Pokemon('Frankie', 'trainer_2', 'Psyduck', '12/1/2016', nurse_1,
                    "Burnt by Charizard")
pokemon_3 = Pokemon('Sally', 'trainer_2', 'Seel', '15/8/2015', nurse_2,
                    "Shocked by Pikachu")

#assign nurse to pokemon before running console.py

# trainer_repository.save(trainer_1)
# trainer_repository.save(trainer_2)
nurse_repository.save(nurse_1)
nurse_repository.save(nurse_2)

pokemon_repository.save(pokemon_1)
pokemon_repository.save(pokemon_2)
pokemon_repository.save(pokemon_3)
示例#22
0
from models.trainer import Trainer
import repositories.nurse_repository as nurse_repository
import repositories.pokemon_repository as pokemon_repository
import repositories.trainer_repository as trainer_repository

# pokemon_repository.delete_all()
# nurse_repository.delete_all()
# trainer_repository.delete_all()



nurse_1 = Nurse("Joy", "Fire")
nurse_repository.save(nurse_1)
trainer = Trainer("Simon", 12345)
trainer_repository.save(trainer)


pokemon = Pokemon('Seed Backman', 'Bulbasaur', 'Grass', '25/09/1990', trainer , 'burned')

pokemon.assign_nurse(nurse_1)
pokemon_repository.save(pokemon)

trainer.name = 'Simondovich'



trainer_repository.update(trainer)

nurse_1.name = "Betsy"

nurse_repository.update(nurse_1)
示例#23
0
def test_instantiate_pokemon():
    pokemon = Pokemon(1, "ivysaur", 10, 130, 1)
    assert pokemon.id == 1
    assert pokemon.name == "ivysaur"