Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My Python Game
#1
For school, we have been asked to research how a game is made. So instead of researching, I decided to make one, in Python. The full code will be 1000+ lines long and is open-source.

Here's the code at the moment:
Code:
import sys, time, random, math

def died():
    sys.exit('You have died!\nGame over!')

print("Welcome to Kieron's Text-Based Python Game.")
time.sleep(2)
name = raw_input("???: What is your name? ")
print("???: So you are " + name + ".")
time.sleep(1)
print("???: Perfect. If you have any questions, don't refrain from asking.")
time.sleep(1)
print("1 - Who are you?\n2 - What is this game?\n3 - I have no questions")
qa1 = int(raw_input('Type one of the above: '))
if qa1 == 1:
    print("???: In this world, I am Kieron Dodge.")
elif qa1 == 2:
    print("???: This is a text-based war game, based in the Year 2018, it includes most of the people I know in it.")
elif qa1 == 3:
    print("???: Very well, then.")
else:
    print("???: I assume you want to continue.")
print("Kieron: I may have told you this already but I am Kieron or Kieron Dodge, a much less greater name, and a war has broke out on an island called Hatton in the Year 2018.")
time.sleep(6)
print("Kieron: You will be serving as a soldier in a special force of Hatton named Hippo Squad.")
time.sleep(3)
print(name + ": Hippo Squad?")
time.sleep(3)
print("Kieron: Yes, the special force faction of the Army Of Hatton. There are a few members in it, Col. 'Nat' Birch, SSgt. Kieron Dodge, Sgt. Alex Thorpe, Sgt. Wojtech Grodecki, Sgt. Adam Parret and Sgt. Mitchell Frisby.")
time.sleep(6)
print(name + ": Who are these people?")
time.sleep(3)
print("Kieron: The best youngest soldiers of the Hatton Army. But now, time is running out, it's time for you to join them. See you soon...")
time.sleep(2)
print(name + ": Wait! I still have more to ask!")
time.sleep(4)
print("---------------------------------------------------------------------------------------------------------------------------------------------------------------")
print("Date: January 1st 2018\nTime: 04:31\n" + name + "\n'War begins'")
time.sleep(2)
print("Bodyguard: " + name + ", welcome to Hippo Squad, where the youngest and strongest are put into. You've been serving for Hatton since you were 11, correct?")
time.sleep(5)
qa2 = int(raw_input("1 - Yes\n2 - No\nYour answer(by number): "))
time.sleep(1)
if qa2 == 1:
    print("Bodyguard: Just as I thought, just as talented as the others.")
elif qa2 == 2:
    print("Bodyguard: Maybe I just got the wrong impression.")
else:
    print("Bodyguard: Fine with me.")
time.sleep(5)
print("Bodyguard: We're at the conference, sir. Best of luck.")
dc1 = int(raw_input("1 - Go inside\n2 - Turn back\nYour answer(by number): "))
if dc1 == 1:
    print("You go inside.")
elif dc1 == 2:
    print("Bodyguard: Wow, sir! Where ya goin'?")
    print("You go inside.")
else:
    print("You go inside.")
print("Col. Birch: Here's our new recruit, and it's about time, take a seat.")
dc2 = int(raw_input("1 - Sit next to Sgt. Pedrick\n2 - Sit next to Sgt. Frisby\n3 - Sit next to SSgt. Dodge\nYour answer(by number): "))
if dc2 == 1:
    print("Sgt. Pedrick: Hm, looks weaker than Dodge. This'll be interesting. *she rolls her eyes* I'm Sgt. Abigail Pedrick, bla bla bla. I specialise in the air commandment of Hippo Squad bla bla bla, now pay attention.")
elif dc2 == 2:
    print("Sgt. Frisby: I've heard good things about you, " + name + ". You just better live up to those expectations or else...")
elif dc2 == 3:
    print("SSgt. Dodge: The cow thinks she can call me weak, don't see 'er shooting her way around. Oh, sorry, I was talking to myself, " + name + " is it? Sit down and pay attention.")
else:
    print("Sgt. Pedrick: Hm, looks weaker than Dodge. This'll be interesting. *she rolls her eyes* I'm Sgt. Abigail Pedrick, bla bla bla. I specialise in the air commandment of Hippo Squad bla bla bla, now pay attention.")
time.sleep(5)
print("Col. Birch: As most of you probably know, we are in grave danger of war with my home country of Sumantrina. They built themselves into an electrical state in 19 hours and have many nukes at stake.")
time.sleep(5)
print("Col. Birch: If we are attacked, we cannot lose A Block or C Block or else we're finished.")
time.sleep(5)
print("*A hatton soldier charged in*Soldier: Colonel! We're under attack! And I'm talking atleast 2000 soldiers out there, we can't handle it!")
time.sleep(5)
print("Col. Birch: Put yourself together! Hippo Squad, let's go! " + name + ", you're on Sniper duty, Pedrick get your plane, the rest of you, with me!")
time.sleep(5)
print("--------------------------------------------------------------------------------------------------------------------------------------------------------------")
print("Date: January 1st 2018\nTime: 06:22\n" + name + "\n'Sniper 101'")
print("Sgt. Pedrick: Alright, " + name + ", be grateful I brought you, now get off and do what you are supposed to.")
time.sleep(3)
dc3 = int(raw_input("1 - Jump\n2 - Stay\nYour answer(by number): "))
if dc3 == 1:
    print("You jump into C Block.")
elif dc3 == 2:
    print("Sgt. Pedrick pushes you.")
else:
    print("You jump into C Block.")
