How to add multiplayer in Android? - java

I'm making a Tic Tac Toe game in Android with three options:One player, two players and multiplayer.
The first two options were easy to make but I'm having A LOT of troubles with the last one, I have no idea what to do.
I am a beginner java programmer and I've never worked on networking with java, I know some basic things like MySQL and web stuff but I dont think it has anything to do with android.
So my questions are:
Do I have to use a server for this type of game? how and where do I find servers for this?
What do I need to learn in order to have the knowledge for developing multiplayer games?
Is it possible to make players play with other random available players? just hit play and be ready to go.
Can you recommend me some good guides that could help me?
Thank you very much !

Try Firebase
Firebase can act as a server where the users are connected
Firebase provides Realtime Database which would help your app. for eg
when a player makes a move, the changes would be effected to all the other player devices in Realtime by Firebase itself, you won't have to write the code to keep them in Sync

I recommend you take a look at Google Play Games Services.
It comes with a tone of features, and, most important for you, it has a Turn Based Multiplayer option that you could maybe use in your Tic Tac Toe.

Related

Display activity on 2 android devices simultaneously over a network

I have to create a simple single and multiplayer game in android about tilting the phone and recording the quickest time in a certain direction. I have successfully managed to create the single player version in Java. However I have no clue where to start with the multiplayer option where the game starts simultaneously on both devices where one is a server and the other the client (decided beforehand by the 2 people). I did take a look at the Android p2p website, but it wasn't much help. I have used Android Studio for the project.
I have all the math and logic ready from the single player, I am only struggling to how I can start the multiplayer by displaying an activity on 2 separate devices simultaneously. Unfortunately I don't have code to show for multiplayer as I have no idea where to begin.
Any help or advice will be highly appreciated.

How can I implement google play achievements and sign in on my game?

I found this tutorial for implementing the sign in and also the google play achievements.
The problem is that it shows me that I have to extend the BaseGameActivity class,but I'm already extending AndroidApplication.Oh and I am using LibGdx if it matters.
For the achievement, you can use com.google.android.gms.games.achievement.
If you haven't done with it, you can follow the instructions for installing and setting up your app to a Google Play games services. Define the achievements that you want your game to unlock or display. Achievements can be a great way to increase your users' engagement within your game. You can implement achievements in your game to encourage players to experiment with features they might not normally use, or to approach your game with entirely different play styles.
To create an achievement, just go to Google Play Developer Console. Select the Achievements tab and click the Add Achievement. Then, simply fill out the information required for this achievement. Click Save, and your achievement will be made available in "Ready to publish" mode. Once you publish your game, all of your game's achievements will be published with it.
your game needs to implement user sign-in to authenticate your player's identity with the Google Play games services. If the user is not authenticated, your game will encounter errors when making calls to the Google Play games services APIs.
In order to sign players in, you will need to properly instantiate GoogleApiClient in your Activity by following the instructions in Accessing the Games APIs.
Check this documentation, this documentation describes some sign-in implementation techniques that your game can use to provide a seamless user experience.
That tutorial is out of date and I suggest you do not use it.
It is no longer necessary to extend BaseGameActivity. See
Android Game Leader Board: Where to extends BaseGameActivity?
and https://www.youtube.com/watch?v=1oSoaFLuTwM for further information.
The google documentation and samples are up to date, very clearly written and accurate and I recommend you start here:
https://developers.google.com/games/services/

Google Play Game Services leaderboard -- what does it look like?

Has anyone tried out the Google Play Game Services leaderboard? I currently use SwarmConnect for my leaderboard but am not 100% satisfied with their UI and functionaility.
I have been searching since the Google I/O and have not been able to find an example. Can someone provide a pic, video or link to what a finished leaderboard looks like? I would love to see how it compares to SwarmConnect.
If this is not the place to post this, please advise on which Q/A website it should be placed on.
I implemented the Google Play Games on my Minesweeper 3D game, these are the leaderboard and achievements screenshots:
I removed people's name and face to keep their privacy! In my opinion it is better and easier to use than Scoreloop and Openfeint (I already tested both).

Java Tic Tac Toe architecture

I'm currently having a major brain fart :).
My plan was to build a simple swing based tic tac toe application in Java. I had planned for the app to allow for one player, two player local and two player remote options. I've got the one and two player local versions working fine but am struggling to get my head around the two player remote option.
Worth noting in the Netbeans project I have the gui in a separate package from the logic.
I've fried my brain thinking about all the options.
Like having a client server architecture but then if the client is running on a different pc than the logic this slows down the one player and two player local versions for no reason.
I'm thinking the entire application (gui + logic) should be distributed amongst the various pc's on the home wirless network. That way players can play one and two player local games without any unneccesary lag time and see if anyone else is available for a two player remote version. The question if I go this way is who's logic acts as the server - how does that work?
Is option 2 the best / only way of going about this because this isn't just a networked game?
Are there any other ways of going about this?
I know doing a tic tac toe game with just a remote game option would be a simple case of a client server architecture but having one player and then a networked version in the same app is tricky.
Thanks,
Paul.
Technically, you could do this without actual server -- you can make it like client/host.
When user wants to be host, he sends UDP broadcast packet, with information on what ip, and what game he wants to play. everyone who wants to join can catch this packet.
When user wants to join, he listens to broadcast packet, and joins to the one he recieved.
Every player could do his own logic, and send his move to other player -- other side should only check is the move legal -- because maybe someone wants to hack your game :D
The application should be installed on each client. For the remote 2-player mode, you should implement your own P2P protocol to send actions from one player to the other and to keep track of the evolution of the game.
In a few words, each client should have its own model of the game locally which it updates whenever either the local player makes "a move" or the remote user sends (through the protocol) "a move".
Of course, if you need to keep track of statistics like scores, points, etc, you will need a central server to store this. But the actual game should take place in a P2P mode, with no need for a server.

Java multiplayer card game AI integration

I have developed a Multi-player Client/Server Variation of Trumps Card Game using QuickServer library. It works well with 4 human players. But when I finished the AI player, I didn't find a way to integrate it into the server: Should I create a separate thread for each player?
I hope my question is clear. Any suggestions would be highly appreciated.
A server should just be a server. In this case, it updates the clients as to what happened and what happens next.
If it were me, I would have a AIClientPlayer, which gets passed a client, and acts using your fancy AI logic when the client signals it to act.

Categories