changeset 27:26adc2827983

More work on the internals.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 01 Feb 2011 20:38:19 +0200
parents 3d4cc47df31a
children 2185f274d08a
files Makefile game/Engine.java game/Piece.java
diffstat 3 files changed, 73 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Feb 01 19:18:25 2011 +0200
+++ b/Makefile	Tue Feb 01 20:38:19 2011 +0200
@@ -3,7 +3,10 @@
 
 RESOURCES=graphics/*.png graphics/*.jpg graphics/font.ttf sounds/*.wav
 
-CLASSES=game/Piece.class game/PieceType.class game/Engine.class game/Interpolate.class game/ResourceLoader.class
+CLASSES=game/Piece.class game/PieceType.class \
+	game/Engine.class game/Interpolate.class \
+	game/ResourceLoader.class game/Sound.class \
+	game/SoundElement.class
 
 # Utils
 JAVAC=javac -g
@@ -30,8 +33,8 @@
 ###
 ### Package
 ###
-Ristipolku.jar: $(RUN) $(CLASSES) $(RESOURCES)
-	jar cvfm $@ manifest.txt $+
+Ristipolku.jar: $(RUN) $(RESOURCES)
+	jar cvfm $@ manifest.txt $+ game/*.class
 
 
 upload: Ristipolku.jar
--- a/game/Engine.java	Tue Feb 01 19:18:25 2011 +0200
+++ b/game/Engine.java	Tue Feb 01 20:38:19 2011 +0200
@@ -31,6 +31,12 @@
         this.outX = outX;
         this.outY = outY;
     }
+    
+    public void print()
+    {
+        System.out.print("PathInfo: inP="+in+", inX="+inX+", inY="+inY+"\n");
+        System.out.print("          outP="+out+", outX="+outX+", outY="+outY+"\n");
+    }
 }
 
 /*
@@ -129,14 +135,6 @@
         return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null);
     }
 
-    private Piece getPiece(int x, int y)
-    {
-        if (x >= 0 && x < boardSize && y >= 0 && y < boardSize)
-            return board[x][y];
-        else
-            return null;
-    }
-
     public void pieceRotate(boolean dir)
     {
         if (current != null)
@@ -146,20 +144,54 @@
     public PathInfo resolvePath(int startX, int startY, int startPoint, boolean mark)
     {
         int x = startX, y = startY;
-        int point = -1;
-
-        Piece curr = getPiece(startX, startY);
-        if (curr == null)
-            return null;
+        int point = startPoint;
+        Piece curr = board[x][y];
 
-/*            
-        while (curr != null)
+        do
         {
-//            curr.(true);
-//            elements.spawn("", );
+            if (x >= 0 && x < boardSize && y >= 0 && y < boardSize)
+            {
+                curr = board[x][y];
+                if (curr == null)
+                    break;
+                
+                if (curr.getType() == PieceType.START)
+                {
+                    // Hit center starting piece
+                    return null;
+                }
+                else
+                {
+                    // Mark, if needed
+                    if (mark)
+                    {
+                        curr.setType(PieceType.LOCKED);
+                        curr.setActiveConnection(point);
+                    }
+                    
+                    // Get next piece
+                    point = curr.getConnection(point);
+                    switch (point)
+                    {
+                        case 0: y--; break;
+                        case 1: y--; break;
+                        case 2: x++; break;
+                        case 3: x++; break;
+                        case 4: y++; break;
+                        case 5: y++; break;
+                        case 6: x--; break;
+                        case 7: x--; break;
+                    }
+                }
+            }
+            else
+            {
+                // Outside of the board
+                return null;
+            }
         }
-*/
-      
+        while (curr != null);
+        
         return new PathInfo(startPoint, startX, startY, point, x, y);
     }
 
@@ -172,6 +204,11 @@
             
             if (i != null)
             {
+                System.out.print("moveX="+moveX+", moveY="+moveY+", movePoint="+movePoint+"\n");
+                i.print();
+                moveX = i.outX;
+                moveY = i.outY;
+                movePoint = i.out;
             }
         }
 
@@ -186,7 +223,10 @@
             if (i != null)
                 board[moveX][moveY] = current;
             else
+            {
+                System.out.print("pieceFinishTurn(): Game Over!\n");
                 flagGameOver = true;
+            }
         }
    }
 }
--- a/game/Piece.java	Tue Feb 01 19:18:25 2011 +0200
+++ b/game/Piece.java	Tue Feb 01 20:38:19 2011 +0200
@@ -122,6 +122,11 @@
         active[index] = true;
         activeChanged = true;
     }
+    
+    public PieceType getType()
+    {
+        return type;
+    }
 
     public void animate(float time)
     {
@@ -192,7 +197,6 @@
             g.draw(new RoundRectangle2D.Float(x - offs1, y - offs1, dim + offs2, dim + offs2, dim / 10, dim / 10));
         }
 
-        g.setPaint(Color.black);
         g.setStroke(new BasicStroke(6.0f));
 //      CubicCurve2D c = new CubicCurve2D.Float();
         QuadCurve2D c = new QuadCurve2D.Float();
@@ -201,6 +205,9 @@
         if (!drawn[i])
         {
             Point2D start, cp1, cp2, end;
+
+            boolean act = active[i] || active[connections[i]];
+            g.setPaint(act ? Color.white : Color.black);
             
             start = getPointCoords(x, y, dim, i);
             end   = getPointCoords(x, y, dim, connections[i]);