time.sleep(5)
ammo1 = 20
mag1 = 5
killed1 = 0
health1 = 100
while ammo1 > 0:
    time.sleep(5)
    print("Col. Birch: " + name +", you are clear to shoot!")
    print("Your ammo: ")
    print(ammo1)
    print("Your shots left: ")
    print(mag1)
    print("Enemies killed: ")
    print(killed1)
    print("Your health: ")
    print(health1)
    st1 = int(raw_input("1 - Shoot\n2 - Reload\nYour answer(by number): "))
    enemyshoot1 = random.randrange(0, 3)
    enemydamage1 = random.randrange(1, 10)
    if enemyshoot1 == 0:
        print("The enemy missed you!")
    else:
        print("The enemy hit you!")
        health1 = health1 - enemydamage1
    if st1 == 1:
        if mag1 == 0:
            print("You reload")
            mag1 = 5
            ammo1 = ammo1 - 5
        else:
            shothit1 = random.randrange(0, 3)
            if shothit1 == 0:
                print("Shot missed!")
                mag1 = mag1 - 1
            elif shothit1 == 1:
                print("Shot hit!")
                killed1 = killed1 + 1
                mag1 = mag1 - 1
            elif shothit1 == 2:
                print("BOOM! Headshot!")
                killed1 = killed1 + 1
                mag1 = mag1 - 1
    elif st1 == 2:
        if mag1 > 0:
            print("Mag not at 0, turn missed")
        else:
            print("Fully loaded!")
            mag1 = 5
            ammo1 = ammo1 - 5
    else:
        print("TURN MISSED!")
print(name + ": Sir! I'm all out of ammo!")
time.sleep(5)
print("Col. Birch: I understand the situation, standby while I try to get Pedrick.")
time.sleep(10)
print("Col. Birch: She says she'll be on the rooftops, but she is taking heavy fire, so hurry up. Birch out.")
time.sleep(5)
dc4 = int(raw_input("1 - Go through the door\n2 - Jump out the window and hang on to the ledges\nYour answer(by number): "))
if dc4 == 1:
    print("You go through the door")
    dc4a = int(raw_input("1 - Go left\n2 - Go right\nYour answer(by number): "))
    if dc4a == 1:
        print("You go left")
        time.sleep(5)
        rubble1 = random.randrange(1, 3)
        if rubble1 == 1:
            print("You get hit by rubble!")
            health1 = health1 - 5
            print("Health: ")
            print(health1)
        else:
            print("You avoid the rubble")
        time.sleep(5)
        dc4aa = int(raw_input("1 - Go up\n2 - Breach classroom\nYour answer(by number): "))
        if dc4aa == 1:
            print("You get to the rooftops.")
            time.sleep(5)
            print("Sgt. Pedrick: I see you, " + name + "! Run!")
            time.sleep(5)
            print("You run over to Pedrick's Helicopter and jump!")
            jumpcatch1 = random.randrange(0, 4)
            if jumpcatch1 == 0:
                print("You missed the helicopter!")
                died()
            else:
                print("Col. Birch: Good job, rookie.")
        else:
            print("You breach the classroom")
            breachclass1 = random.randrange(0, 3)
            if breachclass1 != 0:
                print("Breached classroom successfully!")
                time.sleep(5)
                print("Sgt. Pedrick: Looks like I can pick you up from here")
                time.sleep(5)
                print("Col. Birch: Good job, rookie.")
            else:
                print("You died!")
                died()
    else:
        if dc4b == 2:
            print("You go right")
            time.sleep(5)
            rubble2 = random.randrange(1, 3)
            if rubble2 == 1:
                print("You get hit by rubble!")
                health1 = health1 - 5
                print("Health: ")
                print(health1)
            else:
                print("You avoid the rubble")
            time.sleep(5)
            dc4ab = int(raw_input("1 - Climb handrails\n2 - Jump out the window\nYour answer(by number): "))
            if dc4ab == 1:
                balance1 = random.randrange(0, 2)
                if balance1 == 0:
                    print("You missed the handrails!")
                    died()
                else:
                    print("You climb the handrails to the rooftops")
                    time.sleep(5)
                    print("Sgt. Pedrick: It's about time, " + name + "! Hurry it up, run!")
                    time.sleep(5)
                    print("You run over to Pedrick's helicopter and jump!")
                    jumpcatch2 == random.randrange(0, 4)
                    if jumpcatch2 == 0:
                        print("You missed the helicopter!")
                        died()
                    else:
                        print("Col. Birch: Good job, rookie.")
else:
    print("There were no ledges, so you fell to your death.")
    died()
print("Level Completed.")
print("Score: ")
print(health1 * killed1 / 2)
time.sleep(5)
print("---------------------------------------------------------------------------------------------------------------------------------------------------------------")
print("Date: January 1st 2018\nTime: 12:44\n" + name + "\n'null'")
Edit 1: I have found several errors in the shooting part.

Edit 2: Fixed errors in the shooting part, game ends after reloading.
Reply
#2
You should actually research too.
As a fall-back if you don't finish this, or the teacher won't accept it.
[Image: 76561198037039305.png]
[Image: nmdd7o.gif]
Reply
#3
(11-22-2011, 11:06 PM)Interwebs Wrote: You should actually research too.
As a fall-back if you don't finish this, or the teacher won't accept it.

Good point. Thanks.
Reply
#4
Quote:In this world, I am Kieron Dodge. But you can call me God
You should change that.
[Image: 76561198037039305.png]
[Image: nmdd7o.gif]
Reply
#5
(11-22-2011, 11:40 PM)Interwebs Wrote:
Quote:In this world, I am Kieron Dodge. But you can call me God
You should change that.

Will do. Forgot about strict religions.
Reply
#6
It's not that, it's just that you sound self-centered.
[Image: 76561198037039305.png]
[Image: nmdd7o.gif]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)