Wednesday, 9 October 2013

Game #001: Greeting

Github

Remember, my posts are like buses. You wait 10 months for one, then two come along straight away!

I have uploaded my first game. As I said in my first post, many of these will probably be a demo of something, rather than a full-on game. And this is no exception.

Greeting.py is a script which will ask you your name and then greet you. It's such a small script, I can post it in its entirety.


print ("Hi! What is your name? ")
name = input(">>> ")

print ("Welome " + name + "! I hope you enjoy your time browsing the 100 Games project.") 

The main feature of this script is to get the user's input. For games to be interactive, they require input of some kind from the user.
Obtaining the user's input is cunningly done via the input command. Whatever the user types in will be assigned to the variable name for use in the next line, the welcome statement.

Ways to enhance this script may be to only accept characters A-Z, filter out swear words using a dictionary, limit the number of characters a user can input. The list is endless! I will probably want to use some of the above ideas in later games when I interact with users in more complicated games.

P.S. I used the standard highlight function of blogger to make the code look code-y. I realise it looks a bit pants right now. Hopefully I can find a way to style the code snippets better in the future.
[Edit] Found it! Code highlighted

Tags for google+: #Python #100Games #Game

No comments: