One Card! - Multiplayer Card Game
import Felgo 3.0
import QtQuick 2.0
import "scenes"
import "common"
import Qt.labs.settings 1.0
GameWindow {
id: window
height: 640
width: 960
title: gameNetwork.user.deviceId + " - " + gameNetwork.user.name
readonly property string gameTitle: "One Card!"
property MenuScene menuScene: sceneLoader.item && sceneLoader.item.menuScene
property InstructionScene instructionScene: sceneLoader.item && sceneLoader.item.instructionScene
property CardScene cardScene: sceneLoader.item && sceneLoader.item.cardScene
property GameScene gameScene: sceneLoader.item && sceneLoader.item.gameScene
property MultiplayerScene matchmakingScene: sceneLoader.item && sceneLoader.item.matchmakingScene
property GameNetworkScene gameNetworkScene: sceneLoader.item && sceneLoader.item.gameNetworkScene
property StoreScene storeScene: sceneLoader.item && sceneLoader.item.storeScene
property alias loadingScene: loadingScene
property alias facebook: facebookLoader.item
readonly property bool enableStoreAndAds: Constants.enableStoreAndAds
readonly property bool showAdvertisements: gameTokens < gameTokenNoAdsLimit && enableStoreAndAds
readonly property int gamesPlayed: menuScene ? menuScene.localStorage.gamesPlayed : 0
readonly property int appStarts: menuScene ? menuScene.localStorage.appStarts : 0
readonly property int gameTokens : storeScene ? storeScene.tokens : 0
readonly property int gameTokenEarnedPerVideoWatch: 1
readonly property int gameTokensEarnedPerDay: 1
readonly property int gameTokenNoAdsLimit: 10
EntityManager {
id: entityManager
entityContainer: gameScene
}
FontLoader {
id: standardFont
source: "../assets/fonts/agoestoesan.ttf"
}
Settings {
id: multiSettings
property alias counterAppInstances: gameNetwork.counterAppInstances
Component.onCompleted: {
console.log("multiSettings loaded with counterAppInstances value:" + counterAppInstances+ ", userName: " + gameNetwork.user.name)
multiSettings.counterAppInstances++
}
}
Component.onDestruction: {
multiSettings.counterAppInstances--
console.debug("decreasing counterAppInstances by -1 to:", multiSettings.counterAppInstances)
}
FelgoGameNetwork {
id: gameNetwork
clearAllUserDataAtStartup: system.desktopPlatform && enableMultiUserSimulation
clearOfflineSendingQueueAtStartup: true
gameId: Constants.gameId
secret: Constants.gameSecret
user.deviceId: generateDeviceId()
facebookItem: facebook
property int counterAppInstances: 0
property bool enableMultiUserSimulation: true
function generateDeviceId() {
if(system.isPlatform(System.IOS) || system.isPlatform(System.Android) || system.isPlatform(System.WindowsPhone)) {
console.debug("xxx-setting deviceId to", system.UDID)
return system.UDID
}
if(counterAppInstances > 1 && enableMultiUserSimulation) {
return system.UDID + "_" + (counterAppInstances) % multiplayer.playerCount
} else {
return system.UDID
}
}
gameNetworkView: gameNetworkScene && gameNetworkScene.gnView
}
FelgoMultiplayer {
id: multiplayer
playerCount: 4
startGameWhenReady: true
gameNetworkItem: gameNetwork
multiplayerView: matchmakingScene && matchmakingScene.mpView
maxJoinTries: 5
fewRoomsThreshold: 3
joinRankingIncrease: 200
enableLateJoin: true
appVersion: "1.5.0"
latencySimulationTime: system.desktopPlatform && !system.publishBuild ? 2000 : 0
appKey: Constants.appKey
pushKey: Constants.pushKey
onGameStarted: {
console.debug("yyy-gameStarted")
if(menuScene) {
menuScene.localStorage.setGamesPlayed(gamesPlayed + 1)
if(!gameRestarted && enableStoreAndAds)
storeScene.takeTokens(1)
}
window.state = "game"
}
}
Loader {
id: facebookLoader
active: Constants.fbAppId !== "<your-app-id>"
sourceComponent: Component {
Facebook {
appId: Constants.fbAppId
readPermissions: [ "email", "user_friends" ]
publishPermissions: ["publish_actions"]
}
}
}
GoogleAnalytics {
id: ga
}
Flurry {
id: flurry
}
state: "loading"
activeScene: loadingScene
LoadingScene {
id: loadingScene
}
Loader {
id: sceneLoader
onLoaded: window.state = "menu"
Timer {
id: loadingTimer
interval: 500
onTriggered: sceneLoader.source = Qt.resolvedUrl("OneCardMainItem.qml")
}
}
Component.onCompleted: {
loadingTimer.start()
}
states: [
State {
name: "loading"
PropertyChanges {target: loadingScene; opacity: 1}
PropertyChanges {target: window; activeScene: loadingScene}
},
State {
name: "menu"
PropertyChanges {target: menuScene; opacity: 1}
PropertyChanges {target: window; activeScene: menuScene}
StateChangeScript {
script: { menuScene.enterScene() }
}
},
State {
name: "instructions"
PropertyChanges {target: instructionScene; opacity: 1}
PropertyChanges {target: window; activeScene: instructionScene}
},
State {
name: "cards"
PropertyChanges {target: cardScene; opacity: 1}
PropertyChanges {target: window; activeScene: cardScene}
},
State {
name: "game"
PropertyChanges {target: gameScene; opacity: 1}
PropertyChanges {target: window; activeScene: gameScene}
},
State {
name: "multiplayer"
PropertyChanges {target: matchmakingScene; opacity: 1}
PropertyChanges {target: window; activeScene: matchmakingScene}
},
State {
name: "gn"
PropertyChanges {target: gameNetworkScene; opacity: 1}
PropertyChanges {target: window; activeScene: gameNetworkScene}
},
State {
name: "store"
PropertyChanges {target: storeScene; opacity: 1 }
PropertyChanges {target: window; activeScene: storeScene}
StateChangeScript {
script: { storeScene.enterScene() }
}