![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 327
Rep Power: 4
![]() |
online game
I completed the battleship game that i was working on and posted that other thread with the question but now i have another question. I have made it 2 player so the players enter their name and where they want to place the ships and everything but i want to make it so 2 people can play each other over the internet. I have done a simple echo server in java but i am still confused if i have multiple classes and stuff how i make the server so in the places where now i would display to the screen i want to display to the 2 clients. Would i have the server end run the main battleship program and then just change the display methods to display the board and moves to the clients connected instead of to the screen? I am confused on how i could do that? Thanks for any input. If i have to post code i will but its like 8 classes basically in the board class I have a printBoard() method that prints the board out so that would have to print to the clients connected and i would have to print the prompts and wait for the response from the clients on where to place ships and where to try and hit the opponents ship.
|
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 327
Rep Power: 4
![]() |
Re: online game
ok so i looked at the echo server example and i think here is what i want. I want it to be that all the server does is prompt the user for their name, where to place the ships and then when its their turn what row and column to try and attack the other persons ship. It will take that information into the appropiate methods and take the turn or place the ship so right now i have a method that reads from the command line so that would have to read from a Socket instead right? And then the server would send back that players board back to the appropiate client connected and then send to both players if they hit a ship or missed. I have all the logic correct i just seem to be stuck on sending and recieving from a socket to and from the server.
|
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 327
Rep Power: 4
![]() |
Re: online game
Ok the more I think about this the more i think that it is simpler then what i am trying to do. Basically if each client has a copy of the battleship program and each connects to the same server then couldn't the server just be used to relay the moves to the other client and that is what would be used as input into the program? So each battleship program would only have 1 player and 1 board and the moves that are made against that player and board come across the server from the second client right?
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Dec 2006
Posts: 50
Rep Power: 2
![]() |
Re: online game
Yeah, the client and server revision is much simpler and easier. It sounds like a great plan, but I don't understand the last part, "board come across the server from the second client right?" If the only data being transmitted is each player's moves, then there is no need to transmit the board because each client will interpret the received move accordingly. Like you said, the received data would be the other player's move and the each client would distinguish a win or loss.
|
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 327
Rep Power: 4
![]() |
Re: online game
Sorry, that wording is a little confusing i mean the move would be sent to the server and that move would be done against the player's board. So each client would just get 1 player and 1 board and the move against those boards would be taken from the server. But does that sound like a good plan? I've never done anything like this over the internet before so i dont really know what the best design would be.
|
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 327
Rep Power: 4
![]() |
Re: online game
so to start i am just trying to make 2 clients and a server. The clients will connect to the server and pass a message from one client to the other and it is not working right. The message never gets sent and the server and both clients just hang. Do i need a different name for the different client Sockets? If so I don't know how i would do this because both people playing will be running exact copies of the same program and connect to the server and then the server passes messages between them.
Here is the server code i have java Syntax (Toggle Plain Text)
java Syntax (Toggle Plain Text)
I want the one client to send the String line to the server and then the server to pass it to the second client. This is like how the battleship game will work one player sends the row and column he wants to hit and the server sends that information to the other client. |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 327
Rep Power: 4
![]() |
Re: online game
Alright I have an echo server that can connect to clients and echo back what they enter. Now I am stuck on how do i get the input from one client and send it to another client rather than back to the client it came from. I have 3 classes and i will post them. If someone could let me know what i need to do to make it so instead of the server echoing the information it passes the information to a second client.
Sever, main method java Syntax (Toggle Plain Text)
ServerThread - created for each new client that connects java Syntax (Toggle Plain Text)
the Client class java Syntax (Toggle Plain Text)
|
|
|
|
|
|
#8 |
|
Programmer
Join Date: Nov 2007
Posts: 86
Rep Power: 1
![]() |
Re: online game
I want to help you out. I wrote a program in college which might get you started. I need to go through all the source and make sure that none of it is copyrighted. If it is all written by me (none provided by my professor) then I will send it to you. It is too late to go through it tonight. It seems like you are on the right track so far though.
|
|
|
|
|
|
#9 |
|
Programmer
Join Date: Dec 2006
Posts: 50
Rep Power: 2
![]() |
Re: online game
I would use Socket and ServerSocket for the server class. In the first group of code, your
java Syntax (Toggle Plain Text)
java Syntax (Toggle Plain Text)
java Syntax (Toggle Plain Text)
java Syntax (Toggle Plain Text)
java Syntax (Toggle Plain Text)
|
|
|
|
|
|
#10 |
|
Hobbyist Programmer
|
Re: online game
hmm, im not sure about this as i am only just beginning Java so im not sure how it would handle something like what im about to suggest.
When a new client connects to the server a connection is established and sotred. Then it is passed to a new Thread and all data from that client is handled by that thread. Now if you store that connection in a global array, if this is possible in Java. Then it becomes avaliable to everything. This means that other threads that are running for other clients can access the connection via the global array and send data to it. Cheers, Chris
__________________
Who said i couldn't program sarcasm = raw_input('Type in a sarcastic remark: ')
|
|
|
|
![]() |
| 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 |
| Programmers wanted for an online text based game | esimagin | Paid Job Offers | 1 | May 18th, 2006 5:13 PM |
| Conflict Online (Browser Game) | JavaMan | Existing Project Development | 7 | Apr 28th, 2006 12:02 PM |
| Java programmers, game developers, artists, be ware! RPG game team is recruiting! | atcomputers.us | Paid Job Offers | 7 | Sep 25th, 2005 7:25 PM |
| Programmers Wanted: Online FPS game | troy_eisert | C++ | 0 | Feb 2nd, 2005 10:59 PM |
| Programmers Needed! Online Game | troy_eisert | C++ | 2 | Jan 29th, 2005 12:51 PM |