Mercurial > hg > ristipolku
comparison game/Engine.java @ 41:a5fd4f74a767
Rename some variables.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 19 Feb 2011 03:05:13 +0200 |
parents | a69103644bf6 |
children | 951a4d669af0 |
comparison
equal
deleted
inserted
replaced
40:a69103644bf6 | 41:a5fd4f74a767 |
---|---|
114 class GameBoard | 114 class GameBoard |
115 { | 115 { |
116 public static final int boardSize = 9; | 116 public static final int boardSize = 9; |
117 public static final int boardMiddle = 4; | 117 public static final int boardMiddle = 4; |
118 Piece[][] board; | 118 Piece[][] board; |
119 Piece current; | |
120 public boolean flagGameOver; | 119 public boolean flagGameOver; |
121 | 120 |
122 int moveX, moveY, movePoint; | 121 Piece currPiece; |
122 int currX, currY, currPoint; | |
123 | 123 |
124 public GameBoard() | 124 public GameBoard() |
125 { | 125 { |
126 board = new Piece[boardSize][boardSize]; | 126 board = new Piece[boardSize][boardSize]; |
127 | 127 |
128 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); | 128 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); |
129 | 129 |
130 moveX = boardMiddle; | 130 currX = boardMiddle; |
131 moveY = boardMiddle - 1; | 131 currY = boardMiddle - 1; |
132 movePoint = 5; | 132 currPoint = 5; |
133 | 133 |
134 pieceFinishTurn(); | 134 pieceFinishTurn(); |
135 | 135 |
136 flagGameOver = false; | 136 flagGameOver = false; |
137 } | 137 } |
169 return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null); | 169 return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null); |
170 } | 170 } |
171 | 171 |
172 public void pieceRotate(Piece.RotateDir dir) | 172 public void pieceRotate(Piece.RotateDir dir) |
173 { | 173 { |
174 if (current != null) | 174 if (currPiece != null) |
175 current.rotate(dir); | 175 currPiece.rotate(dir); |
176 } | 176 } |
177 | 177 |
178 public PathInfo resolvePath(int startX, int startY, int startPoint, boolean mark) | 178 public PathInfo resolvePath(int startX, int startY, int startPoint, boolean mark) |
179 { | 179 { |
180 int x = startX, y = startY; | 180 int x = startX, y = startY; |
233 } | 233 } |
234 | 234 |
235 public void pieceFinishTurn() | 235 public void pieceFinishTurn() |
236 { | 236 { |
237 // Do we have a piece? | 237 // Do we have a piece? |
238 if (current != null) | 238 if (currPiece != null) |
239 { | 239 { |
240 // Yes, start resolving path to next piece placement | 240 // Yes, start resolving path to next piece placement |
241 PathInfo i = resolvePath(moveX, moveY, movePoint, true); | 241 PathInfo i = resolvePath(currX, currY, currPoint, true); |
242 | 242 |
243 if (i != null) | 243 if (i != null) |
244 { | 244 { |
245 moveX = i.outX; | 245 currX = i.outX; |
246 moveY = i.outY; | 246 currY = i.outY; |
247 movePoint = i.out; | 247 currPoint = i.out; |
248 } | 248 } |
249 } | 249 } |
250 | 250 |
251 // Create a new piece | 251 // Create a new piece |
252 current = new Piece(PieceType.ACTIVE); | 252 currPiece = new Piece(PieceType.ACTIVE); |
253 | 253 |
254 // Find a place for it | 254 // Find a place for it |
255 if (isEmpty(moveX, moveY)) | 255 if (isEmpty(currX, currY)) |
256 { | 256 { |
257 // Current position is empty, use it | 257 // Current position is empty, use it |
258 board[moveX][moveY] = current; | 258 board[currX][currY] = currPiece; |
259 } | 259 } |
260 else | 260 else |
261 { | 261 { |
262 // Resolve path | 262 // Resolve path |
263 PathInfo i = resolvePath(moveX, moveY, movePoint, true); | 263 PathInfo i = resolvePath(currX, currY, currPoint, true); |
264 if (i != null) | 264 if (i != null) |
265 { | 265 { |
266 // Path found, place the piece | 266 // Path found, place the piece |
267 board[moveX][moveY] = current; | 267 board[currX][currY] = currPiece; |
268 } | 268 } |
269 else | 269 else |
270 { | 270 { |
271 // Path ended up center/gameboard walls - it's game over, man | 271 // Path ended up center/gameboard walls - it's game over, man |
272 System.out.print("pieceFinishTurn(): Game Over!\n"); | 272 System.out.print("pieceFinishTurn(): Game Over!\n"); |