changeset 2:1785f66a7beb

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Jan 2011 16:53:06 +0200
parents 44f1e7b47fcf
children b8fd19e2d879
files Makefile Ristipolku.java game/Piece.java game/PieceType.java
diffstat 4 files changed, 99 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Jan 28 16:34:53 2011 +0200
+++ b/Makefile	Fri Jan 28 16:53:06 2011 +0200
@@ -1,5 +1,5 @@
 # Settings, directories
-RUN=gfxtest.class
+RUN=Ristipolku.class
 TARGETS=$(RUN)
 SUBDIR=game
 
@@ -12,7 +12,7 @@
 ###
 all: $(TARGETS)
 
-gfxtest.class: game/Piece.class game/PieceType.class
+#Ristipolku.class: game/Piece.class game/PieceType.class $(SUBDI
 
 %.class: %.java
 	$(JAVAC) $<
--- a/Ristipolku.java	Fri Jan 28 16:34:53 2011 +0200
+++ b/Ristipolku.java	Fri Jan 28 16:53:06 2011 +0200
@@ -2,7 +2,7 @@
  * Ristipolku
  * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
  *
- * Ohjelmointiprojekti Java-kurssille.
+ * Ohjelmointiprojekti Java-kurssille .
  */
 import java.awt.*;
 import java.awt.geom.*;
@@ -11,80 +11,83 @@
 import java.util.*;
 import game.*;
 
+
 class PathInfo
 {
-   public int in, inX, inY, out, outX, outY; 
+    public int in, inX, inY, out, outX, outY; 
    
-   public PathInfo(in, inX, inY, out, outX, outY)
-   {
-      this.in = in;
-      this.inX = inX;
-      this.inY = inY;
-      
-      this.out = out;
-      this.outX = outX;
-      this.outY = outY;
-   }
+    public PathInfo(int in, int inX, int inY, int out, int outX, int outY)
+    {
+        this.in = in;
+        this.inX = inX;
+        this.inY = inY;
+
+        this.out = out;
+        this.outX = outX;
+        this.outY = outY;
+    }
 }
 
 
 class GameBoard
 {
-   public static final int boardSize = 9;
-   public static final int boardMiddle = 4;
-   Piece[][] board;
-   Piece current;
+    public static final int boardSize = 9;
+    public static final int boardMiddle = 4;
+    Piece[][] board;
+    Piece current;
    
-   public GameBoard()
-   {
-      board = new Piece[boardSize][boardSize];
-      board[boardMiddle][boardMiddle] = new Piece(PieceType.START);
-      moveX = boardMiddle;
-      moveY = boardMiddle - 1;
-      
-      
-   }
+    public GameBoard()
+    {
+        board = new Piece[boardSize][boardSize];
+
+        board[boardMiddle][boardMiddle] = new Piece(PieceType.START);
+
+        moveX = boardMiddle;
+        moveY = boardMiddle - 1;
+    }
 
-   public void paint(Graphics2D g, int sx, int sy, double scale)
-   {
-      for (int y = 0; y < boardSize; y++)
-      for (int x = 0; x < boardSize; x++)
-      {
-         if (board[x][y] != null)
+    public void paint(Graphics2D g, int sx, int sy, double scale)
+    {
+        for (int y = 0; y < boardSize; y++)
+        for (int x = 0; x < boardSize; x++)
+        if (board[x][y] != null)
+        {
             board[x][y].paint(g, sx + (x * scale), sy + (y * scale), scale - scale/10);
-      }
-   }
+        }
+    }
    
-   private boolean isEmpty(int x, int y)
-   {
-       return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null);
-   }
+    private boolean isEmpty(int x, int y)
+    {
+        return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null);
+    }
 
-   private Piece getPiece(int x, int y)
-   {
-       return board[x][y];
-   }
-   
-   public Point resolvePath(int x, int y, int inpoint)
-   {
-   }
+    private Piece getPiece(int x, int y)
+    {
+        if (x >= 0 && x < boardSize && y >= 0 && y < boardSize)
+            return board[x][y];
+        else
+            return null;
+    }
    
