当前位置:网站首页>[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?

[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?

2022-07-28 11:44:00 Gu Muzi acridine

Introduction

There are so many people in the world , They believe that they will encounter those situations in the doomsday movie in their lifetime .

Such as biochemical disaster 、 Natural disasters 、 Alien invasion and so on .

These people have a cool name ——“ Doomsday survivalist ”

They rely on one “ I believe it anyway ” The spirit of , Save against a rainy day . Storing a lot of survival supplies is just an introductory course .

Build private shelters , Devil's wild survival training is their daily .

Of course , Most people don't deliberately prepare for the end of the world . But Xiaobian thinks , Everyone's sense of survival at the end of the world is still very strong .

I don't know if you still remember the salt we robbed in those years ?

Complete material for all articles + The source code is in

Fans white whoring source code welfare , Please move to CSDN The community or the public at the end of the article hao It's free .

This sense of being prepared for danger in times of peace , Maybe it's related to the fact that we always come into contact with works with eschatological themes .

Many famous movies have eschatological backgrounds , for example 《 A dead-alive person 》《 Busan trip 》 wait

Of course, such a good theme can't do without games , All the rage H1Z1, classical 《 radiation 》 Series and so on , Today Xiaobian took

Warm blooded excitement also gives everyone Make a Python Version of the text doomsday game Ba !

( The interface version of the apocalyptic game is too hair consuming , I can't do it myself , This is a simple text apocalyptic version .)

Text

One 、 Effect display

The code is packaged directly , The following demonstration is in exe On the file

1) The first day of the Apocalypse

2) Different choices lead to different results

3) View people information

Two 、 Code display

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>>( Check character status , return 1; Check the item list , return 2):'))
                        break
                except:
                        print('error')
        if choice==1:
            print(' Check character status ')
            print(' life :'+str(Hp)+'\n'+' hunger :'+str(Hunger)+'\n'+' attack :'+str(Atk)+'\n'+' defense :'+str(Def))
        if choice==2:
            print(' Check the item list ')
            print(sorted(yourobject.values()))
            if sorted(yourobject.values())==[]:
                print(' Item column is empty !')
                koo=1
            else:
                    while True:
                            try:
                                    choice2=int(input(' Whether to use items ?( yes :1; no ;2):'))
                                    koo=0
                                    break
                            except:
                                    print('error')
            if choice2==1 and koo==0:
                while True:
                        try:
                                nun=int(input(' Please enter the serial number of the item to be used :'))
                                break
                        except:
                                print('error')
                print(' You have used it. '+yourobject1[nun])
                if obj1>=2 and nun==1:
                    obj1-=1
                    Hunger+=80
                    if Hunger>=uphunger:
                            Hunger=uphunger
                            print('############### Hunger has reached the line !')
                    else:
                            print('Hunger+80')
                    yourobject[1]=str(1 )+' Dried beef '+'×'+str(obj1)
                    
                elif obj1==1 and nun==1:
                    yourobject.pop(nun)
                    Hunger+=80
                    if Hunger>=uphunger:
                            Hunger=uphunger
                            print('############### Hunger has reached the line !')
                    else:
                            print('Hunger+80')
                elif obj2>=2 and nun==2:
                    obj2-=1
                    Hp+=50
                    if Hp>=uplimit:
                            Hp=uplimit
                            print('############### Your HP has reached the upper limit !')
                    else:
                            print('Hp:+50')
                    yourobject[2]=str(2 )+' Want Want Children's milk '+'×'+str(obj2)
                elif obj2==1 and nun==2:
                    yourobject.pop(nun)
                    Hunger+=1
                    Hp+=50
                    if Hp>=uplimit:
                            Hp=uplimit
                            print('############### Your HP has reached the upper limit !')
                    else:
                            print('Hp:+50')
                elif obj3>=2 and nun==3:
                    obj3-=1
                    Atk+=15
                    Hp+=90
                    if Hp>=uplimit:
                            Hp=uplimit
                            print('############### Your HP has reached the upper limit !')
                            print(' attack +15')
                    else:
                            print('Hp:+90\n attack +15')
                    yourobject[3]=str(3 )+' Red bull '+'×'+str(obj3)
                elif obj3==1 and nun==3:
                    yourobject.pop(nun)
                    Atk+=15
                    Hp+=90
                    if Hp>uplimit:
                            Hp=uplimit
                            print('############### Your HP has reached the upper limit !')
                            print(' attack +15')
                    else:
                            print('Hp:+90\n attack +15')
                elif obj4>=2 and nun==4:
                    obj4-=1
                    Hunger+=100
                    if Hunger>=uphunger:
                            Hunger=uphunger
                            print('############### Hunger has reached the line !')
                    else:
                            print('Hunger+100')
                    yourobject[4]=str(4 )+' Canned fish '+'×'+str(obj4)
                elif obj4==1 and nun==4:
                    yourobject.pop(nun)
                    Hunger+=100
                    if Hunger>=uphunger:
                            Hunger=uphunger
                            print('############### Hunger has reached the line !')
                    else:
                            print('Hunger+100')
                elif obj5>=2 and nun==5:
                    obj5-=1
                    Def+=10
                    print(' defense +10')
                    yourobject[5]=str(5 )+' Jianlido '+'×'+str(obj5)
                elif obj5==1 and nun==5:
                    yourobject.pop(nun)
                    Def+=10
                    print(' defense +10')
                elif obj6>=2 and nun==6:
                    obj6-=1
                    uplimit+=300
                    print(' Life limit +300')
                    yourobject[6]=str(6 )+' Shenbao tablets '+'×'+str(obj6)
                elif obj6==1 and nun==6:
                    yourobject.pop(nun)
                    uplimit+=300
                    print(' Life limit +300')
                elif obj7>=2 and nun==7:
                    obj7-=1
                    Atk+=1
                    Def+=1
                    print(' attack +1\n defense +1')
                    yourobject[7]=str(7 )+' Rainbow sugar '+'×'+str(obj7)
                elif obj7==1 and nun==7:
                    yourobject.pop(nun)
                    Atk+=1
                    Def+=1
                    print(' attack +1\n defense +1')
        if choice==2019:
            print(' Get a kidney tablet !!!')
            name=' Shenbao tablets '
            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 Now it is {}, How should you act ?\n>>1. Search for supplies ;2. Open the menu bar ;3. Repair in the shelter '.format(timedic[time]))
                choice1=int(input('>> Your choice is ( Input 1 or 2 or 3)?:'))
                break
        except:
                print('error')
