Write Your Own Game in Python3

Good VS Bad Game
So far we have learned many things. I hope you have written the codes and tested them and it executed perfectly. Now the time has come to write a simple game in Python. It is a game called “Good Vs Bad”. The game is simple. But as a beginner you may find this code a bit longer. Write them down. Try to add more features.
If you are in Linux environment, save this file as ‘good-vs-bad.py’ and change the file executable by running this command:
Sudo chmod +x good-vs-bad.py
And then run it on your terminal like this:
./ good-vs-bad.py
If you are in Windows, run the IDLE and save the file as ‘good-vs-bad.py’. Press F5 and play the game.

In the background the code shows and you may play the game on Python Shell.
The code is like this:


#!/usr/bin/python3
class Robots:
    def __init__(self):
        pass
    def WalkLikeARobot(self, WalkingStyle):
        self.WalkingStyle = WalkingStyle
        return self.WalkingStyle
    def CareLikeARobot(self):
        print("takes care like a robot.")
class Humans:
    def __init__(self, nature = "good"):
        self.nature = nature
    def GoodHumanBeing(self):
        print("need not repeat, a good human being is always", self.nature)
    def BadHUmanBeing(self):
        self.nature = "need not repeat, bad human being is always bad."
        print(self.nature)
    def WalkLikeARobot(self, WalkingStyle):
        self.WalkingStyle = WalkingStyle
        return self.WalkingStyle
def main():
    robu = Robots()
    # robu.CareLikeARobot()
    # print(robu.WalkLikeARobot("A robot walks like a robot and nothing happens."))
    GoodMan = Humans()
    # print(GoodMan.nature)
    # GoodMan.GoodHumanBeing()
    BadMan = Humans()
    # BadMan.nature = "bad"
    # print(BadMan.nature)
    # BadMan.BadHUmanBeing()
    # print(BadMan.WalkLikeARobot("he is human but walks like a robot"))
    # when a bad man wlaks like a robot many things happen
    WhenABadManWalksLikeARobot = BadMan.WalkLikeARobot(dict(change = 'he becomes a monster inside',
                               act = 'he kills fellow people',
                               feel = 'he enjoys torturing animals',
                               care = 'he cares for none',
                               look = 'he looks a normal human being',
                               state = 'finally he destroys himself'))
    # there are lot of actions that take place
    print("What happens when a Bad Man walks like a Robot?")
    change = input("Tell us what kind of change may take place inside him?\n Choose between 'monster' and 'angel',"
                   "and type here...>>>>")
    WhenABadManWalksLikeARobot['change'] = change
    reward = 0
    if change == 'monster':
        print("You have won the first round:", change)
        reward = 1000
        print("You have won ", reward, "points.")
        print("What does he do? :", WhenABadManWalksLikeARobot['act'])
        change = input("Now tell us what the monster feels inside while killing people?\n Choose between 'great' and 'sad',"
                   "and type here...>>>>")
        WhenABadManWalksLikeARobot['change'] = change
        if change == 'great':
            print("You have won the second round:")
            reward = 10000
            print("You have won ", reward, "points.")
            print("What he feels inside? :", WhenABadManWalksLikeARobot['feel'])
            change = input("Tell us does the monster care for anyone?\n Choose between 'yes' and 'no',"
                   "and type here...>>>>")
            WhenABadManWalksLikeARobot['change'] = change
            if change == 'no':
                print("You have won the third round:")
                reward = 100000
                print("You have won ", reward, "points.")
                print("What he feels inside? :", WhenABadManWalksLikeARobot['care'])
                change = input("Tell us does the monster look like a normal human being?\n Choose between 'yes' and 'no',"
                   "and type here...>>>>")
                WhenABadManWalksLikeARobot['change'] = change
                if change == 'yes':
                    print("You have won the fourth round:")
                    reward = 1000000
                    print("You have won ", reward, "points.")
                    print("What does he look like? :", WhenABadManWalksLikeARobot['look'])
                    change = input("Tell us what happens to the monster finally? Does he destroy himself\n Choose between 'yes' and 'no',"
                                   "and type here...>>>>")
                    WhenABadManWalksLikeARobot['change'] = change
                    if change == 'yes':
                        print("You have won the fifth round:")
                        reward = 100000000
                        print("You have won Jackpot.", reward, "points.")
                    else:
                        print("You have changed the course of game. It ends here. You have lost", reward - 100000, "points.")
                else:
                    print("You have changed the course of game. It ends here. You have lost", reward - 1000, "points.")
            else:
                print("You have changed the course of game. It ends here. You have lost", reward - 100, "points.")
        else:
            print("You have changed the course of game. It ends here. You have lost", reward - 10, "points.")
    else:
        print("You have changed the course of game. It ends here and you have won no point.")
if __name__ == "__main__":
    main()

And the output on your Python Shell looks like this:

What happens when a Bad Man walks like a Robot?
Tell us what kind of change may take place inside him?
Choose between ‘monster’ and ‘angel’,and type here…>>>>monster
You have won the first round: monster
You have won 1000 points.
What does he do? : he kills fellow people
Now tell us what the monster feels inside while killing people?
Choose between ‘great’ and ‘sad’,and type here…>>>>great
You have won the second round:
You have won 10000 points.
What he feels inside? : he enjoys torturing animals
Tell us does the monster care for anyone?
Choose between ‘yes’ and ‘no’,and type here…>>>>no
You have won the third round:
You have won 100000 points.
What he feels inside? : he cares for none
Tell us does the monster look like a normal human being?
Choose between ‘yes’ and ‘no’,and type here…>>>>yes
You have won the fourth round:
You have won 1000000 points.
What does he look like? : he looks a normal human being
Tell us what happens to the monster finally? Does he destroy himself
Choose between ‘yes’ and ‘no’,and type here…>>>>yes
You have won the fifth round:
You have won Jackpot. 100000000 points.

Since I wrote the code, I won the game. But there are few tricks. In those tricky parts, if you failed and supplied wrong inputs you would lose.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s