大一接觸的python,然後被她的簡潔優雅所吸引,這是我拿python做的第一個遊戲,也是最不像遊戲的遊戲,當時剛剛學會一點python基礎語法就迫不及待地寫下了這款遊戲,總共三百多行代碼,既沒有用到類,也沒有用到幾個函數,完全是基礎語法的順序堆砌,但是它帶給我的快樂是無法言說的。
就這款在黑色窗口運行的簡陋遊戲,致敬我第一次編程的激動與興奮
遊戲截圖
完整代碼
def f():
global choice,yourobject,choice2,Hp,Hunger,obj1,obj2,obj3,obj4,obj5,obj6,obj7,nun,koo,Def,Atk,uplimit
while True:
try:
choice=int(input('\n>>(查看人物狀態,返回1;查看物品欄,返回2):'))
break
except:
print('error')
if choice==1:
print('查看人物狀態')
print('生命:'+str(Hp)+'\n'+'飢餓:'+str(Hunger)+'\n'+'攻擊:'+str(Atk)+'\n'+'防禦:'+str(Def))
if choice==2:
print('查看物品欄')
print(sorted(yourobject.values()))
if sorted(yourobject.values())==[]:
print('物品欄爲空!')
koo=1
else:
while True:
try:
choice2=int(input('是否使用物品?(是:1;否;2):'))
koo=0
break
except:
print('error')
if choice2==1 and koo==0:
while True:
try:
nun=int(input('請輸入將使用物品的序號:'))
break
except:
print('error')
print('你使用了'+yourobject1[nun])
if obj1>=2 and nun==1:
obj1-=1
Hunger+=80
if Hunger>=uphunger:
Hunger=uphunger
print('###############飢餓已達上線!')
else:
print('Hunger+80')
yourobject[1]=str(1 )+'牛肉乾'+'×'+str(obj1)
elif obj1==1 and nun==1:
yourobject.pop(nun)
Hunger+=80
if Hunger>=uphunger:
Hunger=uphunger
print('###############飢餓已達上線!')
else:
print('Hunger+80')
elif obj2>=2 and nun==2:
obj2-=1
Hp+=50
if Hp>=uplimit:
Hp=uplimit
print('###############血量已達上線!')
else:
print('Hp:+50')
yourobject[2]=str(2 )+'旺仔牛奶'+'×'+str(obj2)
elif obj2==1 and nun==2:
yourobject.pop(nun)
Hunger+=1
Hp+=50
if Hp>=uplimit:
Hp=uplimit
print('###############血量已達上線!')
else:
print('Hp:+50')
elif obj3>=2 and nun==3:
obj3-=1
Atk+=15
Hp+=90
if Hp>=uplimit:
Hp=uplimit
print('###############血量已達上線!')
print('攻擊+15')
else:
print('Hp:+90\n攻擊+15')
yourobject[3]=str(3 )+'紅牛'+'×'+str(obj3)
elif obj3==1 and nun==3:
yourobject.pop(nun)
Atk+=15
Hp+=90
if Hp>uplimit:
Hp=uplimit
print('###############血量已達上線!')
print('攻擊+15')
else:
print('Hp:+90\n攻擊+15')
elif obj4>=2 and nun==4:
obj4-=1
Hunger+=100
if Hunger>=uphunger:
Hunger=uphunger
print('###############飢餓已達上線!')
else:
print('Hunger+100')
yourobject[4]=str(4 )+'魚肉罐頭'+'×'+str(obj4)
elif obj4==1 and nun==4:
yourobject.pop(nun)
Hunger+=100
if Hunger>=uphunger:
Hunger=uphunger
print('###############飢餓已達上線!')
else:
print('Hunger+100')
elif obj5>=2 and nun==5:
obj5-=1
Def+=10
print('防禦+10')
yourobject[5]=str(5 )+'健力多'+'×'+str(obj5)
elif obj5==1 and nun==5:
yourobject.pop(nun)
Def+=10
print('防禦+10')
elif obj6>=2 and nun==6:
obj6-=1
uplimit+=300
print('生命上限+300')
yourobject[6]=str(6 )+'腎寶片'+'×'+str(obj6)
elif obj6==1 and nun==6:
yourobject.pop(nun)
uplimit+=300
print('生命上限+300')
elif obj7>=2 and nun==7:
obj7-=1
Atk+=1
Def+=1
print('攻擊+1\n防禦+1')
yourobject[7]=str(7 )+'彩虹糖'+'×'+str(obj7)
elif obj7==1 and nun==7:
yourobject.pop(nun)
Atk+=1
Def+=1
print('攻擊+1\n防禦+1')
if choice==2019:
print('獲得一枚腎寶片!!!')
name='腎寶片'
q()
obj6+=1
yourobject[6]=str(6 )+name+'×'+str(obj6)
yourobject1[6]=name
elif choice==520:
Atk+=200
elif choice==1314:
Def+=50
def g():
global time,choice1
while True:
try:
print('\n現在是{},你該如何行動?\n>>1.搜索物資;2.打開菜單欄;3.在庇護所修整'.format(timedic[time]))
choice1=int(input('>>你的選擇是(輸入1或2或3)?:'))
break
except:
print('error')
def t():
enter=input('(enter繼續遊戲)')
if enter=='':
pass
def t1():
enter=input('(enter繼續戰鬥!)\n')
if enter=='':
print('\n'+'*'*50)
def w():
global Hp,die,tap
ff=randint(0,50)
if ff==12 or ff==5 or ff==28 or ff==44:
print('\n糟糕!\n出現了殭屍頭目!!!')
Hp-=50
print('經過戰鬥,你損失了50點HP\n-50Hp')
elif tap==1:
print('你遭遇了屍潮!!!')
Hp-=300
print('受到重創!!!\nHp-300')
die=1
elif ff>30 and ff<40:
print('\n糟糕!\n出現了普通殭屍!!!')
Hp-=10
print('經過戰鬥,你損失了10點HP\n-10Hp')
else:
print('\n你沒有驚動喪屍。\n')
def w1():
global monster,Hp,Hp1
print('{}發現了你!!!\n你將面臨苦戰!'.format(monster))
t()
while Hp>0 and Hp1>0:
first=randint(0,1)
if first==0:
print('>>{}的回合!\n'.format(monster))
w2()
t1()
elif first==1:
print('>>你的回合!\n')
w3()
t1()
def w2():
global Atk1,Def,Hp,Hp1
mon1=randint(1,10)
if mon1==1:
if Atk1<=Def:
print('miss')
else:
Hp-=(Atk1-Def)
print('>{}擡起了血腥的利爪,一記重擊! {}的HP:{}\n 你的HP:{}\n***對你造成了{}點傷害!'.format(monster,monster,Hp1,Hp,Atk1-Def))
else:
if Atk1<=3*Def:
print('miss')
else:
Hp-=(Atk1-3*Def)
print('>{}擡手進行了普通攻擊! {}的HP:{}\n 你的HP:{}\n***對你造成了{}點傷害!'.format(monster,monster,Hp1,Hp,Atk1-3*Def))
def w3():
global monster,Atk,Def1,Hp1,Hp
you=randint(1,10)
if you==1:
if 2*Atk<=Def1:
print('miss')
else:
Hp1-=(2*Atk-Def1)
print('>你打出了致命一擊!!! {}的HP:{}\n 你的HP:{}\n***對{}造成了{}點傷害!!!'.format(monster,Hp1,Hp,monster,2*Atk-Def1))
else:
if Atk<=Def1:
print('miss')
else:
Hp1-=(Atk-Def1)
print('>你打出了普通攻擊! {}的HP:{}\n 你的HP:{}\n***對{}造成了{}點傷害!!!'.format(monster,Hp1,Hp,monster,Atk-Def1))
def h():
global obj1,obj2,name,obj3,obj4,obj5,obj6,obj7
print('開始搜索!')
obj=randint(1,40)
if obj==1 or obj==4 or obj==7:
name='牛肉乾'
q()
obj1+=1
yourobject[1]=str(1 )+name+'×'+str(obj1)
yourobject1[1]=name
elif obj==14 or obj==17 or obj==20 or obj==21:
name='旺仔牛奶'
q()
obj2+=1
yourobject[2]=str(2 )+name+'×'+str(obj2)
yourobject1[2]=name
elif obj==2 or obj==8 or obj==13:
name='紅牛'
q()
obj3+=1
yourobject[3]=str(3 )+name+'×'+str(obj3)
yourobject1[3]=name
elif obj==24 or obj==11 or obj==10:
name='魚肉罐頭'
q()
obj4+=1
yourobject[4]=str(4 )+name+'×'+str(obj4)
yourobject1[4]=name
elif obj==5 or obj==15:
name='健力多'
q()
obj5+=1
yourobject[5]=str(5 )+name+'×'+str(obj5)
yourobject1[5]=name
elif obj==9:
name='腎寶片'
q()
obj6+=1
yourobject[6]=str(6 )+name+'×'+str(obj6)
yourobject1[6]=name
elif obj==40 or obj==33 or obj==35 or obj==37:
name='彩虹糖'
q()
obj7+=1
yourobject[7]=str(7 )+name+'×'+str(obj7)
yourobject1[7]=name
else:
print('你什麼都沒找到!')
t()
def q():
global name
print('恭喜你,獲得了'+name)
t()
yourobject={}
yourobject1={}
obj1=0
obj2=0
obj3=0
obj4=0
obj5=0
obj6=0
obj7=0
Hp=250
uplimit=250
Hp1=550
Hunger=300
uphunger=300
Day=0
time=1
choice1=0
name=''
name2=''
a=''
monster=''
choice2=100
koo=0
tap=0
Atk=22
Atk1=70
Def=10
Def1=20
die=0
timedic={1:'清晨6點',2:'中午12點',3:'下午2點',4:'傍晚6點',5:'午夜12點'}
from random import*
while Hp>0:
Day+=1
time=1
tap=0
print('\n>>你被庇護所外喪屍的吼叫吵醒了,你活到了第{}天!######'.format(Day))
if Day==1:
print('末世的第一天,整座城市都被喪屍襲擊了,交通癱瘓,電力受損。\n清晨6點,面對着突如其來的一切,你感到了迷茫與無助。')
elif Day==7:
print('\n事態似乎愈來愈嚴重了!\n')
t()
monster='【䘮爆者】'
w1()
if Hp<=0:
print('你死了!')
break
elif Hp1<=0:
print('{}已經死亡!'.format(monster))
print('\n>>>>獲得一枚腎寶片!!!')
name='腎寶片'
q()
obj6+=1
yourobject[6]=str(6 )+name+'×'+str(obj6)
yourobject1[6]=name
elif Day==22:
print('\n你不確定是否還有活人!\n')
t()
monster='【屍王】'
Hp1+=3000
Atk1+=200
Def1+=50
w1()
if Hp<=0:
print('你死了!')
break
elif Hp1<=0:
print('{}已經死亡!'.format(monster))
print('\n>>>>獲得一枚腎寶片!!!')
name='腎寶片'
q()
obj6+=1
yourobject[6]=str(6 )+name+'×'+str(obj6)
yourobject1[6]=name
t()
while time<=5:
g()
if choice1==1:
time+=1
Hunger-=10
print('\n飢餓讓你行動遲緩! Hunger-10\n')
h()
if time==6:
tap=1
w()
if die==1 and Hp<=0:
print('你在屍潮中死亡!')
break
elif choice1==2:
time=time
f()
elif choice1==3:
time+=1
Hp+=30
if Hp>=uplimit:
Hp=uplimit
print('###############血量已達上線!無需休息!')
else:
print('Hp:+30')
if Hunger<=0:
Hp+=Hunger
print('飢餓讓你抓狂!\n你損失了{}點Hp\n-{}Hp'.format(abs(Hunger),abs(Hunger)))
print('gameover')
input('123:')