Learn to Code - Build a Game
TalkIT January 2016 Newsletter
Contents
Learn to Code
How to Create the Game
Architecture First
Basic Project Setup
Can You Solve This Coding Problem?
Other Bits
Learn to Code - Build a Game
Welcome to the latest news from TalkIT. This issue is about learning to code by creating a game application. TalkIT have published an online game tutorial using Java. The tutorial is the conclusion of our Java online course. It provides an opportunity to consolidate the skills covered in the course. Take a look at our Java Course. The first tutorial is a free trial.
By focusing on building the game, you learn the rules and grammar of the programming language as a by-product. Creating a game is fun. You get an interesting result.
To make learning easier the tutorial includes videos, solution downloads and lots of code snippets. This is the video that gets you started.
Be warned building the whole game can take more than 10 hours. It includes some advanced skills.
How to Create the Game
The game, Dungeon of Doom, allows players to move around a dungeon collecting points.
- The idea of the game:
- Players are spawned in a darkened dungeon
- They can only see so much of the map and the rest is dark and not visible
- The aim is to collect a certain amount of gold laying in the map
- Then make it to the exit before another player or without dying
- You can pick-up items that can help you along the way such as lanterns and swords
- It is a turn based game, meaning you have to be strategic
- The components of the game:
- Multi-player
- Chat System
- Graphical UI
- The game has many parts but is easily extensible. You can fight in the game and kill opponents. You can run an AI bot on and off-line which I have partially implemented. This will allow you to test your skills but have support.
- The Rules of the game:
- Each player starts off with 6 APs (Action Points) which dictates how many things they can do in one turn (this can change depending on items they hold).
To read more about the game see the online tutorial.
Architecture First
When creating any complex application it is a good idea to first think about its architecture. From experience, I can say it is best to invest time at working on the initial design. This avoids refactoring most of your code to add a new feature.
The game uses the Model View Controller (MVC) architecture.
The components of the MVC are:
- Model: manages business logic classes and data access
- View: renders model objects with client-slide intelligence
- Controller: Handles incoming requests then chooses a view to render
Some of the benefits of using MVC are that MVC encourages separation of presentation and application logic. The model classes hold the application logic. These are reusable and consistent.
The game has many similar items that the users can pickup. Hence it would be useful to employ inheritance for game items. Best to create an item base class. Specific items will then inherit from this but modify it to their needs. This will save re-writing code and will also help with maintenance and upgrades.
With the above in mind I have created a diagram that should help explain the structure. We want keep classes as separated and self-contained as possible. Also use inter-class communication only when it is needed.
Read the whole blog.
Thanks to Steven Paske for creating the game and writing the tutorial
Thanks to Andy Olsen for Java snippet
Photos www.freedigitalphotos.net/
David Ringsell MCPD 2016 ?