寶可夢小隊代碼

以下是一個簡單的寶可夢小隊代碼示例,使用Python編寫。這個代碼模擬了一個包含寶可夢的小隊,並展示了如何添加、刪除和查看小隊中的寶可夢。

class Pokemon:
    def __init__(self, name, type, level):
        self.name = name
        self.type = type
        self.level = level

    def __str__(self):
        return f"{self.name} (Type: {self.type}, Level: {self.level})"

class PokemonSquad:
    def __init__(self):
        self.squad = []

    def add_pokemon(self, pokemon):
        if len(self.squad) < 6:
            self.squad.append(pokemon)
            print(f"{pokemon.name} has been added to the squad.")
        else:
            print("Squad is full! Cannot add more Pokemon.")

    def remove_pokemon(self, name):
        for pokemon in self.squad:
            if pokemon.name == name:
                self.squad.remove(pokemon)
                print(f"{name} has been removed from the squad.")
                return
        print(f"{name} is not in the squad.")

    def show_squad(self):
        if not self.squad:
            print("The squad is empty.")
        else:
            print("Current Squad:")
            for pokemon in self.squad:
                print(pokemon)

# 示例使用
squad = PokemonSquad()

pikachu = Pokemon("Pikachu", "Electric", 25)
charmander = Pokemon("Charmander", "Fire", 15)
bulbasaur = Pokemon("Bulbasaur", "Grass", 12)

squad.add_pokemon(pikachu)
squad.add_pokemon(charmander)
squad.add_pokemon(bulbasaur)

squad.show_squad()

squad.remove_pokemon("Charmander")

squad.show_squad()

代碼說明:

  1. Pokemon類:表示一個寶可夢,包含名稱、屬性和等級。
  2. PokemonSquad類:表示一個寶可夢小隊,最多可以包含6隻寶可夢。
  3. add_pokemon方法:將寶可夢添加到小隊中,如果小隊已滿則無法添加。
  4. remove_pokemon方法:從小隊中移除指定名稱的寶可夢。
  5. show_squad方法:顯示當前小隊中的所有寶可夢。

輸出示例:

Pikachu has been added to the squad.
Charmander has been added to the squad.
Bulbasaur has been added to the squad.
Current Squad:
Pikachu (Type: Electric, Level: 25)
Charmander (Type: Fire, Level: 15)
Bulbasaur (Type: Grass, Level: 12)
Charmander has been removed from the squad.
Current Squad:
Pikachu (Type: Electric, Level: 25)
Bulbasaur (Type: Grass, Level: 12)

這個代碼可以作為一個基礎框架,進一步擴展以支持更多功能,例如寶可夢對戰、屬性相剋等。

周公算命熱門測算:

周公算命易經六十四卦四柱八字天罡地煞周易算命六壬神課梅花易數算命文章
姓名測試男孩名字大全女孩名字大全起名大全寶寶起名成人改名公司起名店鋪起名康熙字典百家姓
抽籤占卜觀音靈籤呂祖靈籤黃大仙靈籤關帝靈籤天后靈籤車公靈籤佛祖靈籤周公靈籤土地公靈籤北帝靈籤月老靈籤月下老人靈籤月老靈籤姻緣籤五路財神靈籤城隍爺靈籤孔子聖籤王公靈籤財神爺靈籤
民俗看相生男生女預測表眼皮跳測吉凶打噴嚏測吉凶耳鳴測吉凶面熱測吉凶二十四香譜圖解萬年曆農曆陽曆轉換花語大全手相算命圖解痣相算命圖解面相圖解手相圖解痣相圖解骨相圖解體相圖解
十二星座白羊座金牛座雙子座巨蟹座獅子座處女座天秤座天蠍座射手座魔羯座水瓶座雙魚座星座配對星座運勢星座排行星座知識星座愛情星座分析星座名人星座故事
星座知識星座配對 星座分析 星座星象 星座運勢 星座查詢 星座日期 12星座 星座生日 星座月份 星座性格 上升星座 牡羊座 金牛座 雙子座 巨蟹座 獅子座 處女座 天秤座 天蠍座 射手座 摩羯座 水瓶座 雙魚座
十二生肖屬鼠屬牛屬虎屬兔屬龍屬蛇屬馬屬羊屬猴屬雞屬狗屬豬生肖配對屬相星座生肖運勢
風水知識家居風水辦公室風水臥室風水客廳風水房屋風水廚房風水墓地風水風水用品
心理測試愛情測試性格測試趣味測試財富測試智商測試職業測試社交測試惡搞測試情商測試綜合測試血型性格A型血B型血O型血AB型血血型配對星座血型生肖血型