Skip to content

Commit c8367b8

Browse files
committed
Merge branch 'master' of github.com:kanawish/RHoK_libgdx
Conflicts: src/com/androidmontreal/rhok/WaterSupplyGame.java Signed-off-by: Boris Dubois <deus13@gmail.com>
2 parents 220647c + 21a88e7 commit c8367b8

15 files changed

+262
-93
lines changed

src/com/androidmontreal/rhok/WaterSupplyGame.java

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
import java.util.List;
55

66
import com.androidmontreal.rhok.board.Board;
7+
import com.androidmontreal.rhok.controllers.BoardController;
78
import com.androidmontreal.rhok.pieces.Piece;
89
import com.androidmontreal.rhok.pieces.Pipe;
910
import com.androidmontreal.rhok.pieces.Pipe.PipeType;
1011
import com.androidmontreal.rhok.pieces.Point;
1112
import com.androidmontreal.rhok.pieces.factory.PipeFactory;
13+
import com.androidmontreal.rhok.renderers.BoardRenderer;
14+
import com.androidmontreal.rhok.renderers.PieceRenderer;
1215
import com.badlogic.gdx.ApplicationListener;
1316
import com.badlogic.gdx.Gdx;
1417
import com.badlogic.gdx.graphics.GL10;
15-
import com.badlogic.gdx.graphics.Texture;
1618
import com.badlogic.gdx.graphics.g2d.Sprite;
1719
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
1820