-   public pieceRotate(boolean dir)
-   {
-      current.rotate(dir);
-   }
+    public Point resolvePath(int x, int y, int inpoint)
+    {
+    }
+   
+    public void pieceRotate(boolean dir)
+    {
+        current.rotate(dir);
+    }
 
-   public void pieceFinishTurn()
-   {
-      if (current != null)
-         current.setType(PieceType.NORMAL);
+    public void pieceFinishTurn()
+    {
+        if (current != null)
+            current.setType(PieceType.NORMAL);
       
-      if (isEmpty(cx, cy))
-      {
-         current = new Piece(PieceType.ACTIVE);
-         lauta.setPiece(cx, cy, current);
-      }
-      
+        if (isEmpty(cx, cy))
+        {
+            current = new Piece(PieceType.ACTIVE);
+            lauta.setPiece(cx, cy, current);
+        }
    }
 }
 
@@ -92,72 +95,49 @@
 public class gfxtest extends JApplet
                      implements KeyListener
 {
-   GameBoard lauta;
-
-   public void init()
-   {
-      getContentPane().setBackground(Color.white);
-      
-      lauta = new GameBoard();
-
-      addKeyListener(this);
-   }
-
+    GameBoard lauta;
 
-/*
-    public Graphics2D createGraphics2D(Dimension d) {
-        Graphics2D g2 = null;
+    public void init()
+    {
+        getContentPane().setBackground(Color.white);
+        lauta = new GameBoard();
+        addKeyListener(this);
+    }
 
-        if (bimg == null || bimg.getWidth() != d.w || bimg.getHeight() != d.h) {
-            bimg = (BufferedImage) createImage(d.w, d.h);
-            reset(d);
-        } 
-
-        g2 = bimg.createGraphics();
-        g2.setBackground(getBackground());
-        g2.clearRect(0, 0, w, h);
+    public void paint(Graphics g)
+    {
+        Graphics2D g2 = (Graphics2D) g;
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
-        return g2;
+        lauta.paint(g2, 15, 15, 60);
     }
-*/
-
-   public void paint(Graphics g)
-   {
-      Graphics2D g2 = (Graphics2D) g;
-
-      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-                          RenderingHints.VALUE_ANTIALIAS_ON);
-
-      lauta.paint(g2, 15, 15, 60);
-   }
 
 
-   public void keyPressed(KeyEvent e)
-   {
-   }
+    public void keyPressed(KeyEvent e)
+    {
+    }
    
-   public void keyReleased(KeyEvent e)
-   {
-   }
+    public void keyReleased(KeyEvent e)
+    {
+    }
    
-   public void keyTyped(KeyEvent e)
-   {
-      switch (event.getKeyCode())
-      {
-         case VK_LEFT:
-         case VK_UP:
-            moveRotate(false);
-            break;
+    public void keyTyped(KeyEvent e)
+    {
+        switch (event.getKeyCode())
+        {
+            case VK_LEFT:
+            case VK_UP:
+                lauta.pieceRotate(false);
+                break;
 
-         case VK_RIGHT:
-         case VK_DOWN:
-            moveRotate(true);
-            break;
-         
-         case VK_ENTER:
-            moveNew();
-            break;
-      }
-   }
+            case VK_RIGHT:
+            case VK_DOWN:
+                lauta.pieceRotate(true);
+                break;
+
+            case VK_ENTER:
+                lauta.pieceFinishTurn();
+                break;
+        }
+    }
 }
--- a/game/Piece.java	Fri Jan 28 16:34:53 2011 +0200
+++ b/game/Piece.java	Fri Jan 28 16:53:06 2011 +0200
@@ -1,8 +1,6 @@
 /*
  * Ristipolku
  * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
- *
- * Ohjelmointiprojekti Java-kurssille.
  */
 package game;
 
--- a/game/PieceType.java	Fri Jan 28 16:34:53 2011 +0200
+++ b/game/PieceType.java	Fri Jan 28 16:53:06 2011 +0200
@@ -1,8 +1,6 @@
 /*
  * Ristipolku
  * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
- *
- * Ohjelmointiprojekti Java-kurssille.
  */
 package game;