-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #752 from Bram-Hub/gridPK
Initializing Grid Region Colors
- Loading branch information
Showing
10 changed files
with
244 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<Legup version="2.0.0"> | ||
<puzzle name="RippleEffect"> | ||
<board height="3" width="3"> | ||
<region> | ||
<cells> | ||
<cell value="1" x="0" y="0"/> | ||
<cell value="2" x="1" y="0"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="4" x="0" y="1"/> | ||
<cell value="3" x="0" y="2"/> | ||
<cell value="5" x="1" y="2"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="6" x="2" y="0"/> | ||
<cell value="7" x="1" y="1"/> | ||
<cell value="8" x="2" y="1"/> | ||
<cell value="9" x="2" y="2"/> | ||
</cells> | ||
</region> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="--"/> | ||
</Legup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/edu/rpi/legup/puzzle/rippleeffect/RippleEffectCellController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package edu.rpi.legup.puzzle.rippleeffect; | ||
|
||
import edu.rpi.legup.controller.ElementController; | ||
import edu.rpi.legup.model.gameboard.PuzzleElement; | ||
|
||
import java.awt.event.MouseEvent; | ||
|
||
public class RippleEffectCellController extends ElementController { | ||
|
||
@Override | ||
public void changeCell(MouseEvent e, PuzzleElement data) { | ||
// Since we don't need to change any cell data in Ripple Effect, | ||
// we leave this method empty. | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/edu/rpi/legup/puzzle/rippleeffect/RippleEffectCellType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/edu/rpi/legup/puzzle/rippleeffect/RippleEffectElementView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package edu.rpi.legup.puzzle.rippleeffect; | ||
|
||
import edu.rpi.legup.model.gameboard.PuzzleElement; | ||
import edu.rpi.legup.ui.boardview.GridElementView; | ||
|
||
import java.awt.*; | ||
|
||
public class RippleEffectElementView extends GridElementView { | ||
|
||
public RippleEffectElementView(RippleEffectCell cell) { | ||
super(cell); | ||
} | ||
|
||
/** | ||
* Gets the PuzzleElement associated with this view | ||
* | ||
* @return PuzzleElement associated with this view | ||
*/ | ||
@Override | ||
public RippleEffectCell getPuzzleElement() { | ||
return (RippleEffectCell) super.getPuzzleElement(); | ||
} | ||
|
||
@Override | ||
public void drawElement(Graphics2D graphics2D) { | ||
RippleEffectCell cell = getPuzzleElement(); | ||
RippleEffectCellType type = cell.getType(); | ||
|
||
// Draw the cell based on its type | ||
switch (type) { | ||
case WHITE: | ||
graphics2D.setColor(Color.WHITE); | ||
break; | ||
case BLUE: | ||
graphics2D.setColor(Color.BLUE); | ||
break; | ||
case RED: | ||
graphics2D.setColor(Color.RED); | ||
break; | ||
case YELLOW: | ||
graphics2D.setColor(Color.YELLOW); | ||
break; | ||
case GREEN: | ||
graphics2D.setColor(Color.GREEN); | ||
break; | ||
default: | ||
// For BLACK and any other type | ||
graphics2D.setColor(Color.BLACK); | ||
break; | ||
} | ||
|
||
// Fill the cell with the color | ||
graphics2D.fillRect(location.x, location.y, size.width, size.height); | ||
|
||
// Draw a black border | ||
graphics2D.setColor(Color.BLACK); | ||
graphics2D.drawRect(location.x, location.y, size.width, size.height); | ||
|
||
// Draw the number inside the cell | ||
graphics2D.setColor(Color.BLACK); | ||
graphics2D.setFont(new Font("Arial", Font.BOLD, 14)); | ||
String data = String.valueOf(cell.getNumber()); | ||
FontMetrics metrics = graphics2D.getFontMetrics(); | ||
int x = location.x + (size.width - metrics.stringWidth(data)) / 2; | ||
int y = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); | ||
graphics2D.drawString(data, x, y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/edu/rpi/legup/puzzle/rippleeffect/RippleEffectRegion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package edu.rpi.legup.puzzle.rippleeffect; | ||
|
||
import java.awt.Color; | ||
|
||
public class RippleEffectRegion { | ||
private char color; | ||
|
||
public RippleEffectRegion(char color) { | ||
this.color = color; | ||
} | ||
|
||
public char getColor() { | ||
return color; | ||
} | ||
|
||
public void setColor(char color) { | ||
this.color = color; | ||
} | ||
} |
Oops, something went wrong.