![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Professional Programmer
|
Re: back to online battleship
OK, so your server must wait for two people to connect, once that is done execution can continue. It should first ask P1 to send there board and store it. Once it has recieved P1 Board it asks for and recieves P2 Board.
Once that has been done you can enter a loop, that is continues whilst gameWon = False. In the loop you want to do something like this. while(gameWon==False){
P1.requestMove();
P1.getMove(); //stall until move is recieved.
P2.boardUpdate(); //makes player ones move onto P2's board to check for hits etc
isWin = P1.CheckWin(); //check to see if P2 has any boats left
P1.sendMoveStatus(); //Show hits miss....
P2.sendMoveStatus(); //result of P1's Move.
if(isWin == True){
P1.send("P1 Won");
P2.send("P1 Won");
break;
}
P2.requestMove();
P2.getMove(); //stall until move is recieved.
P1.boardUpdate(); //makes player two's move onto P1s board to check for hits etc
isWin = P2.CheckWin(); //check to see if P1has any boats left
P2.sendMoveStatus(); //Show hits miss....
P1.sendMoveStatus(); //result of P2s Move.
if(isWin == True){
P1.send("P2 Won");
P2.send("P2 Won");
break;
}
}
//close connections or whatever comes nextIs that any help to you? Chris
__________________
Steven Skiena - Algorithms ,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],brainf**k -- It's such a pretty language Last edited by Freaky Chris; May 15th, 2008 at 1:32 PM. |
|
|
|
|
|
#12 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
Re: back to online battleship
now i am wondering about what wizard said if the clients keep their boards separate because i already have a version where each client sends the move to the server and the server passes it to the other client and executes the move, could i just then have the client send through the server if the game ends or not to the other client? As for what you said i think i am pretty much doing that now but it gets confused because server only takes every other move because it still plays with only 1 player so the player 2 move is not done or something here is the code i have:
client java Syntax (Toggle Plain Text)
Here is the server java Syntax (Toggle Plain Text)
Last edited by cwl157; May 15th, 2008 at 2:20 PM. |
|
|
|
|
|
#13 |
|
Professional Programmer
|
Re: back to online battleship
indeed you can. To do that simple send the players move to the server, have the server send it on to the other player. The player then checks the mova against his board and returns the result back to the server and then back to the original player.
What happened to the code you posted? Chris
__________________
Steven Skiena - Algorithms ,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],brainf**k -- It's such a pretty language |
|
|
|
|
|
#14 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
Re: back to online battleship
yea thats what i kinda had, but it only worked for the move so when the game was over the other player had no way of knowing the game ended but i guess i could have the client send that the game is over to the server and then the server would send it to the clients and end the game
|
|
|
|
|
|
#15 |
|
Professional Programmer
|
Re: back to online battleship
It should go from 1 player to the next fine, your while loop doesn't appear to be the problem how ever it may be something to do with how your are changing boards. You call p1.takeTurn(b1,.....) when player1 makes a move and then you call p2.takeTurn(b1,...) when player 2 makes a move. So your only changing 1 board, this maybe the problem you are having.
Chris
__________________
Steven Skiena - Algorithms ,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],brainf**k -- It's such a pretty language |
|
|
|
|
|
#16 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
Re: back to online battleship
ok i fixed that and now that and now every move works but only with 1 player and 1 board. The other player enters their name and gives their board but then never gets to move
|
|
|
|
|
|
#17 |
|
Professional Programmer
|
Re: back to online battleship
does takeTurn2() get called?
I think you may find that the reason player to never gets to play is because in takeTurn2() you call send(), which is sending it to player one and not player 2... Chris
__________________
Steven Skiena - Algorithms ,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],brainf**k -- It's such a pretty language |
|
|
|
|
|
#18 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 343
Rep Power: 4
![]() |
Re: back to online battleship
how do i get it to send it to player 2 i thought send worked for both of them
|
|
|
|