comparison game/Engine.java @ 53:6bf4675e2d96

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 23 Feb 2011 16:58:21 +0200
parents 01851bae3da3
children cc7943cd7f2d
comparison
equal deleted inserted replaced
52:01851bae3da3 53:6bf4675e2d96
140 case 6: currX--; break; 140 case 6: currX--; break;
141 case 7: currX--; break; 141 case 7: currX--; break;
142 } 142 }
143 } 143 }
144 144
145 public boolean pieceCheck(Piece curr) 145 public boolean pieceCheck(Piece piece)
146 { 146 {
147 if (curr == null) 147 if (piece == null)
148 { 148 {
149 // Create new piece 149 // Create new piece
150 currPiece = new Piece(PieceType.ACTIVE); 150 currPiece = new Piece(PieceType.ACTIVE);
151 board[currX][currY] = currPiece; 151 board[currX][currY] = currPiece;
152 return true; 152 return true;
153 } 153 }
154 else 154 else
155 if (curr.getType() == PieceType.START) 155 if (piece.getType() == PieceType.START)
156 { 156 {
157 if (currPiece != null) 157 if (currPiece != null)
158 { 158 {
159 // Hit center starting piece, game over 159 // Hit center starting piece, game over
160 flagGameOver = true; 160 flagGameOver = true;
161 currPiece = null;
162 System.out.print("GameOver!\n");
163 return true; 161 return true;
164 } 162 }
165 else 163 else
166 { 164 {
167 // Start piece as first piece means game is starting 165 // Start piece as first piece means game is starting
171 return true; 169 return true;
172 } 170 }
173 } 171 }
174 172
175 // Mark the current piece as locked 173 // Mark the current piece as locked
176 curr.setType(PieceType.LOCKED); 174 piece.setType(PieceType.LOCKED);
177 175
178 // Solve connection (with rotations) through the piece 176 // Solve connection (with rotations) through the piece
179 currPoint = curr.getRotatedPoint(curr.getMatchingPoint(currPoint)); 177 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint));
180 178
181 // Mark connection as active 179 // Mark connection as active
182 curr.setConnectionState(currPoint, true); 180 piece.setConnectionState(currPoint, true);
183 181
184 // Solve exit point (with rotations) 182 // Solve exit point (with rotations)
185 currPoint = curr.getAntiRotatedPoint(curr.getConnection(currPoint)); 183 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint));
186 184
187 // Move to next position accordingly 185 // Move to next position accordingly
188 pieceMoveTo(currPoint); 186 pieceMoveTo(currPoint);
189 return false; 187 return false;
190 } 188 }
201 else 199 else
202 { 200 {
203 // Outside of the board, game over 201 // Outside of the board, game over
204 finished = true; 202 finished = true;
205 flagGameOver = true; 203 flagGameOver = true;
206 currPiece = null; 204 }
207 System.out.print("GameOver!\n"); 205 }
208 } 206
207 if (flagGameOver)
208 {
209 currPiece = null;
210 System.out.print("GameOver!\n");
209 } 211 }
210 } 212 }
211 213
212 public boolean keyPressed(KeyEvent e) 214 public boolean keyPressed(KeyEvent e)
213 { 215 {