/android-friend-smash-v2

Built natively in Eclipse, using Java, Friend Smash for Android integrates the Facebook SDK for Android to provide easy login, increased engagement and improved organic distribution. Learn how to build Facebook into an Android app from the ground up.

Primary LanguageJavaOtherNOASSERTION

Friend Smash sample Facebook game

Authors:

  • Peter Chang (peter78)
  • Phil Hewinson (philhewinson)
  • Ali Parr (aliparr)
  • Jakub Pudelek (skoggkatt)

Overview

To help better understand different products and services available to game developers, Facebook maintains a sample game called Friend Smash!

The game is implemented on different platforms:

There are minor differences between the four implementations, but overall the goal and structure of all is similar. This is the Android version of the game.

What is “Friend Smash!”?

Friend Smash is a simple game which utilizes Facebook platform to enhance the gameplay by making it more fun and social. It uses variety of products and services, such as Facebook Login, Graph API, Game Requests and Sharing. The code examples serve as a guide of how they may be used in a games context. It also serves as an implementation guide - parts of source code relevant to Facebook integration are clearly separated from the pure gaming-logic and clearly documented with in code comments.

Please note that Friend Smash! was not designed as an example of how to design or code a game. The focus is on Facebook integration - other parts of the project may not be as clear and well designed and documented.

Friends Smash! is a game in which players are tasked with "smashing" (mouse-clicking or screen-tapping) pictures of a specific person while avoiding smashing pictures of anyone else. Player gets points for each correct picture smashed. Each miss or wrong smash causes the player to lose a heart. After losing 3 lives, the game is over. Player can also smash images of coins to collect them and later redeem these coins to buy bombs. In turn, bombs can be used in game to smash all correct pictures on the screen, helping to achieve a higher score. Additionally, the web version of the game allows players to purchase coins with Facebook Payments.

Facebook integration

To make the experience more fun and social, players are asked to log in with Facebook and grant user_friends permission. When granted, the game will have access to subset of player's friends data, specifically those who also logged in to Friend Smash! and granted user_friends permission. This means the game will use the profile picture of randomly selected friend as the picture the player is asked to smash. If user_friends permission hasn’t been granted or the player doesn't have friends who also logged in to Friend Smash! and granted user_friends permission, a picture of randomly selected celebrity is used instead.

At different points in the game player has an opportunity to share to Facebook. For example after the game is over, player can brag about the score achieved by posting a custom Open Graph story. The game also shows how to ask for publish_actions permission (which is required for API based sharing) and how to handle the case when publish_actions permission is not granted. If publish_actions permission is granted - the game uses Scores API to publish and store the top score achieved by the player.

Game Requests are used in the game for two main purposes. First to let the player invite their friends who are not playing the game to try it. Second, to send a challenge to a friend who is already playing to bring them back to the game. Additionally on the web version, the game uses Facebook Payments to allow players to purchase in-game currency and In-Game Gifting to allow purchasing gifts for players’ friends. The web example also includes reference implementation of a payments server handling static pricing and payments verification.

Friend Smash! also logs App Events, which enables Facebook Analytics for Apps - a free tool allowing developers to learn how people use their app across all platforms and devices, get insights about the people using the app, and improve marketing.

How to use “Friend Smash!”?

All versions of Friend Smash! are available as part of Facebook Platform Samples on github: Web, Android, iOS, Unity.

The recommended way to explore the projects is to begin with how Facebook products are integrated. To make it easier code responsible for Facebook integration is separated and well documented with in code comments for all versions. You can find it here for different versions: Web, Android, iOS, Unity. The reference implementation of a payments server is included in the Web repository.

To play Friend Smash! on Web, simply go to apps.facebook.com/friendsmashsample. To play it on mobile, download the Android, iOS or Unity project and build it from source and try on your device.

Please note it is likely that unless you have friends who also installed Friend Smash! you will not see any of your friends in the game. If this is the case, you can invite some of your friends to play Friend Smash! to fully explore how social integration works in Friend Smash!

Installing

Before running the sample, please see the Getting Started on Android guide

Additional Resources

Facebook SDK for Android documentation

Contributing

All contributors must agree to and sign the Facebook CLA prior to submitting Pull Requests. We cannot accept Pull Requests until this document is signed and submitted.