O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – implementing game logic

Most of the required preparations are done, and now it's time to make our game functional. The player should be able to make a move by clicking on a rod and then clicking on another rod. After the first rod is selected, the game should remember it and show it in a different color.

First, let's prepare the Rod component. We need it to have a new property that indicates that this rod was selected as the first rod for the next move:

property bool isSourceRod: false

It's easy to make the rod change color depending on the isSourceRod value using a property binding:

DiffuseSpecularMaterial {    ambient: {        if (isSourceRod) {            return picker.containsMouse? "#f44" : "#f11";        } else { return picker.containsMouse? ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required