Posts tagged coding
My Second Official Python Video Game
2Well I have “officially” created another program that I am happy with showing everyone. It is called the Guess Your Number Game. Basically you think of a number between 1 and 100 and the program guesses your number based on hints that you provide. (e.g. Higher or Lower)
#The Guess Your Number Game
#This Game simply guesses a number that you think of
#inbetween 1 and 100 using "Higher" or "Lower" hints.
import random
print("""
Welcome to the Guess Your Number Game!
In this game you will think of a number between 1 and 100.
The computer will then guess what the number is.
If the computer's guess is lower then the number you gave,
then type L into the console.
If the computer's guess is higher then the number you gave,
then type H into the console.
If the computer's guess is correct then type Y into the console.
""")
Min = 1
Max = 100
Input = " "
input("\nPress the enter key if you have thought of your number.")
while Input.lower() != "y":
Guess = random.randint(Min,Max)
print("\nI have guessed", Guess)
Input = input("Is the number Higher or Lower or did I guess correctly? ")
if Input.lower() == "h": Min = Guess + 1
if Input.lower() == "l": Max = Guess - 1
print("\nI have guessed correctly. Your Number is " + str(Guess) + ", Good Game.")
input("\nPress the Enter Key to Exit.")
(Update: here is the exe download link)
(Note: Just extract the files into a folder and run the program)
Don’t expect much. I’m new to this =) =P
My First Official Python Video Game
0Well I actually just got back from a vacation so I haven’t been doing much coding but before I left I made this one program which technically counts as a video game. Its really simple and it doesn’t have graphics but it does have health points! Since I don’t know how to compile programs yet I can’t post that up here but I can post the actual code. This is in Python:
# Troll Battle
# Simulates a Fight with a Troll using random sets of damage.
import random
print("Your Hero is attacked by a massive Troll Monster.")
print("Your hero unsheathes his sword ready for batle but with little hope in his eyes.\n")
roll = random.randrange(5) + 1
health = 100
thealth = 300
while ((health > 0) and (thealth > 0)):
input("Press enter to continue.\n\n")
roll = random.randrange(5) + 1
if roll > 3:
tdamage = random.randint(10,26)
thealth -= tdamage
print("Your hero swings and damages the troll for" \
, tdamage, "damage points.")
print("The Troll's health is now", thealth, "\n\n")
if roll == 3:
damage = random.randrange(3,9)
tdamage = random.randint(7,12)
thealth -= tdamage
health -= damage
print("Your Hero swings but the troll matches his strength"
, "and you both take damage")
print("Your Hero takes", damage,"damage. His health is now", health)
print("The Troll takes", tdamage, "damage. His health is now", thealth, "\n\n")
if roll < 3:
damage = random.randint(4,15)
health -= damage
print("Your Hero swings but the Troll blocks his attack and counters,")
print("Your Hero takes", damage,"damage. His health is now", health, "\n\n")
if thealth < 0:
print("Huzzah! Your Hero has Triumphed!")
print("The Troll is vanquished")
if health < 0:
print("Your hero fought valiantly...")
print("But alas, He is no more.")
input("\n\nPress the enter key to exit.")
(Update: here is the exe download link)
(Note: Just extract the files into a folder and run the program)
Don’t expect much. I’m new to this =) =P