THeVIperTOoth
Posts: 1
Joined: Wed Apr 10, 2019 12:19 am

Creating a 2 Player Java game using the PI B+

Wed Apr 10, 2019 12:30 am

Hey folks so i plan on creating a project using the raspberry pi as a server for communication between the computers, the game is a simple dice roll where if playerX gets 2 of the same numbers they win or if playerY gets it first they win, this is the easiest part the only difficulty I'm having is figuring out a way to designate computerA and computerB as the players along with actually setting up a server to run the java code. Sorry if this is a newbie kinda of thing just started heavily using the PI for coding . If anyone has any good recommendations for tutorials or any advice that would be great. Again i just need help with setting the servers up not the actual game itself. Thanks folks.

ejolson
Posts: 3039
Joined: Tue Mar 18, 2014 11:47 am

Re: Creating a 2 Player Java game using the PI B+

Thu Apr 11, 2019 2:10 am

THeVIperTOoth wrote:
Wed Apr 10, 2019 12:30 am
Hey folks so i plan on creating a project using the raspberry pi as a server for communication between the computers, the game is a simple dice roll where if playerX gets 2 of the same numbers they win or if playerY gets it first they win, this is the easiest part the only difficulty I'm having is figuring out a way to designate computerA and computerB as the players along with actually setting up a server to run the java code. Sorry if this is a newbie kinda of thing just started heavily using the PI for coding . If anyone has any good recommendations for tutorials or any advice that would be great. Again i just need help with setting the servers up not the actual game itself. Thanks folks.
The networking part of creating a multiplayer networked game is somewhat difficult.

Instead of Java have you considered using one of the existing programmable multiplayer network game engines such as Dworkin's Game Driver? DGD implements an object-oriented C-like programming language that is well suited for a multiplayer game such as you have described.

knute
Posts: 423
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Creating a 2 Player Java game using the PI B+

Fri Apr 12, 2019 3:07 am

That sounds like a fun project. Before you actually code it, you should decide exactly how the game and the players are going to interact. Then you can decide on what messages you need to pass between the clients and the server.

So big picture I can see the first player logs into the server and he becomes the home team. The next player logs in and he is the visitor. The visitor gets to roll first and the server then sends both clients the results of the roll. If the visitor doesn't win on the first roll the home team gets to roll and so on. When somebody wins they get to decide to play again or just disconnect them and let them log in again.

So for client to server messages you need login, roll and disconnect. For the server to client you need opposing team information, roll results and winner notifications.

Java is fairly easy to use to write client/server code. If you want some help with this just ask.

Return to “Networking and servers”