GithubHelp home page GithubHelp logo

andreyul / android-samples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from playgameservices/android-basic-samples

0.0 2.0 0.0 2.33 MB

Google Play game services - Android samples

Groovy 2.58% Java 97.42%

android-samples's Introduction

Google Play game services - Android Samples

Copyright (C) 2014 Google Inc.

Contents

These are the Android samples for Google Play game services.

  • BasicSamples - a set of basic samples, including a convenience library (BaseGameUtils):

    • BaseGameUtils. Utilities used on all samples, which you can use in your projects too. This is not a stand-alone sample, it's a library project.

    • ButtonClicker2000. Represents the new generation in modern button-clicking excitement. A simple multiplayer game sample that shows how to set up the Google Play real-time multiplayer API, invite friends, automatch, accept invitations, use the waiting room UI, send and receive messages and other multiplayer topics.

    • CollectAllTheStars2. Demonstrates how to use the Snapshots feature to save game data. The sample signs the user in, synchronizes their data from a named Snapshot, then updates the UI to reflect the game state saved in the Snapshot.

    • TrivialQuest2. Demonstrates how to use the Events and Quests features of Google Play Services. The sample presents a sign in button and four buttons to simulate killing monsters in-game. When you click the buttons, an event is created and sent to Google Play Games to track what the player is doing in game.

    • TrivialQuest. The simplest possible single-player game. Shows how to sign in and how to unlock one achievement. Sign-in and click the button to win the game. Are you ready for this epic adventure?

    • TypeANumber. Shows leaderboards and achievements. In this exciting game, you type the score you think you deserve. But wait! There is a twist. If you are playing in easy mode, you get the score you requested. However, if you are playing in hard mode, you only get half! (tough game, we know).

    • SkeletonTbmp A trivial turn-based-multiplayer game. In this thrilling game, you can invite many friends, then send a shared gamestate string back and forth until someone finishes, cancels, or the second-to-last player leaves.

    • BeGenerous Send gifts and game requests to other players of BeGenerous.

Note: the samples that have corresponding counterparts for iOS and web (particularly, CollectAllTheStars and TypeANumber) are compatible across the platforms. This means that you can play some levels on CollectAllTheStars on your Android device, and then pick up your iOS device and continue where you left off! For TypeANumber, you will see your achievements and leaderboards on all platforms, and progress obtained on one will be reflected on the others.

Frequently Asked Questions

If you have questions about the samples (particularly, about BaseGameActivity and GameHelper), please take a look at our FAQ.

How to run a sample

  1. Set up the project in Developer Console. For more info:

    https://developers.google.com/games/services/console/enabling

    Note your package name and the APP ID of the project.

  2. Create leaderboards/achievements as appropriate for the sample (see the ones that the sample needs in its res/values/ids.xml)

Pick a set of instructions below depending on whether you're using Eclipse or Android Studio.

If you're using Eclipse...

  1. Start Eclipse
  2. Import the Google Play Services library project (available for download through the SDK manager):
    1. Click File | Import | Android | Existing Android Code into Workspace
    2. Select SDK/extras/google/google_play_services/google_play_services_lib (where SDK stands for the path where you installed your Android SDK)
    3. Click Finish
  3. Import eclipse_compat/libraries/BaseGameUtils as a library
    1. Click File | Import | Android | Existing Android Code into Workspace
    2. Select the eclipse_compat/libraries/BaseGameUtils project
    3. Click Finish
    4. Right-click on BaseGameUtils, then click Properties
    5. In the project properties window, click the Android section
    6. Check the Is Library checkbox
    7. Add a reference to the google_play_services_lib project (click Remove to remove any broken references, then click Add to add the correct one)
  4. Import the desired sample from the eclipse_compat directory (Project | Import | Android | Existing Android Source)
  5. Go into the project properties window for that project (right-click, Properties) and check that this project has a reference to the BaseGameUtils project.

Your project should now compile. However, don't run it yet, since you still need to adjust your game's IDs in order for the sample(s) to work.

Now jump to the Modify IDs, compile and run section and continue to follow the instructions there.

If you're using Android Studio...

  1. Open Android Studio and launch the Android SDK manager from it (Tools | Android | SDK Manager)
  2. Check that these two components are installed and updated to the latest version. Install or upgrade them if necessary.
    1. Google Play Services
    2. Google Repository
  3. Return to Android Studio and select Import Project
  4. Select the BasicSamples directory
  5. Select "Import from existing model - Gradle"

Modify IDs, compile and run

To set up a sample:

  1. Change the package name from com.google.example.games.* to your own package name (the same one you registered in Developer Console!). To do that, open AndroidManifest.xml and put your package name in the "package" attribute of the manifest tag. You will need to fix some of the references (particularly to the generated R class) because of the package name change. Ctrl+Shift+O in Eclipse (and Alt+Enter in Android Studio) should take care of most of the work.
  2. Modify res/values/ids.xml and place your IDs there, as given by the Developer Console (create the leaderboards and achievements necessary for the sample, if any). Remember that the App ID is only the numerical portion of your client ID, so use 123456789012 and not 123456789012.apps.gooogleusercontent.com.
  3. Compile and run.

IMPORTANT: make sure to sign your apk with the same certificate as the one whose fingerprint you configured on Developer Console, otherwise you will see errors.

IMPORTANT: if you are testing an unpublished game, make sure that the account you intend to sign in with (the account on the test device) is listed as a tester in the project on your Developer Console setup (check the list in the "Testing" section), otherwise the server will act as though your project did not exist and return errors.

If you're using another build system...

If you are using your own build system, here is a summary of what you must do:

  1. Configure it to treat google-play-services_lib and BaseGameUtils as library projects, which means that not only their code but also their resources will also get added to the final build.
  2. Make sure TrivialQuest depends on BaseGameUtils
  3. Make sure BaseGameUtils depends on google-play-services_lib.
  4. Make sure the build system is signing the APK with the right certificate (the one whose fingerprint you provided in the Developer Console when creating your client ID)

Building

To build the samples after you have applied the changes above, you can use the build/run option in Eclipse or Android Studio, or build directly from the command line if you prefer:
cd /path/to/BasicSamples
./gradlew build

Support

First of all, take a look at our troubleshooting guide. Most setup issues can be solved by following this guide.

If your question is not answered by the troubleshooting guide, we encourage you to post your question to stackoverflow.com. Our team answers questions there reguarly.

Samples written by Bruno Oliveira with contributions from Wolff. Feel free to add us to your circles on Google Plus and pester us to fix stuff that's broken or answer a question on stackoverflow :-)

Samples written by Bruno Oliveira. Feel free to add me to your circles on Google Plus and pester me to fix anything that's broken or answer a question on stackoverflow!

Special Thanks

  • To ligi for contributing the initial Gradle build files
  • To grantkemp for fixing the Eclipse compat build when we migrated to Gradle
  • To bechhansen for fixing a bug in GameHelper where the turn-based match was being lost when a non-Games client connected.

android-samples's People

Contributors

bechhansen avatar btco avatar geertjan-apptornado avatar gguuss avatar grantkemp avatar grantland avatar hak avatar jansoren avatar ligi avatar thedmail avatar wolffg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.