@@ -27,10 +29,12 @@ public class WaterSupplyGame implements ApplicationListener {
2729

2830
private double steps;
2931

30-
List<Piece> pieces;
32+
private List<Piece> pieces;
3133

3234
private Hashtable<PipeType, Sprite> pipeSprites;
3335
private Board board;
36+
private BoardRenderer boardRenderer;
37+
private BoardController boardController;
3438

3539

3640
@Override
@@ -40,18 +44,19 @@ public void create() {
4044

4145
// pipesTable = new Pipe[TABLE_WIDTH][TABLE_HEIGHT];
4246

43-
board = new Board(TABLE_WIDTH, TABLE_HEIGHT, screenDims);
44-
45-
//initializePipeTypes();
46-
// initializeSomePieces();
47-
47+
board = new Board(TABLE_WIDTH, TABLE_HEIGHT);
48+
boardRenderer = new BoardRenderer();
49+
boardController = new BoardController(board, boardRenderer,screenDims);
4850

51+
// For each new piece.
52+
// new PieceRenderer(p);
4953

54+
// TODO: Remove this I think...
5055
batch = new SpriteBatch();
5156
}
5257

5358
private void initializeSomePieces() {
54-
59+
5560
for (int x = 0; x < TABLE_WIDTH; x++) {
5661

5762
for (int y = 0; y < TABLE_HEIGHT; y++) {
@@ -82,31 +87,36 @@ public void render() {
8287
*/
8388
if(Gdx.input.isTouched()){
8489
System.out.println("Screen is touch at "+Gdx.input.getX()+";"+Gdx.input.getY());
85-
Piece touchedPiece = board.findPiece(Gdx.input.getX(), Gdx.input.getY());
90+
int x = Gdx.input.getX();
91+
int y = Gdx.input.getY();
92+
Piece touchedPiece = boardController.findPiece(x, y);
8693
Point position = touchedPiece.getPosition();
87-
position.getX();
88-
position.getY();
89-
board.addPiece(touchedPiece, Gdx.input.getX(), Gdx.input.getY());
94+
position.setX(x);
95+
position.setY(y);
96+
// position.getY();
97+
boardController.addPiece(touchedPiece, Gdx.input.getX(), Gdx.input.getY());
9098
}
9199

92100

93101

94102
batch.begin();
95-
96-
int spacing = 22;
103+
104+
boardRenderer.render() ;
97105

98-
for (int x = 0; x < TABLE_WIDTH; x++) {
99-
for (int y = 0; y < TABLE_HEIGHT; y++) {
100-
101-
Pipe p = pipesTable[x][y];
102-
103-
int displayX = (x + 1) * spacing;
104-
int displayY = (y + 1) * spacing;
105-
106-
107-
}
108-
}
106+
// int spacing = 22;
109107

108+
// for (int x = 0; x < TABLE_WIDTH; x++) {
109+
// for (int y = 0; y < TABLE_HEIGHT; y++) {
110+
//
111+
// Pipe p = pipesTable[x][y];
112+
//
113+
// int displayX = (x + 1) * spacing;
114+
// int displayY = (y + 1) * spacing;
115+
//
116+
//
117+
// }
118+
// }
119+
//
110120

111121
batch.end();
112122
}

src/com/androidmontreal/rhok/board/Board.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
import com.androidmontreal.rhok.ScreenDims;
76
import com.androidmontreal.rhok.pieces.Direction;
87
import com.androidmontreal.rhok.pieces.DirectionUtil;
98
import com.androidmontreal.rhok.pieces.Piece;
109
import com.androidmontreal.rhok.pieces.Pipe;
11-
import com.androidmontreal.rhok.pieces.Pipe.PipeType;
12-
import com.androidmontreal.rhok.pieces.Point;
1310

1411
public class Board {
1512

@@ -18,8 +15,6 @@ private static void attachPieces(Piece p1, Piece p2, Direction direction)
1815
p1.getGates().get(direction).setAttachedGate(p2.getGates().get(DirectionUtil.getOpposite(direction)));
1916
}
2017

21-
// Physical dims of screen, needed to provide touch services...
22-
private final ScreenDims dims;
2318

2419
// Logical board sizes, in tiles.
2520
int width ;
@@ -34,24 +29,18 @@ private static void attachPieces(Piece p1, Piece p2, Direction direction)
3429

3530
private Pipe mockPipe;
3631

37-
public Board( int width, int height, ScreenDims dims ) {
38-
this.dims = dims;
32+
public Board( int width, int height) {
3933
boardPieces = new Piece[width][height];
4034

41-
// TODO: Remove mock stuff.
42-
mockPipe = new Pipe(PipeType.DOWN_LEFT, new Point(dims.getWidth()/2, dims.getHeight()/2));
4335
pieces.add(mockPipe);
4436
}
4537

46-
public void addPiece(Piece piece, int x, int y){
47-
//TODO implements
48-
}
49-
5038
public void addPiece(Piece piece)
5139
{
5240
this.pieces.add(piece);
5341
this.checkPieceAttachements(piece);
5442
}
43+
5544
private void checkPieceAttachements(Piece currentPiece)
5645
{
5746
for (Piece piece : this.pieces) {
@@ -66,10 +55,6 @@ private void checkPieceAttachements(Piece currentPiece)
6655
}
6756
}
6857

69-
public Piece findPiece( int x, int y ) {
70-
return mockPipe ;
71-
}
72-
7358
public Piece[][] getBoardPieces() {
7459
return boardPieces;
7560
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.androidmontreal.rhok.controllers;
2+
3+
import com.androidmontreal.rhok.ScreenDims;
4+
import com.androidmontreal.rhok.board.Board;
5+
import com.androidmontreal.rhok.pieces.Piece;
6+
import com.androidmontreal.rhok.pieces.Pipe;
7+
import com.androidmontreal.rhok.pieces.Point;
8+
import com.androidmontreal.rhok.pieces.Pipe.PipeType;
9+
import com.androidmontreal.rhok.renderers.BoardRenderer;
10+
import com.androidmontreal.rhok.renderers.PipeRenderer;
11+
12+
public class BoardController {
13+
14+
private final Board board;
15+
private final BoardRenderer renderer;
16+
private Pipe mockPipe;
17+
18+
public BoardController(Board board, BoardRenderer renderer, ScreenDims dims ) {
19+
this.board = board;
20+
this.renderer = renderer;
21+
22+
// TODO: Remove mock stuff.
23+
mockPipe = new Pipe(PipeType.DOWN_LEFT, new Point(dims.getWidth()/2, dims.getHeight()/2));
24+
PipeRenderer pipeRenderer = new PipeRenderer(mockPipe);
25+
this.renderer.addPieceRenderer(pipeRenderer);
26+
27+
}
28+
29+
public void addPiece(Piece piece, int x, int y){
30+
//TODO implements
31+
}
32+
33+
public Piece findPiece( int x, int y ) {
34+
return mockPipe ;
35+
}
36+
37+
38+
}

src/com/androidmontreal/rhok/pieces/Piece.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public interface Piece {
1616
boolean isTicked();
1717
void resetTick();
1818

19-
Sprite getCurrentSprite();
20-
2119
double getWater();
2220
void setWater(double volume);
2321

src/com/androidmontreal/rhok/pieces/Pipe.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
public class Pipe implements Piece {
13-
13+
1414
public enum PipeType{
1515
TOP_LEFT, TOP_RIGHT, DOWN_RIGHT, DOWN_LEFT, HORIZONTAL, VERTICAL, BLANK;
1616
}
@@ -25,9 +25,6 @@ public enum PipeType{
2525
private Boolean ticked;
2626
private double waterContent = 0.0d;
2727

28-
private Sprite sprite;
29-
30-
3128
public Pipe(PipeType type, Point position){
3229
this.type = type;
3330
this.position = position;
@@ -145,13 +142,6 @@ public PipeType getType() {
145142
return type;
146143
}
147144

148-
149-
@Override
150-
public Sprite getCurrentSprite() {
151-
return this.sprite;
152-
}
153-
154-
155145
@Override
156146
public double getWater()
157147
{

src/com/androidmontreal/rhok/pieces/Pump.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package com.androidmontreal.rhok.pieces;
22

3-
import java.util.ArrayList;
43
import java.util.Hashtable;
5-
import java.util.List;
64

75
import com.badlogic.gdx.graphics.g2d.Sprite;
86

97
public class Pump implements Piece {
108

119
private final static double CAPACITY = 25 ;
12-
private final Sprite sprite;
1310

1411
Point point = null ;
1512

@@ -24,10 +21,9 @@ public class Pump implements Piece {
2421
private Direction direction;
2522

2623

27-
public Pump( Direction outputDirection, double pressure, Sprite sprite ) {
24+
public Pump( Direction outputDirection, double pressure ) {
2825

2926
this.direction = outputDirection;
30-
this.sprite = sprite;
3127

3228
switch( outputDirection ) {
3329
case UP :
@@ -90,11 +86,6 @@ public void resetTick() {
9086
ticked = false ;
9187
}
9288

93-
@Override
94-
public Sprite getCurrentSprite() {
95-
return sprite ;
96-
}
97-
9889
@Override
9990
public double getWater() {
10091
return waterContent;

src/com/androidmontreal/rhok/pieces/WaterExit.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public class WaterExit implements Piece {
1414
private Gate gateA;
1515
private Boolean ticked = false;
1616
private Point position;
17-
18-
private Sprite sprite;
19-
17+
2018
public WaterExit() {
2119
}
2220

@@ -68,11 +66,6 @@ public void resetTick() {
6866
this.ticked = false;
6967
}
7068

71-
@Override
72-
public Sprite getCurrentSprite() {
73-
return sprite;
74-
}
75-
7669
@Override
7770
public double getWater() {
7871
return quantity;

src/com/androidmontreal/rhok/pieces/WaterSource.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import java.util.Hashtable;
44

5+
import javax.swing.text.Position;
6+
57
import com.badlogic.gdx.graphics.g2d.Sprite;
68

79
/**
810
* This piece represents a water source where the water needed by the monster village is available.
911
*/
1012
public class WaterSource implements Piece {
11-
12-
private final Sprite sprite;
13-
13+
1414
private double waterContent;
1515

1616
private Gate sourceExit;
@@ -19,9 +19,9 @@ public class WaterSource implements Piece {
1919
private Point position = null ; // DEFAULT
2020

2121

22-
public WaterSource(Sprite sprite ) {
23-
this.sprite = sprite;
24-
this.waterContent = Double.MAX_VALUE ;
22+
public WaterSource(Point p) {
23+
this.position = p;
24+
this.waterContent = Double.MAX_VALUE ;
2525
}
2626

2727
@Override
@@ -55,11 +55,6 @@ public void resetTick() {
5555
this.ticked = false;
5656
}
5757

58-
@Override
59-
public Sprite getCurrentSprite() {
60-
return sprite;
61-
}
62-
6358
@Override
6459
public double getWater() {
6560
return Double.MAX_VALUE ;

src/com/androidmontreal/rhok/pieces/factory/SpriteFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class SpriteFactory {
1818
public static String PUMP_LEFT = "HorizontalPump.png";
1919
public static String PUMP_RIGHT = "HorizontalPump.png";
2020
public static String WATER_SOURCE = "Source.png";
21+
public static String WATER_SOURCE_1 = "water1.png";
22+
public static String WATER_SOURCE_2 = "water2.png";
2123
public static String WATER_EXIT = "Exit.png";
2224
public static String PIPE_TOP_LEFT = "TopLeft.png";
2325
public static String PIPE_TOP_RIGHT = "TopRight.png";
@@ -34,6 +36,8 @@ public class SpriteFactory {
3436
PUMP_LEFT,
3537
PUMP_RIGHT,
3638
WATER_SOURCE,
39+
WATER_SOURCE_1,
40+
WATER_SOURCE_2,
3741
WATER_EXIT,
3842
PIPE_TOP_LEFT,
3943
PIPE_TOP_RIGHT,

0 commit comments

Comments
 (0)