Java game

• 10-12-2002, 05:01 PM
katja
Java game
Hello! I'm trying to write a game in Java. The Sea Battle game where you should hit and sink the opponents ships...
It has to be in a field 10x10 squares and i had written the code for a square. Here it is:
import java.awt.*;
import javax.swing.*;

public class Tile extends JButton{
public Tile() {
super("");
}
public void paintComponent (Graphics g) {
g.setColor (getForeground());
}
}

But i have know idea what to do next. I know I should put them in a Grid Layout, but how the hell should I programm the ships?
• 10-14-2002, 05:02 PM
Shawn Curry
Making a game is no easy task... There are utilites for rendering 3d objects and extracting all the sprites you need. As for torpedoes and blowing ships up, thats gonna take some heavy math. You need to generate an applicable physics model (Vectors for the torpedo trajectory, coordinates of all the ships, and the outline of the ships to register hits, etc). It would be cool to explain it in a couple paragraphs, but people go to college for YEARS to study programming, and study programming for YEARS after they get out to get good at game programming. I'd reccommend "Tricks of the Windows Game Programming Gurus" by Andre LaMothe(SAMS) for starters, but your gonna need some understanding of C to see whats going on.
• 10-14-2002, 07:24 PM
katja
Java Game
No,No,No... Not thst kind of game. The game like in the attached picture. THe concept is:
You have a board with squares 10x10, where you can randomly place 1 4-squared ship, 2 3-squared, 3 2-squared and 4 1-squared. Ships can only be placed vertically or horisontally (not diagonally) and the squared of two different ships can't touch each other. The play should try to hit all the ships in as little time as possible. Look at the attached picture. The red squares are the ships the player has killed and the crosses are the empty spots where there aren't any ship. It's extremely simple game which requares a little knowledge in Java (My teacher said he could write this game in an hour, I can't).
Anyway if you can't help me with this, maybe you vcan help me to write a code for the TicTacToe?http://C:\Documents and Settings\Kat...ment\sankaskep
• 10-16-2002, 03:33 PM
tommysphone
Battleships
A great game. My brother and I played this for hours when we were kids. Great for rainy days.

html page and images attached. Save in the same folder and play on :)
• 10-16-2002, 03:36 PM
tommysphone
tic tac toe
Here is the script (attached) :) Njoy.
• 10-16-2002, 03:37 PM
tommysphone
The battleships stuff would help
Sorry, here it is. Save it all in the same folder etc etc.

On another note, I know you where supposed to write this yourself but a teacher should not boast about how quikc or how good they are but encourage a pupil. So we are getting our own back.
• 10-16-2002, 06:07 PM
katja
Thank you all very much, but I don't need an applet. I need the program which extends from JFrame and has a main method:
public static void main (string[] agrs){...}:rolleyes:
• 10-16-2002, 07:09 PM
katja
Java Game
Another tricky question.
A have another game, consept is that a player pushes the "Start" button an dbackground should change color, as soon as that happened tha player should press the "stop" button, and tha message dialog should come out telling the player how much time did it take for him to push the "stop" button. Any ideas how to do that?:rolleyes: