Showing posts with label Games. Show all posts
Showing posts with label Games. Show all posts

Wednesday, 16 October 2013

Game #002 - Your Interplanetary Age

Game #002 on Github

My second game is another little tech demo which asks your age and returns its equivalent on every planet. Yes, another ground breaking show of technology!

I quite enjoyed make the interplanetary age calculator. This was mainly due to the challenges I encountered whilst coding.

Feature Creep


As someone in the IT (I am a software tester) I am very familiar with feature creep. The phrases "Couldn't we just" and "It would be nice if" are punishable offences around me!  I started #002 with the idea to ask the user their age, and break it down to months, days, minutes. It's a simple one, and a small step up from #001. Then I thought "Wouldn't it be nice if I finished with the user's age on Mars?" Yep, feature creep almost before I had started to code. A bit of searching later, I found a site with Your Age on Other Worlds. And the wish to write a python script which gives you your age on all the planets in the solar system was born. First I put together a table to help me with the different revolution periods of each planet. This formed the basis of my calculations further down the programme.

Planet Rotation Period (Earth days) Revolution Period (Earth years/days)
Mercury
58.6 days
87.97 days
Venus
243 days
224.7
Earth
1 day
365.25 days
Mars
1.03 days
1.88 years
Jupiter
0.41 days
11.86 years
Saturn
0.45 days
29.46 years
Uranus
0.72 days
84.01 years
Neptune
0.67 days
164.79 years
Pluto
6.38 days
248.59 years

The Int to Str, Str to Int Switcheroo 


When I started coding, I asked the person their age and updated a variable, put that variable into an equation, and print the answer. Simple. For a newbie like me, it took a little bit of research to find out why my code kept on failing. It was great fun. It turns out that the input command produced a string, which wouldn't play well with my equation. The solution was to take the user input and turn it into an integer. This meant that the equation worked.
The next problem encountered was that the print statement wouldn't work because the print command doesn't work with integers. Having researched the need to change the user's input to an integer, it was relatively quick to realise what needed to be done. The result was the following flow of code:

 print("What is your age?")age = int(input(">>> "))  
 mars_age_years = age / 1.88  
 print("You are " + str(mercury_age_years) + "Mercury years old")  

This bit of code would essentially calculate and print a user's age on Mars

Round, Float, Decimal - Who knows!?


If the code above is run the result is that you age is likely to be have a lot of numbers after the decimal point (eg. 5.319148936170213 if you input an age of 10). This doesn't scan as easily as having an  age to two decimal points. This is where the majority of my research came in.
I recall in java it is easy to restrict to a number of decimal points by wrapping your equation/result in float. In python there are three options, all with different foibles of their own. I won't go into them here as I don't entirely understand what the difference is at this point in my learning.
After a decent bit of research, I found that rounding the age to two decimal points produced the answer I wanted. So this:
mars_age_years =  age / 1.88
became this:
mars_age_years = round(age / 1.88 ,2)
I now had a working script I could apply to all the revolutionary cycles of all the planets.

Github Learnings


Part of the fun of this project is putting the code out there for all to see. Like many people I use Github. I have the windows client installed, and it is very easy to push everything to the cloud for all to see. I am researching whether there is an online python interpreter so the scripts can be run without the need to have python on the machine.
I had just finished the game and was attempting to put the final version up on Github when I inadvertently rolled back on my machine. Being new to it all, I attempted to revert to the version online, but because there was now a disconnect between local and git, I was getting an error. It took me two and a half hours to sort out what would have taken someone with the knowledge five minutes to do! I really need to be a little more careful with how I roll back in future.

Game #002 Conclusion


If you have taken a look at the script in full, you will note that everything is still very procedural. There are no functions defined, for example. This is ripe for a revisit further down the line to refactor just about every line of code to make it easier to read and maintain.
Another thing that needs to change is that the user input is incredibly brittle, and not very interesting. If you put 0 in, the programme crashes. If you put a decimal in, the programme will crash. A loop needs to be added to handle these two things.
And what about interplanetary days?! The site I found during my initial design and research calculates the user's age in days as well. This is particularly interesting as each planet's rotation period is vastly different. So, this would definitely be a good addition to the whole programme.

Watch this space.

Wednesday, 9 October 2013

The 100 Games Project

Well, it looks like my idea about blogging more didn't really take off. 10 months on from my last post and here I am with the second article of 2013. Let’s see where we go from here.

100 Games Project

The title of this blog is the 100 Games Project. It is something I am trying which will hopefully help me to learn programming in a fun and interesting way.

Last week I noticed a tweet by Z. A. Shaw, who wrote "Learn Python the Hard Way", mentioning Jennifer Dewalt had finished her 180 Websites in 180 Days project. I remembered hearing about this a while back (probably from Shaw himself), and went to take a look. For the past week I have been reading Jennifer's blog, following the journey from her first website onwards. I was impressed by how she took an idea, and then used Stack Overflow, Google, and anything else to work out how to complete the idea. This lead to was Jennifer encountering more advanced technology (than HTML and CSS) such as jQuery and javascript a lot sooner than in most book lead courses on web development.
Reading the blog got me thinking about my own attempts to learn programming and how often I have got to a point in a course and then given up, got bored, or distracted by another language (where I have usually repeated the same process). The 100 Games Project aims to take Jennifer’s process of using ideas to direct learning to help me with my studies in learning to code.

