hi all .
I wrote a tic tac toe game in java using client server.
the server rule was to get the clicked square and check on board and return result .
but now i need to build one which the server only get tcp connection from my client (the orignal program also used TCP).
i only need to build the client( plus the thread) becouse the server is unknow to me.
I ran into some terables importing the server side to the client ( like chossing who goes first and stuff like this)
The question is can some one have a built code for a simple game that uses turn base game that the server only transfer connection between them ??.
or can someone help with some insites.
[edited by - firepowergd on April 15, 2004 4:36:29 PM]
Not sure I understand, are you saying that the server just passes messages between the client players, and the client players each maintain all the state information for the game themselves, updating each other every time they make a move? I guess you could do it that way. What exactly is the question here?
Moo moo MOO moo moo
[edited by - Bovine Supremacy NOW on April 15, 2004 5:36:38 PM]
I haven''t but it would be simple enough. I assume you have some kind of protocol - say a simple integer protocol. 1, followed by the row and col for a client making a move. 2, A reply from the other player that the move is valid, at that point both clients would understand that the turn has switched, and if it was your turn before than now you are waiting to recieve a 1 from the other player. 3, this player has achieved tic tac toe and has won. You would have to have a protocol for figuring how plays X and who plays y. 4, request to play x, say. and 5, start game.
I suppose the use of doing a game this way would be to have game clients use a generic server that would service many kinds of games, but there is the risk of somebody hacking the client to cheat somehow, not that it''s going to be the end of the world if somebody cheats at tic tac toe, although I guess there could be money on the game or you''re playing to the death or slt.
One option is to use RMI - look at Sun''s tutorial on it.
It may be old, but it works (and is quite neat really)
There is an alternative "AltRMI" - which I haven''t used, but it''s basically the same but with a few cleverer ideas.
Using RMI you can create a server object which the clients can call methods off directly, and send (serialisable) objects back and forth.
In a tic-tac-toe (Noughts and crosses we call it) you could create a small class for the board state, another one for an individual move, and have them passed back and forth between client and server.
Another (more advanced) thing you can do with RMI is pass references to client-side objects back to the server and have it do "callbacks" - these are useful if you want to wait for the other player to make his move. You essentially set up an event which is kicked off when it''s your turn.