MultiplayerDemoSimple
import Felgo 3.0
import QtQuick 2.0
Scene{
id: scene
property alias multiplayerView: multiplayerView
SimpleButton {
anchors.right: parent.right
anchors.top: parent.top
text: "Language: " + settings.language
onClicked: settings.language = settings.language == "en_EN" ? "de_DE" : "en_EN"
}
SimpleButton {
id: startButton
text: "Start Game"
anchors.centerIn: parent
onClicked: multiplayer.showMatchmaking()
}
SimpleButton {
text: "Inbox"
anchors.top: startButton.bottom
anchors.topMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
onClicked: multiplayer.showInbox()
}
MultiplayerView {
id: multiplayerView
visible: false
onShowCalled: multiplayerView.visible = true
onBackClicked: multiplayerView.visible = false
Column {
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 6
spacing: 6
Repeater {
model: multiplayer.playerCount - 1
SimpleButton {
visible: multiplayer.isInState(multiplayer.stateEnum.room) && !multiplayer.players[index + 1].connected && multiplayer.amLeader
text: (multiplayer.enabledPlayerCount > 0 && multiplayer.initialized && multiplayer.players[index + 1].enabled
? "Disable player #" : "Enable player #") + (index + 2)
onClicked: multiplayer.enabledPlayerCount && multiplayer.players[index + 1].enabled
? multiplayer.disablePlayer(index + 1) : multiplayer.enablePlayer(index + 1)
}
}
SimpleButton {
text: "Player count: " + multiplayer.playerCount
onClicked: multiplayer.playerCount = multiplayer.playerCount === 4 ? 2 : (multiplayer.playerCount + 1)
visible: multiplayer.isInState(multiplayer.stateEnum.lobby) || multiplayer.isInState(multiplayer.stateEnum.uninitialized)
}
}
}
Rectangle {
id: game
width: parent.width; height: parent.height;
visible: false
color: "white"
property alias text: text.text
Column{
Repeater{
model: multiplayer.players
Text{
text: modelData.name + (modelData.leader ? " [Leader]": "")
color: modelData.activeTurn ? "green" : "red"
}
}
SimpleButton{
text: "SEND PING"
onClicked: {
multiplayer.sendMessage(5, "PING")
game.text += "PING sent\n"
multiplayer.triggerNextTurn();
}
enabled: multiplayer.myTurn
color: multiplayer.myTurn ? "green" : "red"
}
SimpleButton{
text: "SEND REVERSE PING"
onClicked: {
multiplayer.sendMessage(5, "PING")
game.text += "PING sent\n"
multiplayer.triggerPreviousTurn();
}
enabled: multiplayer.myTurn
color: multiplayer.myTurn ? "green" : "red"
}
Text {
id: text
text: "RECEIVED MESSAGES:\n"
}
}
SimpleButton {
text: "Leave Game"
anchors.right: parent.right
onClicked: {
multiplayer.leaveGame()
game.visible = false
}
}
}
Connections {
target: multiplayer
onGameStarted: {
multiplayerView.visible = false
game.visible = true
}
onMessageReceived: {
if(code == 5) {
game.text += "PING received from " +player.name+"\n"
multiplayer.sendMessage(6, "PONG")
game.text += "PONG sent\n"
}
else if(code == 6) {
game.text += "PONG received from "+player.name+"\n"
}
}