org/homelinux/largo/games/board/Board.java
changeset 15 d4b2b9a87d80
parent 14 f12f77aa13b2
child 16 55b0d5006e7b
equal deleted inserted replaced
14:f12f77aa13b2 15:d4b2b9a87d80
     7 
     7 
     8 import java.awt.Color;
     8 import java.awt.Color;
     9 import java.awt.Dimension;
     9 import java.awt.Dimension;
    10 import java.awt.Graphics;
    10 import java.awt.Graphics;
    11 import java.awt.Image;
    11 import java.awt.Image;
    12 import java.util.Vector;
    12 import java.util.ArrayList;
    13 
    13 
    14 import javax.swing.JPanel;
    14 import javax.swing.JPanel;
    15 
    15 
    16 public class Board extends JPanel {
    16 public class Board extends JPanel {
    17     static final long serialVersionUID = 1L;
    17     static final long serialVersionUID = 1L;
    19     protected boolean UNDO_DEBUG = false;
    19     protected boolean UNDO_DEBUG = false;
    20 
    20 
    21     protected Piece board_pieces[];
    21     protected Piece board_pieces[];
    22     private Piece pieces[];
    22     private Piece pieces[];
    23 
    23 
    24     protected Vector<History> stack;
    24     protected ArrayList<History> stack;
    25     protected int moveNr;
    25     protected int moveNr;
    26 
    26 
    27     protected static final int EMPTY = 0;
    27     protected static final int EMPTY = 0;
    28 
    28 
    29     Color color_black;
    29     Color color_black;
    54         yPos = 0;
    54         yPos = 0;
    55 
    55 
    56         black = false;
    56         black = false;
    57         blacksTurn = false;
    57         blacksTurn = false;
    58         board_pieces = getPieces(pieces);
    58         board_pieces = getPieces(pieces);
    59         stack = new Vector<History>();
    59         stack = new ArrayList<History>();
    60         moveNr = 0;
    60         moveNr = 0;
    61     }
    61     }
    62 
    62 
    63     public Board(int w, int h) {
    63     public Board(int w, int h) {
    64         iWidth = w;
    64         iWidth = w;
   284         if (moveNr < 2)
   284         if (moveNr < 2)
   285             return;
   285             return;
   286 
   286 
   287         moveNr -= 2;
   287         moveNr -= 2;
   288 
   288 
   289         h1 = stack.elementAt(moveNr);
   289         h1 = stack.get(moveNr);
   290         h2 = stack.elementAt(moveNr + 1);
   290         h2 = stack.get(moveNr + 1);
   291 
   291 
   292         board_pieces[h1.pos] = h1.piece;
   292         board_pieces[h1.pos] = h1.piece;
   293         board_pieces[h2.pos] = h2.piece;
   293         board_pieces[h2.pos] = h2.piece;
   294 
   294 
   295         repaint();
   295         repaint();
   303         History h2;
   303         History h2;
   304 
   304 
   305         if (moveNr > stack.size() - 2)
   305         if (moveNr > stack.size() - 2)
   306             return;
   306             return;
   307 
   307 
   308         h1 = stack.elementAt(moveNr);
   308         h1 = stack.get(moveNr);
   309         h2 = stack.elementAt(moveNr + 1);
   309         h2 = stack.get(moveNr + 1);
   310 
   310 
   311         board_pieces[h1.pos] = h2.piece;
   311         board_pieces[h1.pos] = h2.piece;
   312         board_pieces[h2.pos] = new Piece(null, null, EMPTY, 0);
   312         board_pieces[h2.pos] = new Piece(null, null, EMPTY, 0);
   313 
   313 
   314         moveNr += 2;
   314         moveNr += 2;
   332         int size = stack.size();
   332         int size = stack.size();
   333 
   333 
   334         if (size < 2)
   334         if (size < 2)
   335             return;
   335             return;
   336 
   336 
   337         h1 = stack.elementAt(size - 1);
   337         h1 = stack.remove(size - 1);
   338         h2 = stack.elementAt(size - 2);
   338         h2 = stack.remove(size - 2);
   339 
   339 
   340         pieces[h1.pos] = h1.piece;
   340         pieces[h1.pos] = h1.piece;
   341         pieces[h2.pos] = h2.piece;
   341         pieces[h2.pos] = h2.piece;
   342 
       
   343         stack.setSize(size - 2);
       
   344 
   342 
   345         /* Reset the current player */
   343         /* Reset the current player */
   346         setBlacksTurn(h2.turn);
   344         setBlacksTurn(h2.turn);
   347     }
   345     }
   348 
   346