• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

2 Player Connect 4 game

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not clear what your question is.
 
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I'm leaning that way too. All of that is client-side technology, so moving off to the HTML/Javascript forum.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to look into image maps.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about one servlet, and you pass different parameters to it based on which part of the map was clicked?
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic