aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes 2 Player Connect 4 game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "2 Player Connect 4 game" Watch "2 Player Connect 4 game" New topic
Author

2 Player Connect 4 game

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi, I've just managed to make a simple chat web application.
Basically each line of text a user enters, is saved as a context attribute.
and all the context attibutes are displayed by redisplaying the screen every 5 seconds.

I was thinking of extending this to a 2 player connect 4 game. I was thinking of generating a jpg image (using BufferedImage) in the servlet, to display the board and pieces dropped.

The problem is selecting the column(1-7) to drop your piece in.
A crude way would be to just use a <FORM> and <INPUT TYPE='TEXT' NAME='COLUMN' > tag in the jsp page, then parse this to an int in the servlet, or perhaps use checkboxes, ideally, getting the column to light up (or something like that)when the mouse moves over it would be good.
But I only know how to do this in a Frame/JFrame, not over a jpg image in a webpage.

Any thoughts and ideas would be much appreciated.
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61412
    
  67

It is not clear what your question is.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18643
    
    8

My interpretation of the question is "How do I allow the browser user to select a particular position in an image?" The servlets part of the question is just a red herring.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61412
    
  67

Yeah, I'm leaning that way too. All of that is client-side technology, so moving off to the HTML/Javascript forum.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61412
    
  67

You might want to look into image maps.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Thanks,
I've just found this website on image maps (never heard of them before)
The site is Image Maps
I'll let you nice people know if I have any problems
Thanks again.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi again,
Ok, I've got a simple Image map working, but here is my problem
I'm making a two player connect4 game. There will be an image of the board
on the html page, which is basically 7 columns with red and yellow
counters in the columns.

With this piece of code...

clicking in either of the rectangular regions takes you into the
Connect4servlet.
So what I really need is 7 rectangular shapes, I could (crudely) have
7 servlets Connect4servlet1, Connect4servlet2, Connect4servlet3,...
With each sevlet updating the specific column.
But 7 (virtually identical) servlets seems almost criminal, if I could just
pass the x-value of the mouse coordinate into the Connect4Servlet, (like when using <FORM> and <INPUT>, then using request.getParameter("Name") in the servlet) I could solve the problem of knowing which column was chosen
using just the one sevlet.

Can anyone help me with this?
Thanks very much
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18643
    
    8

How about one servlet, and you pass different parameters to it based on which part of the map was clicked?
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
AHHHH

Wow, thats genius, why didn't I think of that!!
I was pathetically trying to stick <INPUT TYPE='HIDDEN'...> tags
inbetween the <AREA> tags, but that obviously wouldn't work.

Your method essentially sets the parameters for you in one go.
Thanks very much, I'll try it out now
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 Player Connect 4 game