Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

MultiplayerDemo

 import Felgo 3.0
 import QtQuick 2.0

 // each player adds a certain amount of time to the clock
 Item {
   id: clock
   width: 120
   height: frame.height + display.contentHeight + display.anchors.topMargin

   // the current time of the clock
   property int time
   property bool twelve: time % 12 == 0
   property bool day: time > 6 && time <= 18
   property color sky: getSkyColor()

   // image of the clock frame
   Image {
     id: frame
     width: parent.width
     height: width
     source: "../../assets/img/Clock.png"
   }

   // the moving needle of the clock rotates using the time
   Rectangle {
     id: needle
     height: frame.height / 2
     width: 6
     color: "black"
     transformOrigin: Item.Bottom
     x: frame.width/2 - width/2
     y: 0
     rotation: 30 * time

     // Behavious animates the needle's rotation
     Behavior on rotation {
       RotationAnimation { duration: 400; direction: RotationAnimation.Clockwise}
     }
   }

   Text {
     id: display
     text: time + ":00"
     anchors.horizontalCenter: parent.horizontalCenter
     anchors.top: frame.bottom
     anchors.topMargin: 5
     font.pixelSize: 18
     font.bold: true
   }

   // increase the time of the clock and check if it's 0 o'clock
   function addTime(add){
     var newTime = time + add;
     newTime %= 24;
     setTime(newTime)

     if (twelve)
       gConsole.printLn("It turned twelve o'clock thanks to " + multiplayer.activePlayer.name)
   }

   // increase the time of the clock and check if it's 0 o'clock
   function setTime(newTime){
     time = newTime
   }

   // return the color of the sky for the game background
   function getSkyColor(){
     var dayColor = "#9fedec"
     var noonColor = "#d7f8fc"
     var nightColor = "#8aa5c5"
     var midnightColor = "#5d80ac"

     if (twelve){
       return day ? noonColor : midnightColor
     }else{
       return day ? dayColor : nightColor
     }
   }

   // reset the clock between games
   function reset(){
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded