Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 19 ■ Game Content enGine: ai LoGiC with random Content SeLeCtion methodS

Go back into your createSceneProcessing() method and add a resetTextureMaps(); method call at
the top of your if (picked == spinner) { ... } construct, as shown in Figure 19-17. NetBeans will pop
up a helper menu offering to code the method body for you, so select and double-click the Create method
“resetTextureMaps()” in javafxgame.JavaFXGame option, which is shown in blue in the middle of
Figure 19-17.


Creating this new method body is relatively easy using the copy-and-paste programming technique. All
you have to do is to type the new Image instantiation Java statement referencing gameboardsquare.png and
type the new Shader1 statement setting the setDiffuseMap() method to the diffuse1 Image object. After that,
all you have to do is to select those two lines of code, copy them 19 more times underneath the first two lines
of code, change 1 to the numbers 2 through 20, and add those numbers to the end of the PNG file names,
which will reference the different color default game board square texture map assets.
This will result in the following 40 Java programming statements, which are also shown in light blue and
yellow in Figure 19-18:


private void resetTextureMaps() {
diffuse1 = new Image("/gameboardsquare.png", 256, 256, true, true, true);
Shader1.setDiffuseMap(diffuse1);
Diffuse2 = new Image("/gameboardsquare2.png", 256, 256, true, true, true);
Shader2.setDiffuseMap(diffuse2);
Diffuse3 = new Image("/gameboardsquare.png3", 256, 256, true, true, true);
Shader3.setDiffuseMap(diffuse3);
diffuse4 = new Image("/gameboardsquare.png4", 256, 256, true, true, true);
Shader4.setDiffuseMap(diffuse4);
Diffuse5 = new Image("/gameboardsquare.png5", 256, 256, true, true, true);
Shader5.setDiffuseMap(diffuse5);
Diffuse6 = new Image("/gameboardsquare.png6", 256, 256, true, true, true);
Shader6.setDiffuseMap(diffuse6);
Diffuse7 = new Image("/gameboardsquare.png7", 256, 256, true, true, true);
Shader7.setDiffuseMap(diffuse7);


Figure 19-17. Add the resetTextureMaps() method call to the MouseClick event handling code; press Alt+Enter
to have NetBeans create it

Free download pdf