Re: problem with applet ....
From: Andrew Skouloudis (afterskoulNOSPAMPLEASE_at_yahoo.com)
Date: 01/01/04
- Next message: SolutionPlanet: "HSSF Get formula value"
- Previous message: Jezuch: "Re: Java Code Convention Guidelines question..."
- In reply to: Andrew Thompson: "Re: problem with applet ...."
- Next in thread: Andrew Thompson: "Re: problem with applet ...."
- Reply: Andrew Thompson: "Re: problem with applet ...."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 01 Jan 2004 17:13:59 +0200
First of all , I would like to wish everybody to have a happy new
year!.
Secondly , some background about the application.
I am working on Windows XP , the browser is Internet Explorer 6 and I
have installed
Sun's SDK version 1.4.2.
Some info about the minesweeper for one player :
Once a new game starts, the applet creates a new board ("Board"). A
new board is nothing more than a 2D array of integers with dimensions
BoardrowSize , BoardcolSize and it is created using the following
algorithm (function Createboard):
1.)First of all initialize the board with the value 10 (these values
are important I will explain later)
2.)Place the mines on the board (number of mines : totalmines) by
creating a random pair of integers (x,y) with limits the
the size of the board
3.)After that place in each point(that is not a mine) the number of
its adjacent mines.If a point (i,j) has not a mine
next to it , the value of this point remains as initialized at the
beggining
After that board is created,another board is created called "matrix"
and it is the board that the player sees in the player applet.
All the points of this board are initialized with a value of ten.
Actually this board (the "matrix") when you start a new game ,looks
exactly
the same with the initial look of the board in the original
minesweeper in Windows games ....
Now , when you press a box on the "matrix" then it's value becomes
equal with the value of the
corresponding point of the "Board" and when the applet is repainted ,
the "matrix" is printed but now the
box you pressed is revealed according to the value exists in the
"Board" .
But you don't see integers you see pictures . Here is a small trick ..
.Inside a folder called img are
various small images , another image for mine ,another for flag etc
... These images when the applets starts
are loaded into a array of images :
param = getParameter("bImg");
img=new Image[13];
for (int i = 0 ; i < 13 ; i++)
{
img[i] = getImage(getCodeBase(), param + (i) + ".gif");
}
so ..
j9.gif corresponds to a mine
j0.gif corresponds to an empty box
j11.gif corresponds to a flag etc .....
I think that it is now obvious how you play ... Just see the following
code :
for(j=0; j<BoardrowSize; j++)
{
for(i=0; i<BoardcolSize; i++)
{
g.drawImage(img[matrix[j][i]], iX+(j*15), iY + (i*15)
, this);
}
}
You just draw Images according the values of the "matrix" board . A
simple example
Suppose that the first line of the "matrix" is :
0,0,0,1,1,1,4,5,9
The first line of images that will be printed is :
image[0] image[0] image[0] image[1] image[1] image[1] image[4]
image[5] image[9]
or ...
empty box,empty box,empty box,one,one,one,four,four,five,mine
Of course you cannot see anything if you don't have the Img folder
...
Lets go now the network version ...
After you have created sockets etc,the server creates a board as I
discribed above and then
Server sends the board to the client (I have managed to write that).
When I say that the server
sends the board to the client I mean that the server sends integers
and of course not images..
Now here is my problem : I don't want the client(or the server) to be
able to play (that is to click on a box
and change the board ) until he sees the box that his opponent
revealed. Example when the
game begins, its server turn by default :
--> The server clicks a box on his board (i,j), the client cannot
click on his board
--> The "matrix" is repainted at servers applet,the client cannot
click on his board
--> The server sends two integers (i,j) to the client,the client
cannot click on his board
--> The client receives these two integers (i,j) ,the client cannot
click on his board
--> The "matrix" is repainted at clients applet,the client cannot
click on his board
--> The client clicks on his board (l,m) , the server cannot click on
his board
..............
..............
..............
I know that my English is awfull but it s clear what i have done and
what not ..
you can download here the images and the source code :
http://users.ntua.gr/el99063/java.zip
Note : mr Tompson and mr Woods i wrote down your remarks but I am
trying to make one step at a time , Java is different from C/C++ that
I have learned !!
- Next message: SolutionPlanet: "HSSF Get formula value"
- Previous message: Jezuch: "Re: Java Code Convention Guidelines question..."
- In reply to: Andrew Thompson: "Re: problem with applet ...."
- Next in thread: Andrew Thompson: "Re: problem with applet ...."
- Reply: Andrew Thompson: "Re: problem with applet ...."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|