Mercurial > hg > ristipolku
comparison game/Engine.java @ 27:26adc2827983
More work on the internals.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 01 Feb 2011 20:38:19 +0200 |
parents | 3d4cc47df31a |
children | 60a4579a79df |
comparison
equal
deleted
inserted
replaced
26:3d4cc47df31a | 27:26adc2827983 |
---|---|
29 | 29 |
30 this.out = out; | 30 this.out = out; |
31 this.outX = outX; | 31 this.outX = outX; |
32 this.outY = outY; | 32 this.outY = outY; |
33 } | 33 } |
34 | |
35 public void print() | |
36 { | |
37 System.out.print("PathInfo: inP="+in+", inX="+inX+", inY="+inY+"\n"); | |
38 System.out.print(" outP="+out+", outX="+outX+", outY="+outY+"\n"); | |
39 } | |
34 } | 40 } |
35 | 41 |
36 /* | 42 /* |
37 class AnimatedElement | 43 class AnimatedElement |
38 { | 44 { |
127 private boolean isEmpty(int x, int y) | 133 private boolean isEmpty(int x, int y) |
128 { | 134 { |
129 return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null); | 135 return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null); |
130 } | 136 } |
131 | 137 |
132 private Piece getPiece(int x, int y) | |
133 { | |
134 if (x >= 0 && x < boardSize && y >= 0 && y < boardSize) | |
135 return board[x][y]; | |
136 else | |
137 return null; | |
138 } | |
139 | |
140 public void pieceRotate(boolean dir) | 138 public void pieceRotate(boolean dir) |
141 { | 139 { |
142 if (current != null) | 140 if (current != null) |
143 current.rotate(dir); | 141 current.rotate(dir); |
144 } | 142 } |
145 | 143 |
146 public PathInfo resolvePath(int startX, int startY, int startPoint, boolean mark) | 144 public PathInfo resolvePath(int startX, int startY, int startPoint, boolean mark) |
147 { | 145 { |
148 int x = startX, y = startY; | 146 int x = startX, y = startY; |
149 int point = -1; | 147 int point = startPoint; |
150 | 148 Piece curr = board[x][y]; |
151 Piece curr = getPiece(startX, startY); | 149 |
152 if (curr == null) | 150 do |
153 return null; | 151 { |
154 | 152 if (x >= 0 && x < boardSize && y >= 0 && y < boardSize) |
155 /* | 153 { |
156 while (curr != null) | 154 curr = board[x][y]; |
157 { | 155 if (curr == null) |
158 // curr.(true); | 156 break; |
159 // elements.spawn("", ); | 157 |
160 } | 158 if (curr.getType() == PieceType.START) |
161 */ | 159 { |
162 | 160 // Hit center starting piece |
161 return null; | |
162 } | |
163 else | |
164 { | |
165 // Mark, if needed | |
166 if (mark) | |
167 { | |
168 curr.setType(PieceType.LOCKED); | |
169 curr.setActiveConnection(point); | |
170 } | |
171 | |
172 // Get next piece | |
173 point = curr.getConnection(point); | |
174 switch (point) | |
175 { | |
176 case 0: y--; break; | |
177 case 1: y--; break; | |
178 case 2: x++; break; | |
179 case 3: x++; break; | |
180 case 4: y++; break; | |
181 case 5: y++; break; | |
182 case 6: x--; break; | |
183 case 7: x--; break; | |
184 } | |
185 } | |
186 } | |
187 else | |
188 { | |
189 // Outside of the board | |
190 return null; | |
191 } | |
192 } | |
193 while (curr != null); | |
194 | |
163 return new PathInfo(startPoint, startX, startY, point, x, y); | 195 return new PathInfo(startPoint, startX, startY, point, x, y); |
164 } | 196 } |
165 | 197 |
166 public void pieceFinishTurn() | 198 public void pieceFinishTurn() |
167 { | 199 { |
170 current.setType(PieceType.LOCKED); | 202 current.setType(PieceType.LOCKED); |
171 PathInfo i = resolvePath(moveX, moveY, movePoint, true); | 203 PathInfo i = resolvePath(moveX, moveY, movePoint, true); |
172 | 204 |
173 if (i != null) | 205 if (i != null) |
174 { | 206 { |
207 System.out.print("moveX="+moveX+", moveY="+moveY+", movePoint="+movePoint+"\n"); | |
208 i.print(); | |
209 moveX = i.outX; | |
210 moveY = i.outY; | |
211 movePoint = i.out; | |
175 } | 212 } |
176 } | 213 } |
177 | 214 |
178 current = new Piece(PieceType.ACTIVE); | 215 current = new Piece(PieceType.ACTIVE); |
179 if (isEmpty(moveX, moveY)) | 216 if (isEmpty(moveX, moveY)) |
184 { | 221 { |
185 PathInfo i = resolvePath(moveX, moveY, movePoint, true); | 222 PathInfo i = resolvePath(moveX, moveY, movePoint, true); |
186 if (i != null) | 223 if (i != null) |
187 board[moveX][moveY] = current; | 224 board[moveX][moveY] = current; |
188 else | 225 else |
226 { | |
227 System.out.print("pieceFinishTurn(): Game Over!\n"); | |
189 flagGameOver = true; | 228 flagGameOver = true; |
229 } | |
190 } | 230 } |
191 } | 231 } |
192 } | 232 } |
193 | 233 |
194 | 234 |