Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiplayer

 
Praveen Banthia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a game of yahtzee and I am nearly done with single player
However I want a simple multiplayer where the user logs in and if there are two users they play with each other.
Requirments are very flexible like user may choose to start a game or he may directly start playing as soon as he logs in.

I need help on how multiplayer can be done . creating game ID , assigning player to game recording scores and deciding winner.

Also one feature I need to add if any one player leaves in midlle the other wins how do I implement that to my game .

I know its a lot but I need to get this done asap
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Praveen,

Why don't you let us know how you are planning to do it first. After all it's your game, isn't it.

cheers :-)
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to set expectations properly: While you didn't say what "ASAP" means for you, given that quite a bit seems to be missing, I think it's unlikely that you'll be able to finish this within the next week or so.

Does your web app have a mechanism (maybe based on servlet sessions) to distinguish between several clients that log on to the server? Does it allow to choose which client to play against? What, exactly, do you have so far, and where, exactly, are you stuck making progress?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Just to set expectations properly: While you didn't say what "ASAP" means for you, given that quite a bit seems to be missing, I think it's unlikely that you'll be able to finish this within the next week or so.

Does your web app have a mechanism (maybe based on servlet sessions) to distinguish between several clients that log on to the server? Does it allow to choose which client to play against? What, exactly, do you have so far, and where, exactly, are you stuck making progress?


The world has got itself in one big darn hurry Ulf.
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Praveen, Your problem is very interesting, I was thinking in it for a while, You could solve your problem in this way, First you must have a security constraint in my application no matter the authentication method could be basic or with a form page, when the user logged in you create a session [request.getSession()]. Second you put a session listener (a class that implement the HttpSessionListener and it must be configured in the xml or with the @WebListener) with this listener you can be notified when a new session is created (when the user logged in) or when a session is destroyed (could be when the user logged out and you call the invalidate method from the session). With that you have a list of players and you can join two players in one game, The problem is when one player must wait for the other player, how the single player will be notified, you could use a push mechanism or a javascript function that submit every minute (you must choose this value) to check if there is a partner to play the match or simply put a button for the player to check if there is available a player.

I hope this help you.
Kind regards
Cesar
 
Praveen Banthia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all sorry for being so ambiguous . My method is simple I have created a register/login page which is secure and now player gets displayed a welcome page. The page should show all users names their wins and losses . Then I must create a mechanism where two people if logged in can start a game. I remind you game can be flexible so Cesar method of player checking or refresh will work. I need to create a game room or lobby or something where the two players play their game . Lobby is also flexible It needs to show opponents name and his score and once ends compare their scores calculate win or loss and redirect them to welcome page(The place where we display high score). I like Cesar approach but can you explain in detail and also how do I create a game room, use it and then delete it.

Also If a player is loosing he may not log out and simply quit so I need to check if the session gets invalidated after certain time then the other player is redirected to welcome page with win in his profile.

Once again Cesar some example will be great as my contribution to game starts from the part where user is on welcome page.

By the way my dice game is created securely so now the player cannot cheat thanks to your view on my previous posts

Thanks again
 
Praveen Banthia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
Thanks your replies were what helped me complete my single user game. I can now proudly say that no1 can mess with my small game and crash my server.
But moving on now I need to create a game lobby he are my thoughts (thoughts I have implemented nothing the game was done yesterday night at 5 am and I wont start for few hours for now)

User Logs in has a buton called check players.(This is flexible and time is a constraint so this shall work)
When user logs in I need and presses check players the server needs to check something and two of such exists (things is where I need help on) then
redirect both of them to the game pages(The beauty is my game does not need to wait for other player to finish he just needs to know his opponents score and name , it one player game implementing as two player and the requirements were flexible so I made it as simple as I could)

One thing I need to check if two players are in a game then must now be in condition of check player when player number 3 logs in (In short player 3 ends up playing with player 4 not player 1 or 2 as he is also logged in but are playing each other)

Now Something must be used to create a table in database where two player names are stored their total score is stored and checked at end of game or if any user leaves game in midddle declare the other user ass winner redirect him to welcome page with updated database table showing win+1 to one user and lose+1 to other user.

and delete the game table one it is done else theoritically I might run out of space.

any example code will be great.(and deadline is next Sunday so sooner I get the ideas oe example the quicker I can implement it)

You neeed my code to better understand just ask me I will mail it to you

Once again Thanks
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Banthia wrote:One thing I need to check if two players are in a game then must now be in condition of check player when player number 3 logs in (In short player 3 ends up playing with player 4 not player 1 or 2 as he is also logged in but are playing each other)

If the number of logged in players who are already playing is not very large, I would store it in the application scope rather than a database.
When players leave the game or the game is over, update the list, done.

Praveen Banthia wrote:You neeed my code to better understand just ask me I will mail it to you

Please UseTheForumNotEmail.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic