Home

Java based-simple game

· oth3rside

edie/surabaya/July,30,2009 .

Since two month ago, I had learned Java periodically from several e-book from internet (thank for all guys for providing those book free). My motivation learns java is because it’s multi platform capability. Learning Java one time, you can code on several environment : desktop, server, embedded system ( smard card is the smallest embedded system that can be programmed by Java ) , and mobile phone. This like Java’s motto : “One coding , run everywhere”. Remember that C/C++ have motto “one coding, compile everywhere” .it nice too. Ok, let we discuss about the game. This game is my first useful program (in my opinion  ) that I programmed by java . it’s a memory game like common memory game as you ever played. There are some rectangles which you should search where it’s couple. In this game I used number (for simplicity) not symbol to sign a rectangle. Suppose you choose 4x4 rectangles, so there will be 8 couples rectangles that you should eliminated. The game is simple but not easy especially if you choose more than 4x4 . The list menu on the GUI make you easier to determine how many rectangles which you want to play. I build the game using Model-View-Controller (MVC) design pattern. It’s not good code may be. Design pattern is new material for me and this is my design pattern’s exercises. Below is explanation for each class :

  1. #MainGmem.java Main class of program. On the mvc architecture, this class act as control side. It monitors input from user like number of rectangles, color of rectangles, etc.

  2. #kotak.java Define a rectangles and it’s properties. What is it color & number and what is it state: active or passive. Passive state mean rectangle will be disappeared, and vice versa.

  3. #gViewSetting.java An info tab.

  4. #gView.java This class handles game’s GUI particularly rectangles in the game. This class is an observer class, so what happen in gModel class will be known by this class. User mouse’s input for playing the game also handled by this class.

  5. #gModel.java Define model of the game. Game consist of array of rectangles. Colomn and row are given by user. gModel.java is observable type class, so all changed on it will be known by all observer class. This class handle :

  • filling number on each rectangle

-rectangles clicked by user

-number of failure guess

-state of the game. there are two states : memorizing and playing.

-rectangles remainder

-etc.

Screen shot of the game:

memGame2

Download

To run this game you must install JVM (Java Virtual Machine) on your computer and make sure that you set the path.

Keyword: program game sederhana java code