I am currently learning Python through Udacity's Introduction to Computer Science course. So far I have really enjoyed the show a little, test a little way of presenting the language. Plus the idea of building a web crawler is appealing. I know, however, that if I don't do other things with my knowledge, it won't bed in and I will end up getting to a point where I struggle, get bored, and then stop. The 100 Games Project should go some way to keeping me interested, and bed the knowledge in.

Why 100 Games? 

100 games is quite a lot of games, for sure. I expect a lot of them will probably be more of a tech demo than an actual game. Other games will probably be incremental versions of past games. Even so, I will try and do something new (for me at least) with each game. If I revisit the majority of an old game, it will be to significantly change what was originally coded.
In the same way that Jennifer did, I will also blog a little bit about each game, and uploaded everything to github. That way there is a record
of each game, and other people can take them and play (with) them as well. It will also serve as a reminder of where I started and where I got to should I ever complete the project!

I realise I have now rambled on for quite long enough. If you have read this far, well done. Other posts will definitely not be as long. This I promise.

Thursday, 3 April 2008

Games, Heroin, and Teenage Pregnancies - What's the Difference?

I have just read an article by Giles Whittell of The Times entitled Video Games: I'll never buy one. The reporter/contributor/"notebooker" describes why he will never be buying his children any games consoles. Apparently the answer is because games "suck real people into fake worlds and hold on to them for decades at a time." What a wonderfully broad and sweeping statement. And if that is his main reason, then maybe he should stop his children from watching TV, going to the cinema, surfing the internet, or reading.
Now, I am old enough to remember getting my first games console in the mid 80's, and have had many games machines since. I do not believe I ever wasted my life. I enjoyed playing games, because of the adventures they took me on. Just like reading, and going to the cinema. I enjoyed the social aspect of them; my mother and I used to sit up late into the night playing the latest adventure game.
I do agree in a small way with Mr. Whittell in that many children seem to be so intent on finishing the next level that they barely look around sometimes. For that, I do not blame games, I blame the parents. Surely, it is the parents who should tell little Farquar and Portia to put down their Nintendo DS until after dinner, or whenever. I know it's easy to blame the parents, but in this case I truly believe I am right. My parents used to make sure I stopped playing on my games console and went outside, or stopped playing my Gameboy at the table, and so on. Don't deny your children, but educate them enough to make their own choices and govern themselves.

And equating games with heroin and teenage pregnancies ("It's because, compared with everything else on offer in a kid's life, video games and heroin and teenage pregnancy are a colossal waste of time.") is just irresponsible. Well done for inciting people to read your article Giles, but it is a low blow, and a tenuous analogy at its best. 

Thursday, 22 November 2007

From The Register: eBayer punts Wii for £1m

eBayer punts Wii for £1m | Reg Hardware

For Christmas I really want to get a Wii. The problem is, everyone else does! Some enterprising sod has put  his/her Wii up for sale on ebay with a starting price of £1 million.

I'm not that desperate! If you do buy this, please give it to me. If you are stupid enough to buy a Wii for £1,000,000 maybe you'll just give it away to someone deserving... like me!

 

P.S. This is also testing the Windows Live Writer "Blog This" plugin for Firefox. Get it here.

Saturday, 14 April 2007

World or Warcraft - part 2

It is now 10:45 in the morning, a little while after my last blog.

I'm now downloading another patch! This one is small, just 219MB.

You would think that the patch would have been incorporated onto my disk vastly reducing the time I have to wait to play this game, and therefore increasing my chances of becoming addicted.

Right now I just feel frustrated, and can't really be bothered with the game.

I'm going out.

World or Warcraft

I sit before you ready to embark on what my gamer mates call "crack for geeks".

This is World of Warcraft.

The Times a couple of weeks ago was giving away a free two week trial of this game. I have now installed the game and am waiting for a small patch (697MB!) to install and update.
A quick sideline on patches. I started off my career as a tester at a games publisher in London. One of the games released, Fallout Tactics, had to be patched almost immediately (not my testing, our sister company). I say "almost immediately". What I actually mean is "on the day of release" (no wonder the company is no longer around). This patch was 80MB, and made industry people nearly pass out when they heard this needed to be downloaded, or requested from customer support.
"80MB on a 56k modem, that could take days!"
If you were paying per minute for your connection, you could end up paying almost as much as the original game. Ludicrous! This wasn't that long ago either, only in 2000.

So now I am sitting here blogging waiting for 697MB of patching goodness to download in "About 2 hours". I'm going to wait for it and play the game because I am curious to see what all the craik is about (see what I did there?).
10% downloaded...
World of Warcraft stormed onto the world stage in 2004 and has since continued to grow into a community of gamers 8 million strong. That's 8 million people paying approximately £8.00 per month subscription! For more information, I recommend you read the Times article. If you choose to give the game a go like I am, you can either request a disk from The Times, or you can download it from the World of Warcraft official site.

You see, I haven't even played the game yet and I am dealing it like an addict!

24% downloaded, still "About 2 hours" to wait...
It's only a game. Plus, it's only a 2 week trial, then I can give it all up.

30% downloaded, "About 75 minutes" to wait...
Tell my mum I love her.

40% downloaded, "About 65 minutes" to wait...
Tell the future Mrs. Mouse that I will see her at the wedding.

50% downloaded, "About 51 minutes" to wait...
Why am I sitting here watching a download?

60% downloaded, "About 42 minutes" to wait...
Bored, hungry, going for breakfast.

. . .

. .

.