def t():
        enter=input('(enter Keep playing )')
        if enter=='':
                pass
def t1():
        enter=input('(enter Keep fighting !)\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 too bad !\n There are zombie leaders !!!')
        Hp-=50
        print(' After fighting , You lost 50 spot HP\n-50Hp')
    elif  tap==1:
        print(' You have encountered a wave of corpses !!!')
        Hp-=300
        print(' Be badly hurt !!!\nHp-300')
        die=1
    elif ff>30 and ff<40:
        print('\n too bad !\n There are ordinary zombies !!!')
        Hp-=10
        print(' After fighting , You lost 10 spot HP\n-10Hp')
    else:
        print('\n You didn't disturb the zombie .\n')
def w1():
        global monster,Hp,Hp1
        print('{} Found you !!!\n You will face a bitter battle !'.format(monster))
        t()
        while Hp>0 and Hp1>0:
                first=randint(0,1)
                if first==0:
                        print('>>{} The round of !\n'.format(monster))
                        w2()
                        t1()
                elif first==1:
                        print('>> Your Turn !\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('>{} Raised the bloody claw , A heavy blow !               {} Of HP:{}\n                                                    Yours HP:{}\n*** It has caused you {} Point injury !'.format(monster,monster,Hp1,Hp,Atk1-Def))
        else:
                if Atk1<=3*Def:
                        print('miss')
                else:
                        Hp-=(Atk1-3*Def)
                        print('>{} Raised his hand and made a common attack !               {} Of HP:{}\n                                               Yours HP:{}\n*** It has caused you {} Point injury !'.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('> You hit a fatal blow !!!               {} Of HP:{}\n                                           Yours HP:{}\n*** Yes {} It's caused {} Point injury !!!'.format(monster,Hp1,Hp,monster,2*Atk-Def1))
        else:
                if Atk<=Def1:
                        print('miss')
                else:
                        Hp1-=(Atk-Def1)
                        print('> You hit a normal attack !               {} Of HP:{}\n                                    Yours HP:{}\n*** Yes {} It's caused {} Point injury !!!'.format(monster,Hp1,Hp,monster,Atk-Def1))
                   
                        
                      
        
def h():
    global obj1,obj2,name,obj3,obj4,obj5,obj6,obj7
    print(' Begin your search !')
    obj=randint(1,40)
    if obj==1 or obj==4 or obj==7:
        name=' Dried beef '
        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=' Want Want Children's milk '
        q()
        obj2+=1
        yourobject[2]=str(2 )+name+'×'+str(obj2)
        yourobject1[2]=name
    elif obj==2 or obj==8 or obj==13:
        name=' Red bull '
        q()
        obj3+=1
        yourobject[3]=str(3 )+name+'×'+str(obj3)
        yourobject1[3]=name
    elif obj==24 or obj==11 or obj==10:
        name=' Canned fish '
        q()
        obj4+=1
        yourobject[4]=str(4 )+name+'×'+str(obj4)
        yourobject1[4]=name
    elif obj==5 or obj==15:
        name=' Jianlido '
        q()
        obj5+=1
        yourobject[5]=str(5 )+name+'×'+str(obj5)
        yourobject1[5]=name
    elif obj==9:
        name=' Shenbao tablets '
        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=' Rainbow sugar '
        q()
        obj7+=1
        yourobject[7]=str(7 )+name+'×'+str(obj7)
        yourobject1[7]=name
        
    else:
        print(' You didn't find anything !')
        t()
def q():
    global name
    print(' congratulations , To obtain the '+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:' Early in the morning 6 spot ',2:' At noon, 12 spot ',3:' Afternoon 2 spot ',4:' In the evening 6 spot ',5:' The middle of the night 12 spot '}
from random import*
while Hp>0:
    Day+=1
    time=1
    tap=0
    print('\n>> You were awakened by the roar of zombies outside the shelter , You live to the th {} God !######'.format(Day))
    if Day==1:
        print(' The first day of the Apocalypse , The whole city was attacked by zombies , Traffic is paralyzed , Power damage .\n Early in the morning 6 spot , Facing all the sudden , You feel confused and helpless .')
    elif Day==7:
        print('\n Things seem to be getting worse !\n')
        t()
        monster='【䘮 Exploder 】'
        w1()
        if Hp<=0:
                print(' You're dead !')
                break
        elif Hp1<=0:
                print('{} Already dead !'.format(monster))
                print('\n>>>> Get a kidney tablet !!!')
                name=' Shenbao tablets '
                q()
                obj6+=1
                yourobject[6]=str(6 )+name+'×'+str(obj6)
                yourobject1[6]=name
    elif Day==22:
        print('\n You are not sure if there are still living people !\n')
        t()
        monster='【 undying 】'
        Hp1+=3000
        Atk1+=200
        Def1+=50
        w1()
        if Hp<=0:
                print(' You're dead !')
                break
        elif Hp1<=0:
                print('{} Already dead !'.format(monster))
                print('\n>>>> Get a kidney tablet !!!')
                name=' Shenbao tablets '
                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 slows you down !  Hunger-10\n')
                h()
                if time==6:
                        tap=1
                w()
                if die==1 and Hp<=0:
                        print(' You die in the tide of corpses !')
                        break
        elif choice1==2:
                time=time
                f()
        elif choice1==3:
                time+=1
                Hp+=30
                if Hp>=uplimit:
                            Hp=uplimit
                            print('############### Your HP has reached the upper limit ! No need to rest !')
                else:
                            print('Hp:+30')
                
    if Hunger<=0:
        Hp+=Hunger
        print(' Hunger drives you crazy !\n You lost {} spot Hp\n-{}Hp'.format(abs(Hunger),abs(Hunger)))
print('gameover')
input('123:')

summary

Doomsday survival games always have a kind of romance that people can't refuse .

Compared with other open world games , The unique charm of the doomsday background lies in “ Existence ” This is the most essential problem .

We are not for someone or something , Or save the world , We just want to live , That's it .

In the familiar and strange urban ruins , Under the endless doomsday , This sense of substitution makes the heart beat faster .

​ So Xiaobian thinks “ Save against a rainy day , Save yourself when the crisis comes ” Doomsday survivalists are definitely not psychotic .

More Than This , Many people still think it's cool , Yearn for those expensive and reliable tools and materials . This kind of people actually

It can also be understood as a military enthusiast or collector , Of course , Nor is it a bad phenomenon . On the contrary, as a minority

The phenomenon , Doomsday survivalism is quickly integrated into cultural works represented by Games .

Nowadays, this element is more or less added to many games , Obviously, many players ( Including Xiaobian me ) I really like this

“ It looks cool ” Of course . An orthodox game of eschatological survival , Now it's rare .

This kind of attempt is really worth encouraging , So come to me to get the source code and experience it ! Click on , Enter the game and

Xiaobian, let's survive the doomsday !

Interactive topics : If the end comes , You can only bring three items , What will you bring ?

Complete free source code collection office : Find me ! At the end of the article, you can get it by yourself , Didi, I can also !

I recommend previous articles ——

project 1.0  Bubble machine games

 【Pygame actual combat 】 The super interesting bubble game is coming —— May your childlike innocence never die , Always happy and simple ~

project 8.1   《 Basketball “ prince ”》 Little games

 【Pygame actual combat 】 funny Basketball —— To meet “ basket ” And on the , The joy lies in “ The ball ” in , Little cute who likes playing basketball came to report ~

project 7.3  Want to kill the virus and defend the city 》 game

【Pygame actual combat 】 During the epidemic, I recommend a cool tour for you who can't go out 《 Destroy the virus and defend the city 》【 Strong push 】 May the end of

project 5.8  Flop games

Pygame actual combat : How to do with poor memory ? Don't worry. , Memory enhancing games for you ~【 The more you play, the more addictive 】

project 5.3 《 Squid game 》 And 《 One, two, three wooden people 》 Little games

When 《 Squid game 》 A strong incoming :“ One 、 Two 、 3、 ... and , Wooden man , Dioctahedral smectite .” You're still scared ?

A summary of the article ——

project 1.0 Python—2021 | Summary of existing articles | Continuous updating , Just read this article directly

( More + The source code is summarized in the article !! Welcome to ~)

原网站

版权声明
本文为[Gu Muzi acridine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/197/202207131234047730.html