File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,52 @@ public class Referee extends AbstractReferee {
73
73
74
74
The Game Manager's API will thus work with your ` Player ` class, which you may modify at leisure.
75
75
76
+ ## Working with Guice
77
+
78
+ Since the SDK uses injections to handle the instantiation of its different components, it is important to note a few things:
79
+ - An injected field will be instantiated by Guice, those field with ` @Inject ` will always be ` null ` if you instantiate the class yourself.
80
+ - Any simple class can be injected into yout ` Referee ` and you can inject the ` Referee ` or ` GraphicEntityModule ` into any custom class.
81
+
82
+ ### Example
83
+
84
+ ` Referee.java `
85
+ ``` java
86
+ public class Referee extends AbstractReferee {
87
+ @Inject MultiplayerGameManager<Player > gameManager;
88
+ @Inject MyGridMaker gridMaker;
89
+
90
+ @Override
91
+ public void init () {
92
+ // Map size can be 5,6,7 or 8
93
+ int mapSize = 5 + new Random (gameManager. getSeed()). nextInt(4 )
94
+ gridMaker. init(mapSize);
95
+ }
96
+ }
97
+ ```
98
+
99
+ ` MyGridMaker.java `
100
+ ``` java
101
+ public class MyGridMaker {
102
+ @Inject GraphicEntityModule entityModule;
103
+
104
+ public static final int cell_size = 20 ;
105
+
106
+ @Override
107
+ public void init (int size ) {
108
+ // Use the injected GraphicEntityModule to create a grid
109
+ for (int y = 0 ; y < size; ++ y) {
110
+ for (int x = 0 ; x < size; ++ x) {
111
+ entityModule. createRectangle()
112
+ .setX(x * cell_size)
113
+ .setY(y * cell_size)
114
+ .setWidth(cell_size)
115
+ .setHeight(cell_size);
116
+ }
117
+ }
118
+ }
119
+ }
120
+ ```
121
+
76
122
# Features
77
123
78
124
## General Features
You can’t perform that action at this time.
0 commit comments