![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#31 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 323
Rep Power: 4
![]() |
Re: back to online battleship
o ok, so im just confusing myself basically? I flipped the sends and receives around so they are opposite the takeTurn method so takeTurn1 uses send2() and receive2() and that seems to take the right boards but it still executes the move on the wrong player's board.
|
|
|
|
|
|
#32 |
|
Hobbyist Programmer
|
Re: back to online battleship
it would indeed appear that way lol just take a 5 min break get a coffee, then read through your code slowley and it will be clearer to you and you will notice the little out of place things
Chris
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
|
|
#33 |
|
Newbie
Join Date: May 2008
Location: teh interwebz
Posts: 22
Rep Power: 0
![]() |
Re: back to online battleship
ah yes the coffee break. I am emphasizing the importance of taking a break.
I would even take a longer break. maybe watch a TV show or play a video game for half an hour. When you come back to your code, approach the problem as if you weren't the author of the code. just work through it slowly and try to pinpoint exactly where in the code the problem occurs and go from there. works every time.. hehe
__________________
iEngage |
|
|
|
|
|
#34 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 323
Rep Power: 4
![]() |
Re: back to online battleship
alright i have no idea i think ive tried every possible combo of sending and receiving of different boards to the 2 players and can not get it to where player 1 moves on the other board. They always move on their own board
|
|
|
|
|
|
#35 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 188
Rep Power: 2
![]() |
Re: back to online battleship
For what its worth, I think that sending the board back and forth is a bad idea.
To approach this problem you should have classes that represent the board for each player. Then, you should have an additional class that represents an "Action request". This class would be able to interact with the two players, accepting a "strike attempt" and replying with either a hit or a miss, and requesting that each players "board" class update their board in response to this information. If you do not have this additional class, it will make the problem harder to solve. With this class, you can simply send an object of the class back and forth a couple times per turn and have each player update their board appropriately. You should not be using Client and Server to play the game. You should be using appropriate classes to represent the board. Then Player1 will take a turn, which will just update an Action Request object. Player2 will have a method, lets call it "evalAction". When Player2 receives the Action Request object, it will call Action Request object.evalAction(). evalAction should be implemented so that it will update the game board based on whatever is in the Action Request object. Then evalAction will update the Action request object again, and send it back to player 1. Lets look at a possibility of how this would work: 1) Player 1 enters information indicating he wants to hit a square, lets call is sq8 2) The Action Request object is updated, via a method (doesn't matter what it is), which will make the Action Request object basically say that Player1 is trying to hit sq8. 3)Player 2's evalAction method checks the Action Request object, and looks at varying information on its own board, such as was it a hit or a miss? Then Player2 calls its own method to update it's board, then calls a method to guess its own square. 4) This process can just be repeated on each Player. Also, I just saw that you were using ObjectOutputStream. You should note: I think ObjectOutputStream requires any objects sent over it to implement the class 'Serialized'. If you are sending over objects that do not implement the Serialized interface, this could be causing you problems. Last edited by Fall Back Son; May 17th, 2008 at 4:02 PM. |
|
|
|
|
|
#36 |
|
Not a user?
Join Date: Sep 2007
Posts: 231
Rep Power: 1
![]() |
Re: back to online battleship
why not just send 2 arrays, one with ship coordinates, and one with called shots coordinates to both players every turn to ensure they have the correct board setup. The player then sends a new shot to the server, the server adds it to the shots array and compares it to the ship coordinates array, then sends the results to the both players and a call hit or miss to the firing player. This keeps everything on the server, and players only get updates.
Of course what I posted is watered down, as you don't want to send all ship coordinates to both players, and you don't want to send all shots to both players. The client software is only responsible for taking the arrays and setting up the board, and prompting the player for a shot; no sending of the whole board, just the coordinates. Last edited by Jabo; May 17th, 2008 at 7:31 PM. |
|
|
|
|
|
#37 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 188
Rep Power: 2
![]() |
Re: back to online battleship
Because the correct OOP way to do it is what I described above. Also, because you can just send one object which can contain the information you want (however you want to store it, be it an array, whatever) which can provide useful methods for dealing with that information.
|
|
|
|
|
|
#38 |
|
Not a user?
Join Date: Sep 2007
Posts: 231
Rep Power: 1
![]() |
Re: back to online battleship
oic, I must have overlooked where he said it must be OOP oriented.
anywho, if this is something for fun, that's ok, but if it's ever intended to be put into serious use, the peer->peer model will be prone to hacking/cracking; even more so than a server->client model |
|
|
|
|
|
#39 | |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 188
Rep Power: 2
![]() |
Re: back to online battleship
Quote:
The end. |
|
|
|
|
|
|
#40 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 323
Rep Power: 4
![]() |
Re: back to online battleship
fall back son,
Your method does make sense and i will try to do this. I think part of the problem is i originally made it so the computer just used random numbers to simulate battleship and then tried to adapt it to play over a network thinking that the logic of the game is the same but it looks like i can't just force that and need to redesign it so the actions are handled better. I do have some questions though like that action request object how is that updated, and how does player 2 know about it and how does the server fit into it all? Like i have said i have never done any network programming ever so i guess im lost on the overall flow of the program? Last edited by cwl157; May 18th, 2008 at 4:52 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get an email to fill out an online form? | r2d246 | C++ | 2 | Jan 16th, 2006 12:42 PM |
| I am back | kurifu | Coder's Corner Lounge | 9 | Oct 21st, 2005 4:31 AM |
| Eternity Online | Lucid | Project Ideas | 4 | May 12th, 2005 9:54 AM |