/* Copyright 1996 Rujith de Silva. This code is in the public domain. */ package NET.industry.pento; import NET.industry.util.*; public class Piece extends Object { private int init[][] = new int[5][2]; private int dir = 0; private boolean swap = false; protected int current[][] = new int[5][2]; private int xmul[][] = { { 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 } }; private int ymul[][] = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }; public Piece (int init[][]) { for (int i = 0; i < 5; ++i) { for (int j = 0; j < 2; ++j) { this.init[i][j] = init[i][j]; current[i][j] = init[i][j]; } } } public int direction () { return dir; } public void setDirection (int i) { i %= 4; if (dir != i) { dir = i; update (); } } public boolean getSwap () { return swap; } public void setSwap (boolean sw) { if (swap != sw) { swap = sw; update (); } } private void update () { int xm1 = xmul[dir][0]; int xm2 = xmul[dir][1]; int ym1 = ymul[dir][0]; int ym2 = ymul[dir][1]; for (int i = 0; i < 5; ++i) { int i0 = init[i][0]; int i1 = init[i][1]; if (swap) i1 = - i1; current[i][0] = i0 * xm1 + i1 * xm2; current[i][1] = i0 * ym1 + i1 * ym2; } } }