One Card! - Multiplayer Card Game
import QtQuick 2.12
import Felgo 3.0
Item {
id: gameLogic
property bool singlePlayer: false
property bool initialized: false
onInitializedChanged: console.debug("GameLogic.initialized changed to:", initialized)
property double remainingTime
property int userInterval: multiplayer.myTurn && !multiplayer.amLeader ? 7 : 10
property int aiTurnTime: 600
property int restartTime: 8000
property bool cardsDrawn: false
property bool acted: false
property bool gameOver: false
property int messageSyncGameState: 0
property int messageRequestGameState: 1
property int messageMoveCardsHand: 2
property int messageMoveCardsDepot: 3
property int messageSetEffect: 4
property int messageSetSkipped: 5
property int messageSetReverse: 6
property int messageSetDrawAmount: 7
property int messagePickColor: 8
property int messagePressONU: 9
property int messageEndGame: 10
property int messagePrintChat: 11
property int messageSetPlayerInfo: 12
property int messageTriggerTurn: 13
property int messageRequestPlayerTags: 14
property bool receivedMessageBeforeGameStateInSync: false
SoundEffect {
volume: 0.5
id: colorSound
source: "../../assets/snd/color.wav"
}
Timer {
id: timer
repeat: true
running: !gameOver
interval: 1000
onTriggered: {
remainingTime -= 1
if (remainingTime === 0) {
gameLogic.turnTimedOut()
}
if (multiplayer.myTurn){
markValid()
scaleHand()
}
for (var i = 0; i < playerTags.children.length; i++){
playerTags.children[i].canvas.requestPaint()
}
}
}
Timer {
id: aiTimeOut
interval: aiTurnTime
onTriggered: {
gameLogic.executeAIMove()
endTurn()
}
}
Timer {
id: restartGameTimer
interval: restartTime
onTriggered: {
restartGameTimer.stop()
startNewGame()
}
}
Connections {
target: multiplayer
enabled: activeScene === gameScene
onGameStarted: {
if(gameRestarted) {
flurry.logEvent("System.GameReStarted", "singlePlayer", multiplayer.singlePlayer)
flurry.logTimedEvent("Game.TimeInGameSingleMatch", {"singlePlayer": multiplayer.singlePlayer})
} else {
flurry.logEvent("System.GameStarted", "singlePlayer", multiplayer.singlePlayer)
flurry.logTimedEvent("Game.TimeInGameTotal", {"singlePlayer": multiplayer.singlePlayer})
}
}
onAmLeaderChanged: {
if (multiplayer.leaderPlayer){
console.debug("Current Leader is: " + multiplayer.leaderPlayer.userId)
}
if(multiplayer.amLeader) {
console.debug("this player just became the new leader")
if(!timer.running && !gameOver) {
console.debug("New leader selected, but the timer is currently not running, thus trigger a new turn now")
triggerNewTurn()
} else if (!timer.running){
restartGameTimer.start()
}
}
}
onMessageReceived: {
console.debug("onMessageReceived with code", code, "initialized:", initialized)
flurry.logEvent("System.MessageReceived", "singlePlayer", multiplayer.singlePlayer)
if(!initialized && code !== messageSyncGameState) {
console.debug("ERROR: received message before gameState was synced and user is not initialized:", code, message)
if (message.receiverPlayerId === multiplayer.localPlayer.userId && !compareGameStateWithLeader(message.playerHands)) {
receivedMessageBeforeGameStateInSync = true
}
return
}
if (code == messageSyncGameState) {
if (!message.receiverPlayerId || message.receiverPlayerId === multiplayer.localPlayer.userId || !compareGameStateWithLeader(message.playerHands)) {
console.debug("Sync Game State now")
console.debug("Received Message: " + JSON.stringify(message))
console.debug("multiplayer.activePlayer when syncing game state:", multiplayer.activePlayer)
syncPlayers()
initTags()
syncDeck(message.deck)
depot.syncDepot(message.depot, message.current, message.currentCardColor, message.skipped, message.clockwise, message.effect, message.drawAmount)
syncHands(message.playerHands)
gameOver = message.gameOver
gameScene.gameOver.visible = gameOver
timer.running = !gameOver
console.debug("finished syncGameState, setting initialized to true now")
initialized = true
if(receivedMessageBeforeGameStateInSync) {
console.debug("requesting a new game state from server now, as receivedMessageBeforeGameStateInSync was true")
multiplayer.sendMessage(messageRequestGameState, multiplayer.localPlayer.userId)
receivedMessageBeforeGameStateInSync = false
}
if (message.receiverPlayerId){
multiplayer.sendMessage(messageRequestPlayerTags, multiplayer.localPlayer.userId)
}
}
}
else if (code == messageRequestGameState){
multiplayer.leaderCode(function() {
sendGameStateToPlayer(message)
})
}
else if (code == messageMoveCardsHand){
if (multiplayer.activePlayer && multiplayer.activePlayer.userId != message.userId){
multiplayer.leaderCode(function() {
sendGameStateToPlayer(message.userId)
})
return
}
getCards(message.cards, message.userId)
}
else if (code == messageMoveCardsDepot){
if (multiplayer.activePlayer && multiplayer.activePlayer.userId != message.userId){
multiplayer.leaderCode(function() {
sendGameStateToPlayer(message.userId)
})
return
}
depositCard(message.cardId, message.userId)
}
else if (code == messageSetEffect){
if (multiplayer.leaderPlayer.userId != message.userId &&
multiplayer.activePlayer && multiplayer.activePlayer.userId != message.userId){
return
}
depot.effect = message.effect
}
else if (code == messageSetSkipped){
if (multiplayer.leaderPlayer.userId != message.userId &&
multiplayer.activePlayer && multiplayer.activePlayer.userId != message.userId){
return
}
depot.skipped = message.skipped
}
else if (code == messageSetReverse){
if (multiplayer.leaderPlayer.userId != message.userId &&
multiplayer.activePlayer && multiplayer.activePlayer.userId != message.userId){
return
}
depot.clockwise = message.clockwise
}
else if (code == messageSetDrawAmount){
if (multiplayer.leaderPlayer.userId != message.userId &&
multiplayer.activePlayer && multiplayer.activePlayer.userId != message.userId){
return
}
depot.drawAmount = message.amount
}
else if (code == messagePickColor){
if (multiplayer.leaderPlayer.userId != message.userId &&
multiplayer.activePlayer && multiplayer.activePlayer.userId != message.userId){
return
}
pickColor(message.color)
}
else if (code == messagePressONU){
var playerHand = getHand(message.userId)
if (playerHand) {
playerHand.onu = message.onu
}
}
else if (code == messageEndGame){
if (multiplayer.leaderPlayer.userId != message.userId &&
multiplayer.activePlayer && multiplayer.activePlayer.userId != message.userId && !message.test){
return
}
endGame(message.userId)
}
else if (code == messagePrintChat){
if (!chat.gConsole.visible){
chat.chatButton.buttonImage.source = "../../assets/img/Chat2.png"
}
chat.gConsole.printLn(message)
}
else if (code == messageSetPlayerInfo){
updateTag(message.userId, message.level, message.highscore, message.rank)
}
else if (code == messageTriggerTurn){
multiplayer.leaderCode(function() {
if (multiplayer.activePlayer && multiplayer.activePlayer.userId == message){
triggerNewTurn()
}
else {
sendGameStateToPlayer(message)
}
})
}
else if (code == messageRequestPlayerTags){
initTags()
}
}
}
Connections {
target: gameScene
onStackSelected: {
if (multiplayer.myTurn && !depot.skipped && !acted && !cardsDrawn) {
if (hasValidCards(multiplayer.localPlayer)){
acted = true
}
var userId = multiplayer.activePlayer ? multiplayer.activePlayer.userId : 0
getCards(depot.drawAmount, userId)
multiplayer.sendMessage(messageMoveCardsHand, {cards: depot.drawAmount, userId: userId})
if (acted || !hasValidCards(multiplayer.localPlayer)){
acted = true
endTurn()
} else {
depot.drawAmount = 1
depot.effect = false
multiplayer.sendMessage(gameLogic.messageSetDrawAmount, {amount: 1, userId: userId})
scaleHand(1.6)
markValid()
closeToWin()
}
flurry.logEvent("User.StackSelected", "singlePlayer", multiplayer.singlePlayer)
}
}
onCardSelected: {
if (colorPicker.chosingColor) return
if (entityManager.getEntityById(cardId).state === "stack"){
stackSelected()
} else if (entityManager.getEntityById(cardId).state === "player"){
if (multiplayer.myTurn && !depot.skipped && !acted) {
flurry.logEvent("User.CardSelected", "singlePlayer", multiplayer.singlePlayer)
if (depot.validCard(cardId)){
var currentType = entityManager.getEntityById(cardId).variationType
if (currentType !== "wild" && currentType !== "wild4") acted = true
depositCard(cardId, multiplayer.localPlayer.userId)
multiplayer.sendMessage(messageMoveCardsDepot, {cardId: cardId, userId: multiplayer.localPlayer.userId})
if (depot.current.variationType === "draw2") depot.draw(2)
if (depot.current.variationType === "wild4") depot.draw(4)
if (depot.current.cardColor !== "black" && multiplayer.myTurn){
endTurn()
}
}
}
}
}
onColorPicked: {
if (multiplayer.myTurn && !acted){
acted = true
colorSound.play()
pickColor(pickedColor)
multiplayer.sendMessage(messagePickColor, {color: pickedColor, userId: multiplayer.localPlayer.userId})
endTurn()
flurry.logEvent("User.ColorPicked", "singlePlayer", multiplayer.singlePlayer)
}
}
}
function syncDeck(cardInfo){
console.debug("syncDeck()")
deck.syncDeck(cardInfo)
depot.createDepot()
gameOver = false
timer.start()
scaleHand()
markValid()
gameScene.gameOver.visible = false
gameScene.leaveGame.visible = false
gameScene.switchName.visible = false
playerInfoPopup.visible = false
onuButton.button.enabled = false
chat.reset()
}
function depositCard(cardId, userId){
unmark()
scaleHand(1.0)
for (var i = 0; i < playerHands.children.length; i++) {
if (playerHands.children[i].inHand(cardId)){
playerHands.children[i].removeFromHand(cardId)
depot.depositCard(cardId)
if (depot.current.variationType === "reverse"){
multiplayer.leaderCode(function() {
depot.reverse()
})
}
if (depot.current.cardColor === "black"){
if (multiplayer.activePlayer && multiplayer.activePlayer.connected && remainingTime > 0){
if (multiplayer.myTurn){
colorPicker.visible = true
}
colorPicker.chosingColor = true
}else{
multiplayer.leaderCode(function() {
if (!multiplayer.activePlayer || !multiplayer.activePlayer.connected) {
var color = colorPicker.randomColor()
pickColor(color)
multiplayer.sendMessage(messagePickColor, {color: color, userId: userId})
}
})
}
}
if (!multiplayer.activePlayer || !multiplayer.activePlayer.connected){
depot.current.hidden = false
}
}
}
}
function executeAIMove() {
if(!depot.skipped){
playRandomValid()
}
}
function playRandomValid() {
for (var i = 0; i < playerHands.children.length; i++) {
if (playerHands.children[i].player === multiplayer.activePlayer && !cardsDrawn){
var validCardId = playerHands.children[i].randomValidId()
var userId = multiplayer.activePlayer ? multiplayer.activePlayer.userId : 0
if (validCardId){
multiplayer.sendMessage(messageMoveCardsDepot, {cardId: validCardId, userId: userId})
depositCard(validCardId, userId)
if (depot.current.variationType === "draw2") depot.draw(2)
if (depot.current.variationType === "wild4") depot.draw(4)
} else {
getCards(depot.drawAmount, userId)
multiplayer.sendMessage(messageMoveCardsHand, {cards: depot.drawAmount, userId: userId})
}
}
}
}
function hasValidCards(userId){
var playerHand = getHand(multiplayer.localPlayer.userId)
var valids = playerHand.getValidCards()
return valids.length > 0
}
function startTurnTimer() {
timer.stop()
remainingTime = userInterval
if (!gameOver) {
timer.start()
scaleHand()
markValid()
}
}
function turnStarted(playerId) {
console.debug("turnStarted() called")
if(!multiplayer.activePlayer) {
console.debug("ERROR: activePlayer not valid in turnStarted!")
return
}
console.debug("multiplayer.activePlayer.userId: " + multiplayer.activePlayer.userId)
console.debug("Turn started")
gameLogic.startTurnTimer()
acted = false
cardsDrawn = false
unmark()
scaleHand(1.0)
colorPicker.visible = false
colorPicker.chosingColor = false
depot.cardEffect()
if (!depot.skipped && multiplayer.myTurn) scaleHand(1.6)
closeToWin()
markValid()
for (var i = 0; i < playerTags.children.length; i++){
playerTags.children[i].canvas.requestPaint()
}
multiplayer.leaderCode(function() {
if (!multiplayer.activePlayer || !multiplayer.activePlayer.connected) {
aiTimeOut.start()
}
})
}
function turnTimedOut(){
if (multiplayer.myTurn && !acted){
acted = true
scaleHand(1.0)
}
timer.running = false
multiplayer.leaderCode(function () {
if (!colorPicker.chosingColor){
executeAIMove()
}
endTurn()
})
}
function createGame(){
multiplayer.createGame()
}
function leaveGame(){
aiTimeOut.stop()
restartGameTimer.stop()
timer.running = false
depot.effectTimer.stop()
deck.reset()
chat.gConsole.clear()
multiplayer.leaveGame()
scaleHand(1.0)
initialized = false
receivedMessageBeforeGameStateInSync = false
ga.logEvent("User", "Exit Game", "singlePlayer", multiplayer.singlePlayer)
flurry.logEvent("User.ExitGame", "singlePlayer", multiplayer.singlePlayer)
flurry.endTimedEvent("Game.TimeInGameTotal", {"singlePlayer": multiplayer.singlePlayer})
}
function joinGame(room){
multiplayer.joinGame(room)
}
function initGame(calledFromGameOverScreen){
ga.logEvent("System", "Start Game", "singlePlayer", multiplayer.singlePlayer)
flurry.logEvent("System.StartGame", "singlePlayer", multiplayer.singlePlayer)
if(calledFromGameOverScreen) {
ga.logEvent("User", "Restart Game", "singlePlayer", multiplayer.singlePlayer)
flurry.logEvent("User.RestartGame", "singlePlayer", multiplayer.singlePlayer)
} else {
ga.logEvent("User", "Start New Game", "singlePlayer", multiplayer.singlePlayer)
flurry.logEvent("User.StartNewGame", "singlePlayer", multiplayer.singlePlayer)
}
if(!multiplayer.initialized && !multiplayer.singlePlayer){
createGame()
}
console.debug("multiplayer.localPlayer " + multiplayer.localPlayer)
console.debug("multiplayer.players.length " + multiplayer.players.length)
for (var i = 0; i < multiplayer.players.length; i++){
console.debug("multiplayer.players[" + i +"].userId " + multiplayer.players[i].userId)
}
console.debug("multiplayer.myTurn " + multiplayer.myTurn)
gameOver = false
timer.start()
scaleHand()
markValid()
gameScene.gameOver.visible = false
gameScene.leaveGame.visible = false
gameScene.switchName.visible = false
playerInfoPopup.visible = false
onuButton.button.enabled = false
chat.reset()
depot.reset()
initPlayers()
initDeck()
initHands()
initTags()
multiplayer.leaderCode(function () {
initialized = true
if(calledFromGameOverScreen) {
multiplayer.restartGame()
}
if (!multiplayer.singlePlayer) {
sendGameStateToPlayer(undefined)
}
gameLogic.triggerNewTurn(multiplayer.leaderPlayer.userId)
})
scaleHand()
closeToWin()
ga.logEvent("User", "Restart Game", "singlePlayer", multiplayer.singlePlayer)
flurry.logEvent("User.RestartGame", "singlePlayer", multiplayer.singlePlayer)
console.debug("InitGame finished!")
}
function sendGameStateToPlayer(playerId) {
console.debug("sendGameStateToPlayer() with playerId", playerId)
var message = {}
var currentPlayerHands = []
for (var i = 0; i < playerHands.children.length; i++) {
var currentPlayerHand = {}
currentPlayerHand.userId = playerHands.children[i].player.userId
currentPlayerHand.handIds = []
for (var j = 0; j < playerHands.children[i].hand.length; j++){
currentPlayerHand.handIds[j] = playerHands.children[i].hand[j].entityId
}
currentPlayerHands.push(currentPlayerHand)
}
message.playerHands = currentPlayerHands
message.deck = deck.cardInfo
message.current = depot.current.entityId
message.currentCardColor = depot.current.cardColor
message.skipped = depot.skipped
message.clockwise = depot.clockwise
message.effect = depot.effect
message.drawAmount = depot.drawAmount
message.gameOver = gameOver
var depotIDs = []
for (var k = 0; k < deck.cardDeck.length; k++){
if (deck.cardDeck[k].state === "depot" && deck.cardDeck[k].entityId !== depot.current.entityId){
depotIDs.push(deck.cardDeck[k].entityId)
}
}
message.depot = depotIDs
message.receiverPlayerId = playerId
console.debug("Send Message: " + JSON.stringify(message))
multiplayer.sendMessage(messageSyncGameState, message)
}
function compareGameStateWithLeader(messageHands){
for (var i = 0; i < playerHands.children.length; i++){
var currentUserId = playerHands.children[i].player.userId
for (var j = 0; j < messageHands.length; j++){
var messageUserId = messageHands[j].userId
if (currentUserId == messageUserId){
if (playerHands.children[i].hand.length != messageHands[j].handIds.length){
console.debug("ERROR: game state differentiates from the one of the leader because of the different amount of cards - resync the game of this player!")
return false
}
}
}
}
return true
}
function initPlayers(){
multiplayer.leaderCode(function () {
console.debug("Leader Init Players")
var clientPlayers = multiplayer.players
var playerInfo = []
for (var i = 0; i < clientPlayers.length; i++) {
playerTags.children[i].player = clientPlayers[i]
playerHands.children[i].player = clientPlayers[i]
playerInfo[i] = clientPlayers[i].userId
}
})
}
function getPlayer(userId){
for (var i = 0; i < multiplayer.players.length; i++){
console.debug("All UserIDs: " + multiplayer.players[i].userId + ", Looking for: " + userId)
if (multiplayer.players[i].userId == userId){
return multiplayer.players[i]
}
}
console.debug("ERROR: could not find player with id", userId, "in the multiplayer.players list!")
return undefined
}
function getHand(userId){
for (var i = 0; i < playerHands.children.length; i++){
if (playerHands.children[i].player.userId == userId){
return playerHands.children[i]
}
}
console.debug("ERROR: could not find player with id", userId, "in the multiplayer.players list!")
return undefined
}
function updateTag(userId, level, highscore, rank){
for (var i = 0; i < playerTags.children.length; i++){
if (playerHands.children[i].player.userId == userId){
playerTags.children[i].level = level
playerTags.children[i].highscore = highscore
playerTags.children[i].rank = rank
}
}
}
function syncPlayers(){
console.debug("syncPlayers()")
for (var j = 0; j < multiplayer.players.length; j++) {
playerTags.children[j].player = multiplayer.players[j]
playerHands.children[j].player = multiplayer.players[j]
}
}
function initDeck(){
multiplayer.leaderCode(function () {
deck.createDeck()
depot.createDepot()
})
}
function initHands(){
multiplayer.leaderCode(function () {
for (var i = 0; i < playerHands.children.length; i++) {
playerHands.children[i].startHand()
}
})
}
function syncHands(messageHands){
console.debug("syncHands()")
for (var i = 0; i < playerHands.children.length; i++){
var currentUserId = playerHands.children[i].player.userId
for (var j = 0; j < messageHands.length; j++){
var messageUserId = messageHands[j].userId
if (currentUserId == messageUserId){
playerHands.children[i].syncHand(messageHands[j].handIds)
}
}
}
}
function initTags(){
console.debug("initTags()")
for (var i = 0; i < playerTags.children.length; i++){
playerTags.children[i].initTag()
if (playerHands.children[i].player && playerHands.children[i].player.userId == multiplayer.localPlayer.userId){
playerTags.children[i].getPlayerData(true)
}
}
}
function getCards(cards, userId){
cardsDrawn = true
for (var i = 0; i < playerHands.children.length; i++) {
if (playerHands.children[i].player.userId === userId){
playerHands.children[i].pickUpCards(cards)
}
}
}
function pickColor(pickedColor){
if ((depot.current.variationType === "wild4" || depot.current.variationType === "wild")
&& depot.current.cardColor === "black"){
depot.current.cardColor = pickedColor
depot.current.updateCardImage()
}
}
function closeToWin(){
for (var i = 0; i < playerHands.children.length; i++) {
if (playerHands.children[i].player === multiplayer.activePlayer){
playerHands.children[i].closeToWin()
}
}
}
function markValid(){
if (multiplayer.myTurn && !acted && !colorPicker.chosingColor){
for (var i = 0; i < playerHands.children.length; i++) {
if (playerHands.children[i].player === multiplayer.activePlayer){
playerHands.children[i].markValid()
}
}
} else {
unmark()
}
}
function unmark(){
for (var i = 0; i < playerHands.children.length; i++) {
playerHands.children[i].unmark()
}
deck.unmark()
}
function scaleHand(scale){
if (!scale) scale = multiplayer.myTurn && !acted && !depot.skipped && !colorPicker.chosingColor ? 1.6 : 1.0
for (var i = 0; i < playerHands.children.length; i++){
if (playerHands.children[i].player && playerHands.children[i].player.userId == multiplayer.localPlayer.userId){
playerHands.children[i].scaleHand(scale)
}
}
}
function endTurn(){
unmark()
scaleHand(1.0)
var userId = multiplayer.activePlayer ? multiplayer.activePlayer.userId : 0
for (var i = 0; i < playerHands.children.length; i++) {
if (playerHands.children[i].player === multiplayer.activePlayer){
if (playerHands.children[i].checkWin()){
endGame()
multiplayer.sendMessage(messageEndGame, {userId: userId})
}else if (playerHands.children[i].missedOnu()){
getCards(2, userId)
multiplayer.sendMessage(messageMoveCardsHand, {cards: 2, userId: userId})
if (multiplayer.myTurn) onuHint.visible = true
}
}
}
if (!gameOver){
console.debug("trigger new turn in endTurn, clockwise: " + depot.clockwise)
if (multiplayer.amLeader){
console.debug("Still Leader?")
triggerNewTurn()
} else {
multiplayer.sendMessage(messageTriggerTurn, userId)
}
}
}
function triggerNewTurn(userId){
if (depot.clockwise){
multiplayer.triggerNextTurn(userId)
} else {
multiplayer.triggerPreviousTurn(userId)
}
}
function calculatePoints(userId){
var score = 0
for (var i = 0; i < playerHands.children.length; i++) {
score += playerHands.children[i].points()
}
if (multiplayer.singlePlayer){
score = Math.round(score/3)
}
if (userId == undefined) {
var tmpPlayers = [playerHands.children[0], playerHands.children[1], playerHands.children[2], playerHands.children[3]]
var points = [score, 15, 10, 5]
tmpPlayers.sort(function(a, b) {
return a.hand.length - b.hand.length
})
var winnerHand = getHand(tmpPlayers[0].player.userId)
if (winnerHand) gameScene.gameOver.winner = winnerHand.player
for (var i = 0; i < tmpPlayers.length; i++){
var tmpPlayer = getHand(tmpPlayers[i].player.userId)
if (tmpPlayer) tmpPlayer.score = points[i]
if (i > 0){
var prevPlayer = getHand(tmpPlayers[i-1].player.userId)
if (prevPlayer && prevPlayer.hand.length == tmpPlayer.hand.length){
tmpPlayer.score = prevPlayer.score
}
}
}
} else {
var tmpPlayers2 = []
for (i = 0; i < playerHands.children.length; i++){
if (playerHands.children[i].player.userId != userId){
tmpPlayers2[tmpPlayers2.length] = playerHands.children[i]
}
}
var points2 = [15, 10, 5]
tmpPlayers2.sort(function(a, b) {
return a.hand.length - b.hand.length
})
var winnerHand2 = getHand(userId)
if (winnerHand2) gameScene.gameOver.winner = winnerHand2.player
var winner = getHand(userId)
if (winner) winner.score = score
for (var j = 0; j < tmpPlayers2.length; j++){
var tmpPlayer2 = getHand(tmpPlayers2[j].player.userId)
if (tmpPlayer2) tmpPlayer2.score = points2[j]
if (j > 0){
var prevPlayer2 = getHand(tmpPlayers2[j-1].player.userId)
if (prevPlayer2 && prevPlayer2.hand.length == tmpPlayer2.hand.length){
tmpPlayer2.score = prevPlayer2.score
}
}
}
}
}
function endGame(userId){
calculatePoints(userId)
gameScene.gameOver.visible = true
var currentHand = getHand(multiplayer.localPlayer.userId)
if (currentHand) gameNetwork.reportRelativeScore(currentHand.score)
var currentTag
for (var i = 0; i < playerTags.children.length; i++){
if (playerTags.children[i].player.userId == multiplayer.localPlayer.userId){
currentTag = playerTags.children[i]
}
}
var oldLevel = currentTag.level
currentTag.getPlayerData(false)
if (oldLevel != currentTag.level){
gameScene.gameOver.level = currentTag.level
gameScene.gameOver.levelText.visible = true
} else {
gameScene.gameOver.levelText.visible = false
}
if (!multiplayer.singlePlayer && !gameNetwork.user.hasCustomNickName()) {
gameScene.switchName.visible = true
}
scaleHand(1.0)
gameOver = true
onuButton.blinkAnimation.stop()
aiTimeOut.stop()
timer.running = false
depot.effectTimer.stop()
multiplayer.leaderCode(function () {
restartGameTimer.start()
})
ga.logEvent("System", "End Game", "singlePlayer", multiplayer.singlePlayer)
flurry.logEvent("System.EndGame", "singlePlayer", multiplayer.singlePlayer)
flurry.endTimedEvent("Game.TimeInGameSingleMatch", {"singlePlayer": multiplayer.singlePlayer})
}
function startNewGame(){
restartGameTimer.stop()