473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Battleships game

Hello there,

I have currently started a project in java, a battleships game. I am having trouble deciding how to deploy the grid and have the pictures of ships hidden under each picture of blue square which represents the sea. Can anybody out there give me some helpful pointers? Much appreciated,
thanks,
Ragaman
Nov 12 '06 #1
4 1770
r035198x
13,262 8TB
Hello there,

I have currently started a project in java, a battleships game. I am having trouble deciding how to deploy the grid and have the pictures of ships hidden under each picture of blue square which represents the sea. Can anybody out there give me some helpful pointers? Much appreciated,
thanks,
Ragaman
Do you know how to animations in applets?
Nov 13 '06 #2
One method could be to have a grid of JButton objects. You could have say a two dimensional array of JButtons and then when a user clicks on the JButton, the appropriate image/icon of either the ship or nothing eg a hole in the water appears.

To make these images appear you will need to know something about ActionListeners and also Image creation/manipulation

http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html

is a good starting place.

To create a two dimensional array of JButtons you could do something like this
Expand|Select|Wrap|Line Numbers
  1.         JButton[][] battleshipgrid = new JButton[10][10];
  2.         for(int i=0; i < battleshipgrid.length; i++) {
  3.             for(int j=0; j < battleshipgrid.length; j++) {
  4.                 // create new button with a label. Can use an Icon here too.
  5.                 battleshipgrid[i][j] = new JButton("My Button"));
  6.             }
  7.         }
  8.  
Nov 13 '06 #3
Thanks a million man, I appreciate it, i will give it a go.

Regards,

Ragaman
Nov 13 '06 #4
Hello everyone,

I am still working on my battleships project and have been doing some research into how i am going to implement it. I have been working with the idea of having a 2d grid of JButtons and have been looking into the graphics tutorials on the sun wesite but i have been advised that i would not need any of this (such as AlphaComposite) to display and change the display of the sea, ships etc. If so, does anyone have any ideas how to display the images, as in, is there a way of having the images appear in the JButtons themselves?And then change them?

Thanks a million,

Ragaman
Nov 19 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: BlackHawke | last post by:
My name is Nick Soutter, I own a small game development company (www.aepoxgames.net) making our first game (www.andromedaonline.net) in java. I am writing because we are having a very...
138
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
1
by: fowle040 | last post by:
I underlined and bold print my files. I need to know how to make this code into a working game. The object of the game is to have two players 1- belle and 2-beast. I want them to lose and gain...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
2
by: ragaman123 | last post by:
Hello everyone, I am currently working on a battleships game and at the moment i am playing around with a interface which has various different buttons. The interface has a 2d grid of buttons and...
5
by: Kraken | last post by:
Hi, i have a bit of a problem here. I have an assignment to do an animal guessing game using an original database and updating it as the user enters new animals in it. The program enters the file...
2
by: LilMeechc20 | last post by:
Hello, I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.