|
|
|
|
Strumenti |
04-02-2008, 20:25 | #21 | |
Senior Member
Iscritto dal: Nov 2005
Città: Bologna
Messaggi: 1303
|
Quote:
Ok... se non l'avete ancora fatto metto tutto a Cell, anche se secondo me ci complica la vita. Ma se lo dice il God in persona EDIT: Io sto ancora cercando di semplificare il GridTestCase, la sto prendeno un po' alla lontana mettendoa posto TestGrid, ma cosi' dovremmo avere molto piu' controllo sui test in Grid, rendendoci piu' semplice il GridTestCase e di conseguenza l'80% dei test fatti fino ad ora. Sono esentato dal Refactor This oppure prima li faccio fuori tutti e poi posso andare avanti ?! Ultima modifica di Bonfo : 04-02-2008 alle 20:29. |
|
04-02-2008, 21:40 | #22 |
Senior Member
Iscritto dal: Aug 2001
Città: San Francisco, CA, USA
Messaggi: 13826
|
Era :
it.diamonds.grid.action.CrushByChestAction.java Linea 62 Codice:
private void getAdjacentCrushableGems(Droppable crushSourceDroppable, DroppableList adiacentCrushableGems) { // TODO: REFACTOR THIS Region sourceCell = crushSourceDroppable.getRegion(); if(sourceCell.getLeftColumn() >= 1) { getLeftOrRightAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems, GO_LEFT); } if(sourceCell.getRightColumn() < getGrid().getNumberOfColumns() - 1) { getLeftOrRightAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems, GO_RIGHT); } if(sourceCell.getTopRow() >= 1) { getUpOrDownAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems, GO_UP); } if(sourceCell.getBottomRow() < getGrid().getNumberOfRows() - 1) { getUpOrDownAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems, GO_DOWN); } } Codice:
private void getAdjacentCrushableGems(Droppable crushSourceDroppable, DroppableList adiacentCrushableGems) { getLeftOrRightAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems, GO_LEFT); getLeftOrRightAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems, GO_RIGHT); getUpOrDownAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems, GO_UP); getUpOrDownAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems, GO_DOWN); } ad esempio in getUpOrDown... è stato aggiunto: Codice:
if(row + direction.deltaY() < 0 || row + direction.deltaY() > getGrid().getNumberOfRows() - 1) { return; } Ciao
__________________
GPU Compiler Engineer |
04-02-2008, 21:44 | #23 |
Senior Member
Iscritto dal: Oct 2002
Città: California
Messaggi: 11781
|
La seconda che hai detto
__________________
"We in the game industry are lucky enough to be able to create our visions" |
04-02-2008, 21:45 | #24 | |
Senior Member
Iscritto dal: Oct 2002
Città: California
Messaggi: 11781
|
Quote:
Bene, mi piace molto, mi rendi ora piu' chiaro quell'if? E' troppo lunghetto.
__________________
"We in the game industry are lucky enough to be able to create our visions" |
|
04-02-2008, 22:02 | #25 | |
Senior Member
Iscritto dal: Aug 2001
Città: San Francisco, CA, USA
Messaggi: 13826
|
Quote:
La funzione da rifattorizzare diventa : Codice:
private void getAdjacentCrushableGems(Droppable crushSourceDroppable, DroppableList adiacentCrushableGems) { getLeftAndRightAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems); getUpAndDownAdjacentCrushableGems(crushSourceDroppable, adiacentCrushableGems); } Codice:
private void getUpAndDownAdjacentCrushableGems(Droppable source, DroppableList adiacentCrushableGems) { int row = source.getRegion().getTopRow(); Direction direction = GO_UP; if(row + direction.deltaY() >= 0) { for(int column = source.getRegion().getLeftColumn(); column <= source.getRegion().getRightColumn(); column++) { Droppable toTest = getGrid().getDroppableAt(row + direction.deltaY(), column); tryToAddGemToCrushableGems(toTest, source, adiacentCrushableGems); } } row = source.getRegion().getBottomRow(); direction = GO_DOWN; if(row + direction.deltaY() <= getGrid().getNumberOfRows() - 1) { for(int column = source.getRegion().getLeftColumn(); column <= source.getRegion().getRightColumn(); column++) { Droppable toTest = getGrid().getDroppableAt(row + direction.deltaY(), column); tryToAddGemToCrushableGems(toTest, source, adiacentCrushableGems); } } } private void getLeftAndRightAdjacentCrushableGems(Droppable source, DroppableList adiacentCrushableGems) { int column = source.getRegion().getLeftColumn(); Direction direction = GO_LEFT; if(column + direction.deltaX() >= 0) { for(int row = source.getRegion().getTopRow(); row <= source.getRegion().getBottomRow(); row++) { Droppable toTest = getGrid().getDroppableAt(row, column + direction.deltaX()); tryToAddGemToCrushableGems(toTest, source, adiacentCrushableGems); } } column = source.getRegion().getRightColumn(); direction = GO_RIGHT; if(column + direction.deltaX() <= getGrid().getNumberOfColumns() - 1) { for(int row = source.getRegion().getTopRow(); row <= source.getRegion().getBottomRow(); row++) { Droppable toTest = getGrid().getDroppableAt(row, column + direction.deltaX()); tryToAddGemToCrushableGems(toTest, source, adiacentCrushableGems); } } } Il numero di righe delle funzioni UpAndDown e LeftAndRight rimane praticamente invariato (2 righe in più) Ciao
__________________
GPU Compiler Engineer |
|
04-02-2008, 22:06 | #26 |
Senior Member
Iscritto dal: Oct 2002
Città: California
Messaggi: 11781
|
Preferivo l'altra. Le due funzione getUpAndDown... e l'altra sono troppo complesse. Non si capisce che cosa stiano facendo solo leggendo il codice.
Lo dice anche il nome secondo stesso secondo me. Io dividerei ognuna in due. Puoi lavorarci un po'?
__________________
"We in the game industry are lucky enough to be able to create our visions" |
04-02-2008, 22:10 | #27 | |
Senior Member
Iscritto dal: Aug 2001
Città: San Francisco, CA, USA
Messaggi: 13826
|
Quote:
EDIT Così va bene l'if? Codice:
CAVOLATA :fagiano:
__________________
GPU Compiler Engineer Ultima modifica di AnonimoVeneziano : 04-02-2008 alle 22:14. |
|
04-02-2008, 22:11 | #28 |
Senior Member
Iscritto dal: Oct 2002
Città: California
Messaggi: 11781
|
Vedi tu
__________________
"We in the game industry are lucky enough to be able to create our visions" |
04-02-2008, 22:21 | #29 |
Senior Member
Iscritto dal: Aug 2001
Città: San Francisco, CA, USA
Messaggi: 13826
|
Ok, torniamo al vecchio
Così ? : Codice:
row += direction.deltaY(); if(row < 0 || row > getGrid().getNumberOfRows() - 1) { return; } Ciao
__________________
GPU Compiler Engineer |
04-02-2008, 22:41 | #30 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 1536
|
Rifattorizzo questo:
Codice:
public void testDrawTwoFrames() { int frameSize = 32; AnimatedSprite animatedSprite = createAnimatedSprite(3, 100, frameSize); timer.advance(ANIMATION_DELAY); animatedSprite.updateAnimation(timer.getTime()); animatedSprite.getSprite().draw(engine); assertEquals("bad texture drawn", 0, ((MockEngine)engine).getImageRect().getLeft()); assertEquals("bad texture drawn", frameSize, ((MockEngine)engine).getImageRect().getTop()); timer.advance(100); animatedSprite.updateAnimation(timer.getTime()); animatedSprite.getSprite().draw(engine); assertEquals("bad texture drawn", 0, ((MockEngine)engine).getImageRect().getLeft()); assertEquals("bad texture drawn", frameSize * 2, ((MockEngine)engine).getImageRect().getTop()); } Codice:
public void testRenderingOfFirstFrame() { AnimatedSprite animatedSprite = createAnimatedSprite(2, 100, FRAME_SIZE); animatedSprite.updateAnimation(timer.getTime()); animatedSprite.getSprite().draw(engine); Rectangle expectedImageRectangle = new Rectangle(0, 0, FRAME_SIZE, FRAME_SIZE); assertEquals(expectedImageRectangle, engine.getImageRect()); } public void testRenderingOfSecondFrame() { AnimatedSprite animatedSprite = createAnimatedSprite(2, 100, FRAME_SIZE); timer.advance(ANIMATION_DELAY); animatedSprite.updateAnimation(timer.getTime()); animatedSprite.getSprite().draw(engine); Rectangle expectedImageRectangle = new Rectangle(0, FRAME_SIZE, FRAME_SIZE, FRAME_SIZE); assertEquals(expectedImageRectangle, engine.getImageRect()); } public void testRenderingOfThirdFrame() { final int animationUpdateRate = 100; AnimatedSprite animatedSprite = createAnimatedSprite(3, animationUpdateRate, FRAME_SIZE); timer.advance(ANIMATION_DELAY); timer.advance(animationUpdateRate); animatedSprite.updateAnimation(timer.getTime()); animatedSprite.getSprite().draw(engine); Rectangle expectedImageRectangle = new Rectangle(0, FRAME_SIZE * 2, FRAME_SIZE, FRAME_SIZE); assertEquals(expectedImageRectangle, engine.getImageRect()); } Si potrebbe fare ancora qualcosina ma mi accontento, e` abbastanza chiaro penso :o |
04-02-2008, 22:57 | #31 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 1536
|
Prima:
Codice:
private Droppable getGemToDelete(Droppable falshingGem) { //TODO: REFACTOR THIS Region region = falshingGem.getRegion(); Cell cell = new Cell(region.getTopRow(), region.getLeftColumn()); Droppable gemToDelete = searchGemToDelete(cell); if(gemToDelete == null) { gemToDelete = searchLeft(cell); if(gemToDelete == null) { gemToDelete = searchRight(cell); if(gemToDelete == null) { gemToDelete = searchUp(cell); } } } return gemToDelete; } private Droppable searchGemToDelete(Cell cell) { if((cell.getRow() < getGrid().getNumberOfRows() - 1)) { return getGem(cell.getLower()); } return null; } private Droppable searchLeft(Cell cell) { if(cell.getColumn() >= 1) { return getGem(cell.getLeft()); } return null; } private Droppable searchRight(Cell cell) { if(cell.getColumn() < getGrid().getNumberOfColumns() - 1) { return getGem(cell.getRight()); } return null; } private Droppable searchUp(Cell cell) { if(cell.getRow() > 1) { return getGem(cell.getUpper()); } return null; } Codice:
private Droppable getGemToDelete(Droppable falshingGem) { Region region = falshingGem.getRegion(); Cell cell = new Cell(region.getTopRow(), region.getLeftColumn()); Direction directions[] = {Direction.GO_DOWN, Direction.GO_LEFT, Direction.GO_RIGHT, Direction.GO_UP}; for (Direction direction : directions) { Droppable gemToDelete = searchGemToDelete(cell, direction); if (gemToDelete != null) { return gemToDelete; } } return null; } private Droppable searchGemToDelete(Cell cell, Direction direction) { final int rowToSearch = cell.getRow() + direction.deltaY(); final int columnToSearch = cell.getColumn() + direction.deltaX(); final boolean isValidCell = getGrid().isValidCell(rowToSearch, columnToSearch); if (!isValidCell) { return null; } return getGem(new Cell(rowToSearch, columnToSearch)); } |
04-02-2008, 23:25 | #32 |
Senior Member
Iscritto dal: Nov 2005
Città: Bologna
Messaggi: 1303
|
|
04-02-2008, 23:27 | #33 |
Member
Iscritto dal: Apr 2006
Città: Gazzaniga (BG)
Messaggi: 67
|
Per evitare cose del genere o sovrapposizioni di lavoro non si potrebbe creare un topic "Io sto lavorando su..." in cui inserire cosa si sta facendo? Ad esempio su quale Refactor This ci si sta impegnando? (questo eventualmente si può fare anche qua, postando prima di modificarlo ed editando a lavoro completato)
|
05-02-2008, 00:16 | #34 |
Senior Member
Iscritto dal: Nov 2005
Città: Bologna
Messaggi: 1303
|
Io sto rimettendo tutti i cell che avevo tolto!
Mi ci vorra' un po', anche perche' nel mentre lavoro :P |
05-02-2008, 00:16 | #35 | |
Senior Member
Iscritto dal: Oct 2002
Città: California
Messaggi: 11781
|
Quote:
Fede, refactoring stilosissimo
__________________
"We in the game industry are lucky enough to be able to create our visions" |
|
05-02-2008, 00:39 | #36 |
Member
Iscritto dal: Apr 2006
Città: Gazzaniga (BG)
Messaggi: 67
|
Lavorando in CrushByFlashAction.java su getAllGemsSameOf.
Prima: Codice:
//TODO: REFACTOR THIS private DroppableList getAllGemsSameOf(Droppable gemToDelete) { DroppableList gemList = new DroppableList(); Droppable gem; for(int row = getGrid().getNumberOfRows() - 1; row >= 0; row--) { for(int column = 0; column < getGrid().getNumberOfColumns(); column++) { gem = getGrid().getDroppableAt(row, column); if(gem == null) { continue; } if(gem.getGridObject().getColor() == gemToDelete.getGridObject().getColor()) { if(!gemList.contains(gem)) { gemList.add(gem); } } } } return gemList; } Codice:
public void apply(DroppableList gridElements) { super.apply(gridElements); applyToEachDroppable(); } ... private DroppableList getAllGemsSameOf(Droppable gemToDelete) { DroppableList gridElements = getGridElements(); DroppableList gemSameList = new DroppableList(); for(Droppable droppable : gridElements) { if(droppable.getGridObject().getColor() == gemToDelete.getGridObject().getColor()) { gemSameList.add(droppable); } } return gemSameList; } Ultima modifica di Baol : 05-02-2008 alle 02:17. |
05-02-2008, 00:55 | #37 |
Senior Member
Iscritto dal: Nov 2005
Città: Bologna
Messaggi: 1303
|
Rimettendo tutti i new Cell() dentro codice e test, mi sono reso conto chesi usanbo moltissimo la coppia 0, 4 e 1, 4, ovvero qulle delle gemsPair.
Che ne di te di un bel campo statico in GemsPair?? |
05-02-2008, 01:06 | #38 | |
Senior Member
Iscritto dal: Aug 2001
Città: San Francisco, CA, USA
Messaggi: 13826
|
Quote:
Mmm, qua ci vorrebbe un modo facile per ottenere tutte le gemme dello stesso tipo nella griglia ...
__________________
GPU Compiler Engineer |
|
05-02-2008, 01:17 | #39 |
Senior Member
Iscritto dal: Nov 2005
Città: Bologna
Messaggi: 1303
|
Scusate, ma perche' invece di andare per riga e per colonna non andiamo con l'iteratore sull'elenco di droppabales??
Codice:
for(Droppable droppabel : grid.getDroppableList()) { } Codice:
for(Iterator iterator = grid.getDroppableList().iterator(); iterator.hasNext();) { Droppable droppable = (Droppable)iterator.next(); } |
05-02-2008, 01:19 | #40 |
Senior Member
Iscritto dal: Nov 2005
Città: Bologna
Messaggi: 1303
|
Piccolo problemi che ritorna prepotente...
Quando creo una cella con valori negativi mi becco una exception. Che faccio: aggiungo controlli ovunque?? in realta' basta che isValidCell continui aragionare a row e column. Che si fa? Ultima modifica di Bonfo : 05-02-2008 alle 01:25. |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:49.