This is a little snippet of code I wrote for destroying an object in a game I’m working on with pals. See the comments in the code for an explanation. I used currentTimeMillis(); just to check that the code was working as it should, and left it in for demonstration purpose. The output is:

Baddie hits wall, start timer: 
Baddie is dead!
Time Taken: 3000
BUILD SUCCESSFUL (total time: 3 seconds)

Of course, the above output will not display in the game, the action will be represented with an animated ‘Sprite’ of some sort meeting a grizzly death.

* This program will be attached to a game character, the 'Baddie'.
* When Baddie collides with a wall, he hangs around for 3 seconds (roughly)
* then he dies.
* This program is the timer delay logic used to destroy the character.

import java.util.Timer;
import java.util.TimerTask;

public class TimerDelayTask {
static Timer timer;
static TimerTask TimerTask;
static long startTime = 0L;
static long elapsedTime = 0L;
static int seconds = 0;

public TimerDelayTask(int seconds) {
timer = new Timer();
timer.schedule(new Reminder(), seconds * 1000);
startTime = System.currentTimeMillis();
//inner class

class Reminder extends TimerTask {

public void run() {
System.out.println("Baddie is dead!");
System.out.print("Time Taken: ");
System.out.println(elapsedTime = System.currentTimeMillis() - startTime);

public static void main(String[] args) {
new TimerDelayTask(3);
System.out.println("Baddie hits wall, start timer: ");

TreeSet For Sorting Order

Posted: 21st November 2012 by Peter in Java
Tags: , , ,

We’re covering ‘Collections’, ‘Collection’ and erm…’collection’ in Java Programmer 6 at the moment. I’m familiarizing myself with the various Sets, Lists and Maps.

A TreeSet orders its elements using ‘natural ordering’, i.e. alphabetical order for Strings, numerical order for ints. This is a very useful feature of the TreeSet that I wanted to experiment with. I wrote the following program that uses an overloaded method ‘getSortedTreeSet’ that will take a String array, or an int array, and return them as an ordered String for output.

* Take in a String array, sort the contents into alphabetical order
* and return the ordered contents as a String. Then do the same for an
* int array, overloading the method.

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class SetsListsMaps {

public static void main(String[] args) {

//String array and related String method output
String[] strAr = {"b","c","f","a","d","e","i","h","j","g"};

//int array and related String method output
int[] intAr = {9, 5, 1, 8, 4, 6, 2, 3, 7, 0};

public static String getSortedTreeSet(String[] ar) {
String str = "";
String[] myStrAr = ar;

//create TreeSet...
Set set = new TreeSet();
for (String strTemp : myStrAr) {

//TreeSet to String
//Iterator hasNext() and next()
Iterator iter = set.iterator();
while (iter.hasNext()) {
str += (String) + " ";
return str;

//The following is the same as above, but with Integers
public static String getSortedTreeSet(int[] ar) {
String result = "";
int[] myInt = ar;

//create TreeSet...
Set set = new TreeSet();
for (Integer intTemp : myInt) {

//TreeSet to String
//Iterator hasNext() and next()
Iterator iter = set.iterator();
while (iter.hasNext()) {
result += (Integer) + " ";
return result;

“My Card”

Posted: 18th November 2012 by Peter in Misc. Updates

Peter McCormack RobotBash.comCheck out my new business card (mostly for distribution amongst my peers :)). I ordered these online and received them in the post about a week later. Including postage and packing, 250 of these ‘bad boys’ cost only €15. The card is full colour on one side, and blank on the other. This suits me because I can write the venue location or event where I met the new contact. This will give them a frame of reference and hopefully help them recall our meeting when they review their card collection.

Of the seven lines of text, five of them are ways for people to connect with me – sure why beat around the bush? There’s plenty more business card services online if you’re considering personal branding options. It’s all just a bit of fun anyway. I’m half thinking of getting a t-shirt with my favourite robot on it…hmmm…


OCJP Collections Frameworks…

Currently studying Collections Frameworks in OCJP 6 course. I’ll be honest, some of it is tough going but the mist is starting to clear. I can see the power and usefulness of Sets, Lists and Maps, so I’m pretty excited about getting to grips with this material.

Regarding Job Prospects…

I’ve connected with some excellent IT recruitment agents from several agencies. I’ve received positive feedback in relation to my experience, qualifications  and this very website (go!). I hope to meet a couple of agents face-to-face in December, with a view to arranging several interviews in December and January. I also hope to interview for some intern positions next month, fingers crossed. Things are looking good for 2013.

Extra Studies…

I’ve decided to take on a little extra study that I can do at my own pace at home. Two areas I’m going to explore further are Database and HTML 5.

mysql-logoWhy Database?

I picked Database because I’ve tippy-toed around mySQL for years but have never been brave enough to just dive in. Career-wise it’s a good move, SQL is not going away anytime soon. There’s lots of free educational materials for Database online, and Stanford University have an entire course (complete with videos and tests!) for free. I’m looking for some study buddies so check out and give me a shout.

HTML5_LogoWhy HTML 5?

Well, I’m not starting with HTML 5 from scratch, but I want to go deeper into this technology. I’m going to try kill two birds with one stone, and study HTML 5 for both web, and Android apps development too. HTML 5 is hot right now, and it’s fast replacing ActionScript for web and game development. It’s got some amazing features like masking, support for video and lots of other cool stuff.

GameCraft Update:

Ah, bad news here I’m afraid. Unfortunately there were so many registered for the event that I could not secure a ticket. Not to worry, whispers in the wind say there will be another GameCraft in the new year. Gobal-Game-Jam-logoTo help recover from the disappointment I sponsored a web package including .com domain, web hosting and WordPress template site as a prize for the event.

I also set-up a local CoderJam group with some of my programmer classmates. We plan to make our ‘big splash’ in the community January 25th 2013 at host site Griffith College for the Global GameJam. Platform of choice? Unity with JavaScript… After that, we’re going to build some software projects together, so plenty to look forward to.

Game Maker Makes Making Games Easy

Posted: 2nd November 2012 by Peter in Irish Games Industry News

Click This Image To Download The Game.

In preparation for the GameCraft event, I thought it sensible to familiarize myself with Game Maker(Lite). The software is often used to quickly create game demos, as well as ‘polished’ finished games.

While every bone in my body wants to build and code a game from scratch, I decided it best to use the beginners tutorials available online at These tutorials will give me a sound understanding of the platform, and a couple of games to show in my portfolio, so how bad? Once I have a grip on the software, I’ll create my own games from scratch, using the advanced feature to code behaviours and events.

Simple Game To Start With

The game attached to this post is an exe file, click on either of the images in the post to download it. The challenge is simple, click on the clown heads and watch your score increase (at the top left of the window). The clowns will randomly change direction, bounce of the wall, and speed up each time you click on them. All the action is set on a simple stage, called a ‘room’ in Game Maker, and there are several sound effects to add a little spice to proceedings.

The images and sound files, with complete step-by-step instructions are available at the page linked to above. Just download the tutorial to your PC and get cracking. 

Click The Image To Download The Game:

Click This Image To Download The Game.

Game Maker The Verdict…

I’m impressed with the ease of use, and speed of development.  The stand-alone .exe file is just under 4MB (which I think is a little heavy compared to Flash stand-alone files I created in the past). However, I haven’t looked into compression options for publishing yet, so perhaps that size could be reduced. The free version carries a watermark which I can live with for now, though I’ll probably purchase the standard edition eventually which is about $50. Thanks to the author of the tutorial, Mark Overmars for sharing his knowledge!

We’re studying try-catch-finally exception handling at the moment, this is my solution from the Exercise 5-4, page 377 of SCJP 6 Study Guide (Sierra & Bates). I also used reference from this website section 1.9. I wrote the code in Notepad++ and compiled and ran it in Windows command-line.

Exception Gets Handled!

A String array of food is being tested against the try-catch. When the food ‘beans’ (as in ‘tinned beans’, which I don’t like) is tested the exception is thrown and all hell breaks loose (not really, because the exception is handled! Hurrah!)

It’s heavily commented for my own reference and yours.

//created the custom exception in an inner class,
//must extends Exception which is part of java.lang
class BadFoodException extends Exception{
//constructor takes a String argument.
//super(str) takes custom text from String when we throw new
//BadFoodException, which is printed to screen from
//ex.getMessage() in the catch block
public BadFoodException(String str){
System.out.println("BadFoodException is used when the word beans is encountered");

//primary class
public class MyException{

public static String [] array;

//main method
public static void main(String [] arg){

//create array of foods
array = new String [] {"cabbage","chips","apples","beans"};

//try-catch array elements against the custom exception
//with checkFood() doing the exception checking...
for(int i = 0; i < array.length; i++){ String myFood = array[i]; checkFood(myFood); } } catch (BadFoodException ex) { //exception handler ex.printStackTrace(); System.out.println(ex.getMessage()); } } //method checkFood() public static void checkFood(String food) throws BadFoodException{ if(food.equals("beans")){ throw(new BadFoodException("I hate beans!")); } System.out.println("yummy!"); // skip if exception is triggered } //end method }

GameCraftI’m extremely pleased to report that I have been accepted as the forth member of the BH games team for this years GameCraft || event (Dublin 17th November). This will be my first game jam and I’m really looking forward to meeting and building a game with my teammates and everyone else at the event.

So what is GameCraft?

Teams or individuals participating in the challenge will each be invited to build a game in 12 hours. The theme of the game will be revealed during breakfast at 9am, and it’s all hands to the pumps until 9pm that evening when judging will begin (click to see a list of judges on the official site here).

There will be about 80 participants attending, with a mix of disciplines including coders, digital artists, animators, multimedia and so on. Participants will have various levels of experience; some being seasoned game development professionals, and others complete newbies like myself.
Click to check out some photos on flickr from last years GameCraft.

Game Over And Everyone Wins!

The games will be judged on playability  and there are prizes of some sort for the winners. The way I see it, everyone wins, and I’m as excited about meeting the community as I am about building a game.

Roll on November 17th!


Want Your Own Java Yellow Belt? Click The Image...

Just a quick update to report that I have earned my Java OO Fundementals Yellow Belt. Passing this exam, combined with my SCJA 6 qualification means I now officially know enough Java to work with IT companies. Add to that my digital multimedia, animation, and training qualifications, plus years of work experience and problem solving…<insert trumpet horn sound here>

Anyhow, the goal is to pass Oracle Certified Java Programmer 6 by the new year, so back to the books! 

P.s. Want To Get Your Own Belts?

For those programmers/web developers who what to know more about how to get free Java courses, workshops and coach supported training and exams (all provided by a community of your peers), check out

I may actually have time to do some coding, now that I’m a Java Associate (see last post) and the intense studying has ended for a while. To kick things off I decided to go back to some of the early tutorials our class studied in the first month or so of the SCJA 6 course. At the time, the palindrome program we covered was pretty confusing, and I wanted to see how I’d fair trying this without revising my notes.

I produced the code below. There may be better ways of checking if a word is palindromic, but this one works just fine as far as I can see. I commented it throughout, so hopefully Java Noobs will follow easy enough. You can copy and paste and run it in your IDE. Test it with ABBA, ABBBA, AB BA, AB56BA etc.

Basically the code takes a word input by the user and makes a reversed copy of it. Then it checks to see if both words have the same content with the String .equals() method. If the word is the same in reverse then we have a palindrome. The rest of the code checks for empty spaces in the word, and checks to ensure only characters are input by the user.

I’m open to advice/critic so please feel free to comment below any suggestions you may have regarding the code!

package palindrome;
import java.util.Scanner;
* @author
public class Palindrome {
* @param args the command line arguments
public static void main(String[] args) {

//Read in with Scanner
Scanner buffer = new Scanner(;
System.out.println("Type a word here to be tested for palindrome: ");
String input = buffer.nextLine().toLowerCase().trim();

//Checking: if the input is not a character
if (!input.matches("[a-zA-Z]+") || input.contains(" ")){
System.out.println("Invalid input, you may have entered a number, "
+ "space or non-character. Start again!");
//create a new reverse string
String reverse = new StringBuffer(input).reverse().toString();
//compare the strings
if(input.length() > 0 && input.equals(reverse)){
System.out.println("The word you entered is a palindrome.");
//Checking: if they don't enter a string and just hit enter...
else if(input.isEmpty()){
System.out.println("You did not enter a word. Start again!");
//if the string is empty or is not palindromic...
System.out.println("You did NOT submit a palindrome word.");

I’m SCJA 6 Certified!

Posted: 14th October 2012 by Peter in Java
Tags: ,

javadukelogoI’m currently house bound with a particularly nasty case of the dreaded Man-Flu. Despite my suffering I’m feeling fairly pleased with myself.

I completed the Sun/Oracle Certified Java Associate 6 exam 11th Oct, and am pleased to report I passed with a 90% grade. There was no UML or ‘associations’ questions encountered by my classmates or I. I’m kicking myself for incorrectly answering a couple of tricky ‘applet’ related questions, but what is done is done.

Some Resources For Those Studying For SCJA 6

For those preparing for the exam, read…:

  • SCJA study guide is a must read
  • Also the Head First for associate.

For video tutorials check out…:

  • Mark Lassoff’s videos, particularly for Java Enterprise Edition
  • Bucky Roberts ( for Java programming beginners videos.
  • There are also some excellent videos if you don’t mind paying for the monthly subscription.
For mock exams you should consider the following:
  • uCertify – sign up and get a few free questions
  • MeasureUp are also worth a look.
  • Check out for free online tests (they are generally tougher than SCJA 6 exam questions but good for practice and study guide reference).
  • The SCJA Study Guide includes a disk of questions and a free download for many more.
Take note regarding online mock-exam question services like measureUp. Many present questions that a just outside the scope of SCJA 6, which you’ll find difficult to answer.

Near Future…

As of now I am studying for SCJP 6 exam which I will take sometime in December or early January. Studying for Java Associate is an excellent introduction to object orientated programming, and to the Java Enterprise Edition, but actual programming is not the main focus of Java Associate. My goal with SCJP is to lock-down my programming skills and identify the enterprise area I’d like to specialise in for the next year or two, i.e. JSP developer or database tier etc.

All of the above depends on my surviving the Man-Flu of course, fingers crossed.

Onward and upwards!