私は2人のテキストベースのポケモンバトルレプリカに、複数のポケモンを入れ替えて自分の体力と動きを持たせようとしています。pythonのヘルスバーで複数の切り替え文字を編成する
コンピュータプレイヤーが基本的に何もしていないコンピュータと1人で戦っていて、プレイヤーごとに1つのポケモンしかいなかった同様のスクリプトを作成しました。今私はそれを拡大して、2人が同じデバイスでお互いに戦い、ホットシートスタイルを演じるようにしています。
私が抱えている問題は、プレイヤーがどちらがアクティブなものかを切り替えながら、個々のポケモンを整理し戻す方法をまだ見つけていないことです。私は辞書を使ってみましたが、ポケモンを傷つけたいときにはあまり役に立ちません。なぜなら、私は各ヒースバーの値を変更することができないからです。私はまだ個々のポケモンのための辞書を作成しようとしていません。
しかし、個々の辞書を持つことの問題は、各チームに残っているポケモンの数を知る方法が必要なことです。チームごとに3つのチームがあり、1チームが完全に抹消されるとバトルが終了します。
ご協力いただければ幸いです。私は元のPlayer VSを残します。参照のためにここにコンピュータスクリプト:
import time
Hm=150
Hr=60
TackleMove=50
ScratchMove=40
BiteMove=60
#Intro
print 'Difficulty? Type "Easy", "Normal", "Hard"'
EsMo = input("Answer: ")
print "A wild Magikarp appeared!"
time.sleep(0.5)
print "Go! Rattata!"
time.sleep(0.5)
#Using a move
def PlayerTurn():
print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
time.sleep(0.5)
Move = input("Use: ")
#Tackle
if Move is "Tackle":
print "Rattata used Tackle!"
global Hm
Hm-=TackleMove
time.sleep(0.5)
if EsMo is "Hard":
pass
elif EsMo is "Easy" or "Normal":
print "Magikarp has", Hm, "HP Left"
#Scratch
elif Move is "Scratch":
print "Rattata used Scratch!"
Hm-=ScratchMove
time.sleep(0.5)
if EsMo is "Hard":
pass
elif EsMo is "Easy" or "Normal":
print "Magikarp has", Hm, "HP Left"
#HyperFang
elif Move is "HyperFang":
print "Rattata used HyperFang!"
Hm/=2
time.sleep(0.5)
if EsMo is "Hard":
pass
elif EsMo is "Easy" or "Normal":
print "Magikarp has", Hm, "HP Left"
#Bite
elif Move is "Bite":
print "Rattata used Bite!"
Hm-=BiteMove
time.sleep(0.5)
if EsMo is "Hard":
pass
elif EsMo is "Easy" or "Normal":
print "Magikarp has", Hm, "HP Left"
#Cheat
elif Move is "Cheat":
print "CHEATER!"
Hm-=Hm
print "Magikarp has", Hm, "HP Left"
else:
print "Oops"
return
#AI Turn
def AITurn():
if Hm>50 or EsMo is "Easy":
print "Magikarp used Splash!"
time.sleep(1)
print "But nothing happened..."
elif Hm<=50 and EsMo is "Normal" or "Hard":
print "Magikarp used Tackle!"
global Hr
Hr-=TackleMove
time.sleep(1)
print "Rattata has", Hr, "HP Left"
else:
print "Oops"
return
#Full Loop
while Hm>0:
#Action Choice
print 'Actions are: "Fight", "Pokeball", "Run"'
time.sleep(0.5)
Action = input("What do you want to do?: ")
time.sleep(0.5)
#If Choose Fight
if Action is "Fight":
PlayerTurn()
if Hm<=0:
time.sleep(1)
print "Magikarp Fainted!"
time.sleep(1)
print "You Win!"
break
time.sleep(0.5)
AITurn()
if Hm<=0:
time.sleep(1)
print "Magikarp Fainted!"
time.sleep(1)
print "You Win!"
break
elif Hr<=0:
time.sleep(1)
print "Rattata Fainted!"
time.sleep(1.5)
print "You Lost!"
break
time.sleep(0.5)
continue
#If Choose Run
if Action is "Run":
print "Ran away Safley!"
break
#If Choose Pokeball
if Action is "Pokeball":
time.sleep(0.5)
print "You threw the Pokeball!"
time.sleep(1)
if Hm>100:
print "..."
time.sleep(1)
print "Darn! It Broke Free!"
elif 50<Hm<=100:
print "..."
time.sleep(1)
print "..."
time.sleep(1)
print "Almost had it!"
elif 30<Hm<=50:
print "..."
time.sleep(1)
print "..."
time.sleep(1)
print "..."
time.sleep(1)
print "Shoot! So Close!"
elif Hm<=30:
print "..."
time.sleep(1)
print "..."
time.sleep(1)
print "..."
time.sleep(1)
print "You Caught a Magikarp!"
time.sleep(1.5)
print "Congratulations!"
break
else:
print "Oops"
time.sleep(1)
AITurn()
if Hm<=0:
time.sleep(1)
print "Magikarp Fainted!"
time.sleep(1)
print "You Win!"
break
elif Hr<=0:
time.sleep(1)
print "Rattata Fainted!"
time.sleep(1.5)
print "You Lost!"
break
time.sleep(0.5)
continue
time.sleep(2)
print "Please, try again!"
#End
私の現在のコードは2つの形式であり、まだ他の人よりも私はいくつかのものを持って、より完全な働いています。この例では、私はRattataのものだけを記入し、私がテストしている動きはScratchです。
import time
P1Rat=50
P1Abra=100
P1Pidgey=100
P2Rat=50
P2Abra=100
P2Pidgey=100
Play1PokeSt=["Rattata", "Abra", "Pidgey"]
ActPl1Poke=[]
ActPl1PokeSt=[]
Play2PokeSt=["Rattata", "Abra", "Pidgey"]
ActPl2Poke=[]
ActPl2PokeSt=[]
#Player 1's Rattata Attacks
def Rattata1():
global ActPl2Poke
print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
time.sleep(0.5)
R1Move = input("Use: ")
#Tackle
if R1Move is "Tackle":
print "Rattata used Tackle!"
ActPl2Poke[0]-=50
#Scratch
elif R1Move is "Scratch":
print "Rattata used Scratch!"
ActPl2Poke[0]-=40
print ActPl2Poke[:]
print P2Rat
#HyperFang
elif R1Move is "HyperFang":
print "Rattata used HyperFang!"
ActPl2Poke[0]/=2
#Bite
elif R1Move is "Bite":
print "Rattata used Bite!"
ActPl2Poke[0]-=60
def Play1Sel():
while True:
print "What Pokemon do you want to use?"
print "Remaining Pokemon are:"
print ", ".join(Play1PokeSt)
Pokemon1=input()
if Pokemon1 is "Rattata" and "Rattata" in Play1PokeSt:
del ActPl1Poke[:]
ActPl1Poke.append(int(P1Rat))
del ActPl1PokeSt[:]
ActPl1PokeSt.append("Rattata")
break
elif Pokemon1 is "Rattata" and "Rattata" not in Play1PokeSt:
print "Rattata has fainted! Choose another!"
continue
if Pokemon1 is "Abra" and "Abra" in Play1PokeSt:
del ActPl1Poke[:]
ActPl1Poke.append(P1Abra)
del ActPl1PokeSt[:]
ActPl1PokeSt.append("Abra")
break
elif Pokemon1 is "Abra" and "Abra" not in Play1PokeSt:
print "Abra has fainted! Choose another!"
continue
if Pokemon1 is "Pidgey" and "Pidgey" in Play1PokeSt:
del ActPl1Poke[:]
ActPl1Poke.append(P1Pidgey)
del ActPl1PokeSt[:]
ActPl1PokeSt.append("Pidgey")
break
elif Pokemon1 is "Pidgey" and "Pidgey" not in Play1PokeSt:
print "Pidgey has fainted! Choose another!"
continue
def Play2Sel():
while True:
print "What Pokemon do you want to use?"
print "Remaining Pokemon are:"
print ", ".join(Play2PokeSt)
Pokemon2=input()
if Pokemon2 is "Rattata" and "Rattata" in Play2PokeSt:
del ActPl2Poke[:]
ActPl2Poke.append(P2Rat)
del ActPl2PokeSt[:]
ActPl2PokeSt.append("Rattata")
break
elif Pokemon2 is "Rattata" and "Rattata" not in Play2PokeSt:
print "Rattata has fainted! Choose another!"
continue
if Pokemon2 is "Abra" and "Abra" in Play2PokeSt:
del ActPl2Poke[:]
ActPl2Poke.append(P2Abra)
del ActPl2PokeSt[:]
ActPl2PokeSt.append("Abra")
break
elif Pokemon2 is "Abra" and "Abra" not in Play2PokeSt:
print "Abra has fainted! Choose another!"
continue
if Pokemon2 is "Pidgey" and "Pidgey" in Play2PokeSt:
del ActPl2Poke[:]
ActPl2Poke.append(P2Pidgey)
del ActPl2PokeSt[:]
ActPl2PokeSt.append("Pidgey")
break
elif Pokemon2 is "Pidgey" and "Pidgey" not in Play2PokeSt:
print "Pidgey has fainted! Choose another!"
continue
#Player 2's Rattata Attacks
def Rattata2():
global ActPl2Poke
print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
time.sleep(0.5)
R2Move = input("Use: ")
#Tackle
if R2Move is "Tackle":
print "Rattata used Tackle!"
ActPl1Poke[0]-=50
#Scratch
elif R2Move is "Scratch":
print "Rattata used Scratch!"
ActPl1Poke[0]-=40
print P1Rat
#HyperFang
elif R2Move is "HyperFang":
print "Rattata used HyperFang!"
ActPl1Poke[0]/=2
#Bite
elif R2Move is "Bite":
print "Rattata used Bite!"
ActPl1Poke[0]-=60
#Player 1's Turn
def Play1():
print "Actions are: Fight, Change"
time.sleep(0.5)
Act1=input("What do you want to do?: ")
if Act1 is "Fight" and str(*ActPl1PokeSt) is "Rattata":
Rattata1()
elif Act1 is "Change":
Play1Sel()
else:
print "oops"
#Player 2's Turn
def Play2():
print "Actions are: Fight"
time.sleep(0.5)
Act2=input("What do you want to do?: ")
if Act2 is "Fight" and str(*ActPl2PokeSt) is "Rattata":
Rattata2()
else:
print "oops"
#Whole Loop
print "Player 1! Select Your Pokemon!"
Play1Sel()
print ActPl1Poke
print "Player 2! Select Your Pokemon!"
Play2Sel()
print ActPl2Poke
while True:
print "Player 1, your turn."
Play1()
if P1Rat <=0 or P2Rat <=0:
print "Finish"
break
else:
print "Player 2, your turn."
Play2()
if P1Rat <=0 or P2Rat <=0:
print "Finish"
break
continue
そしてこれは、他のバージョンである:
import time
Poke1={"Rattata" : 100 , "Abra" : 100 , "Pidgey" : 100}
Poke2={"Rattata" : 100 , "Abra" : 100 , "Pidgey" : 100}
ActPo1={}
ActPo2={}
#Player 1's Rattata's Moves
def RattataAtk1():
print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
time.sleep(0.5)
MoveR1 = input("Use: ")
#Tackle
if MoveR1 is "Tackle":
print "Rattata used Tackle!"
ActPo2-=50
#Scratch
elif MoveR1 is "Scratch":
print "Rattata used Scratch!"
ActPo2-=40
#HyperFang
elif MoveR1 is "HyperFang":
print "Rattata used HyperFang!"
ActPo2/=2
#Bite
elif MoveR1 is "Bite":
print "Rattata used Bite!"
ActPo2-=60
#Player 2's Rattata's Moves
def RattataAtk2():
print 'Moves are: "Tackle", "Scratch", "HyperFang", "Bite"'
time.sleep(0.5)
MoveR2 = input("Use: ")
#Tackle
if MoveR2 is "Tackle":
print "Rattata used Tackle!"
ActPo1-=50
#Scratch
elif MoveR2 is "Scratch":
print "Rattata used Scratch!"
ActPo1-=40
#HyperFang
elif MoveR2 is "HyperFang":
print "Rattata used HyperFang!"
ActPo1/=2
#Bite
elif MoveR2 is "Bite":
print "Rattata used Bite!"
ActPo1-=60
#Selection of Player 1's Pokemon
def Play1Sel():
while True:
print "What Pokemon do you want to use?"
print "Remaining Pokemon are:"
print Poke1.keys()
Choose1=input()
if Choose1 is "Rattata" and "Rattata" in Poke1:
ActPo1["Rattata"]=Poke1["Rattata"]
break
else:
print "Oops"
break
#Selection of Player 2's Pokemon
def Play2Sel():
while True:
print "What Pokemon do you want to use?"
print "Remaining Pokemon are:"
print Poke2.keys()
Choose2=input()
if Choose2 is "Rattata" and "Rattata" in Poke2:
ActPo2["Rattata"]=Poke2["Rattata"]
break
else:
print "Oops"
break
#Player 1's Choice of Action
def Play1():
print "Actions are: Fight, Change"
time.sleep(0.5)
Act1=input("What do you want to do?: ")
if Act1 is "Fight" and ActPo1.has_key("Rattata") is True:
RattataAtk1()
else:
print "Oops"
#Player 2's Choice of Action
def Play2():
print "Actions are: Fight, Change"
time.sleep(0.5)
Act2=input("What do you want to do?: ")
if Act2 is "Fight" and ActPo2.has_key("Rattata") is True:
RattataAtk2()
else:
print "Oops"
#Full Loop
print "Player 1! Select Your Pokemon!"
Play1Sel()
print ActPo1.items()
print "Player 2! Select Your Pokemon!"
Play2Sel()
print ActPo2.items()
while True:
print "Player 1, your turn."
Play1()
if ActPo1.values()is 0:
print "Finish"
break
else:
print "Player 2, your turn."
Play2()
if ActPo2.values()is 0:
print "Finish"
break
continue
を参照してください。これは、コードの繰り返しを減らすのに役立ちます。同様に、各プレイヤーのポケモンはリストに格納する必要があるため、必要に応じて健康などを変更することができます。また、動作していないコードを投稿してください。動作するコードは助けようとしている人に役に立たないです – user3080953
提案をありがとう!私はそれを調べます。私はちょうどそれを見たい場合は、メインの質問に私の現在のコードを掲載した。 –
ええ、ちょうど私のコードとリストに変更を加えたことは確かに行く方法でした!どうもありがとう。 –