Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion demos/TicTacToe/Classes/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const float kFrameHeight = 600;
AppDelegate::AppDelegate() {}

AppDelegate::~AppDelegate() {}

bool AppDelegate::applicationDidFinishLaunching() {
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
Expand Down
22 changes: 12 additions & 10 deletions demos/TicTacToe/Classes/TicTacToeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include "firebase/app.h"
#include "firebase/auth.h"
#include "firebase/database.h"

using firebase::database::DataSnapshot;
using firebase::database::MutableData;
using firebase::database::TransactionResult;
#include "firebase/future.h"
#include "firebase/util.h"

Expand All @@ -23,9 +19,13 @@ using firebase::database::TransactionResult;
#include <set>
#include <sstream>
#include <string>
using std::string;
#include <unordered_set>

using firebase::database::DataSnapshot;
using firebase::database::MutableData;
using firebase::database::TransactionResult;
using std::string;

USING_NS_CC;

// Player constants.
Expand Down Expand Up @@ -298,7 +298,7 @@ TicTacToeLayer::TicTacToeLayer(string game_uuid) {
// Sign in using Auth before accessing the database.
// The default Database permissions allow anonymous users access. This will
// work as long as your project's Authentication permissions allow anonymous
// signin.
// sign-in.
{
firebase::Future<firebase::auth::User*> sign_in_future =
auth->SignInAnonymously();
Expand Down Expand Up @@ -334,12 +334,14 @@ TicTacToeLayer::TicTacToeLayer(string game_uuid) {
ref = database->GetReference("game_data").Child(join_game_uuid);
auto fIncrementTotalUsers = ref.RunTransaction([](MutableData* data) {
auto total_players = data->Child("total_players").value();
if (total_players.type() == NULL) {
return TransactionResult::kTransactionResultSuccess;
// Completing the transaction based on the returned mutable data value.
if (total_players.is_null()) {
// Must return this if the transaction was unsuccessful.
return TransactionResult::kTransactionResultAbort;
}
int new_total_players = total_players.int64_value() + 1;
if (new_total_players > kNumberOfPlayers) {
// Callback function needs to replace Scenes
// Must return this if the transaction was unsuccessful.
return TransactionResult::kTransactionResultAbort;
}
data->Child("total_players").set_value(new_total_players);
Expand Down Expand Up @@ -514,7 +516,7 @@ void TicTacToeLayer::update(float /*delta*/) {
}

TicTacToeLayer::~TicTacToeLayer() {
// release our sprite and layer so that it gets dealloced
// release our sprite and layer so that it gets deallocated
CC_SAFE_RELEASE_NULL(this->board_sprite);
CC_SAFE_RELEASE_NULL(this->game_over_label);
CC_SAFE_RELEASE_NULL(this->waiting_label);
Expand Down
2 changes: 1 addition & 1 deletion demos/TicTacToe/Classes/TicTacToeLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TicTacToeLayer : public Layer {
std::string join_game_uuid;
firebase::database::DatabaseReference ref;
// Creating listeners for database values.
// The databse schema has a top level game_uuid object which includes
// The database schema has a top level game_uuid object which includes
// last_move, total_players and current_player_index fields.
std::unique_ptr<SampleValueListener> current_player_index_listener;
std::unique_ptr<SampleValueListener> last_move_listener;
Expand Down
4 changes: 2 additions & 2 deletions demos/TicTacToe/Classes/TicTacToeScene.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "TicTacToeScene.h"

// now include our TicTacToeLayer class
#include "MainMenuScene.h"
#include "TicTacToeLayer.h"
#include "cocos2d.h"
using cocos2d::Scene;

Scene* TicTacToe::createScene(std::string game_uuid) {
Scene* TicTacToe::createScene(const std::string& game_uuid) {
// Sets the join_game_uuid to the passed in game_uuid.
// Builds a simple scene that uses the bottom left cordinate point as (0,0)
// and can have sprites, labels and layers added onto it.
Scene* scene = Scene::create();

// Builds a layer to be placed onto the scene which has access to TouchEvents.
// This TicTacToe layer being created is owned by scene.
auto tic_tac_toe_layer = new TicTacToeLayer(game_uuid);
scene->addChild(tic_tac_toe_layer);

Expand Down
2 changes: 1 addition & 1 deletion demos/TicTacToe/Classes/TicTacToeScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TicTacToe : public cocos2d::Layer {
public:
// Builds a simple scene that uses the bottom left cordinate point as (0,0)
// and can have sprites, labels and nodes added onto it.
static cocos2d::Scene* createScene(std::string );
static cocos2d::Scene* createScene(const std::string&);
// Defines a create type for a specific type, in this case a Layer.
CREATE_FUNC(TicTacToe);
};
Expand Down