changeset 8:d8e7fd8f3ccf

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Jan 2011 22:21:45 +0200
parents 70714c229e23
children a7751971c2a3
files Ristipolku.java
diffstat 1 files changed, 100 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Ristipolku.java	Fri Jan 28 20:23:21 2011 +0200
+++ b/Ristipolku.java	Fri Jan 28 22:21:45 2011 +0200
@@ -15,6 +15,8 @@
 import java.io.*;
 import game.*;
 
+import javax.sound.sampled.*;
+
 
 class PathInfo
 {
@@ -32,6 +34,43 @@
     }
 }
 
+/*
+class AnimatedElement
+{
+    float x, y, stime, value;
+    Interpolate lerp;
+    boolean active;
+    
+    public AnimatedElement(float x, float y, )
+    {
+        stime = 0;
+        this.x = x;
+        this.y = y;
+        
+    }
+    
+    public animate(float time)
+    {
+        if (!active)
+        {
+            active = true;
+            stime = time;
+        }
+        
+        float t = (time - stime) / 10.0f;
+        if (t < 100)
+            value = lerp.getValue(t);
+        else
+        {
+            
+        }
+    }
+    
+    public paint(Graphics2D g, );
+    {
+    }
+}
+*/
 
 class GameBoard
 {
@@ -39,6 +78,7 @@
     public static final int boardMiddle = 4;
     Piece[][] board;
     Piece current;
+    public boolean flagGameOver;
     
     int moveX, moveY, movePoint;
     
@@ -51,6 +91,10 @@
         moveX = boardMiddle;
         moveY = boardMiddle - 1;
         movePoint = 0;
+        
+        
+        
+        flagGameOver = false;
     }
 
     public void paint(Graphics2D g, int sx, int sy, float scale)
@@ -88,10 +132,10 @@
         current.rotate(dir);
     }
 
-    public PathInfo resolvePath(int startX, int startY, int startPoint)
+    public PathInfo resolvePath(int startX, int startY, int startPoint, boolean mark)
     {
         int x = startX, y = startY;
-        int point;
+        int point = -1;
 
         Piece curr = getPiece(startX, startY);
         if (curr == null)
@@ -99,7 +143,8 @@
             
         while (curr != null)
         {
-            
+//            curr.(true);
+//            elements.spawn("", );
         }
         
         return new PathInfo(startPoint, startX, startY, point, x, y);
@@ -110,36 +155,46 @@
         if (current != null)
         {
             current.setType(PieceType.LOCKED);
-            PathInfo i = resolvePath(moveX, moveY, movePoint);
+            PathInfo i = resolvePath(moveX, moveY, movePoint, true);
             
             if (i != null)
             {
-                
             }
         }
 
+        current = new Piece(PieceType.ACTIVE);
         if (isEmpty(moveX, moveY))
         {
-            current = new Piece(PieceType.ACTIVE);
-            lauta.setPiece(moveX, moveY, current);
+            board[moveX][moveY] = current;
+        }
+        else
+        {
+            PathInfo i = resolvePath(moveX, moveY, movePoint, true);
+            if (i != null)
+                board[moveX][moveY] = current;
+            else
+                flagGameOver = true;
         }
    }
 }
 
 
-public class Ristipolku extends JApplet
-                        implements KeyListener
+public class Ristipolku extends JPanel
+                        implements Runnable, KeyListener
 {
+    Thread animThread;
+    boolean animEnable = false;
     GameBoard lauta = null;
     BufferedImage lautaBG = null;
+    float clock;
 
     public void init()
     {
-        getContentPane().setBackground(Color.white);
+        clock = 0;
 
         try
         {
-            lautaBG = ImageIO.read(new File("background.jpg"));
+            lautaBG = ImageIO.read(new File("board.png"));
         }
 
         catch (IOException e)
@@ -150,8 +205,32 @@
                 JOptionPane.ERROR_MESSAGE);
         }
         
+        startThreads();
+        
         lauta = new GameBoard();
         addKeyListener(this);
+        
+        startThreads();
+    }
+
+    public void startThreads()
+    {
+        if (animThread == null)
+        {
+            animThread = new Thread(this);
+            animEnable = true;
+            animThread.start();
+        }
+    }
+    
+    public void stopThreads()
+    {
+        if (animThread != null)
+        {
+            animThread.interrupt();
+            animEnable = false;
+            animThread = null;
+        }
     }
 
     public void paint(Graphics g)
@@ -191,4 +270,14 @@
                 break;
         }
     }
+    
+    public void run()
+    {
+        while (animEnable)
+        {
+            clock++;
+            
+            Thread.sleep(100);
+        }
+    }
 }