public class Psycho{ private static final int STEP_MODE = 0; private static final int TURN_MODE = 1; private static final int SEQUENCE_MODE = 2; private int mode; private int direc; private int currSquareIndex; private color col; private ArrayList moveTrail; private Sequence sequence; private Grid grid; private int pathCount;//for moving one whole sequence at a time private int currTurn;//for moving one turn at a time private int currStep; //for moving single steps public Psycho(int startIndex, color psychoCol, Sequence s, Grid g, int m) { currSquareIndex = startIndex; direc = (int)random(4); col = psychoCol; sequence = s; grid = g; mode = m; pathCount=0; currTurn = 0; currStep = 0; } public void update() { setWildcard( (int)random(5)+1); if (mode == STEP_MODE) { moveSingleStep(); } else if (mode == TURN_MODE) { moveSingleTurn(); } else if (mode == SEQUENCE_MODE) { moveWholeSequence(); } else { println("Psycho - no mode"); } } public void moveSingleStep() { moveTrail = new ArrayList(); moveTrail.add(pathCount, new Integer(currSquareIndex)); pathCount++; Turn turn = sequence.getTurn(currTurn); int turnstep_tot = turn.getNumMoves(); //println("Psycho turnstep_tot: " + turnstep_tot); if (currStep < turnstep_tot) { moveOne(); currStep++; } else { if (currTurn < sequence.getTotalTurns()-1) { currTurn++; //println("incrementing current turn: "+ currTurn); }else { currTurn = 0; } currStep=0; boolean left = turn.getLeftTurn(); direc = grid.setDirection(direc, left); moveOne(); } Integer[] path = new Integer[moveTrail.size()]; moveTrail.toArray(path); grid.drawPath(path, col); pathCount=0; } public void moveSingleTurn() { moveTrail = new ArrayList(); moveTrail.add(pathCount, new Integer(currSquareIndex)); pathCount++; Turn turn = sequence.getTurn(currTurn); int turnstep_tot = turn.getNumMoves(); for (int i = 0; i < turnstep_tot; i++) { moveOne(); } boolean left = turn.getLeftTurn(); direc = grid.setDirection(direc, left); moveOne(); Integer[] path = new Integer[moveTrail.size()]; moveTrail.toArray(path); grid.drawPath(path, col); pathCount=0; if (currTurn < (sequence.getTotalTurns()-1)) { //println("incrementing current turn: "+ currTurn); currTurn++; }else { currTurn=0; } } public void moveWholeSequence() { //create array list of moves moveTrail = new ArrayList(); moveTrail.add(pathCount, new Integer(currSquareIndex)); pathCount++; //iterate through sequence of turns int seq_tot = sequence.getTotalTurns(); for (int i = 0; i < seq_tot; i++) { Turn turn = sequence.getTurn(i); int num_moves = turn.getNumMoves(); for (int j = 0; j < num_moves; j++) { moveOne(); } boolean left = turn.getLeftTurn(); direc = grid.setDirection(direc, left); moveOne(); } //convert arrayList back to an array Integer[] path = new Integer[moveTrail.size()]; moveTrail.toArray(path); grid.drawPath(path, col); pathCount=0; } private void moveOne() { currSquareIndex = grid.move(currSquareIndex, direc); moveTrail.add(pathCount, new Integer(currSquareIndex)); pathCount++; grid.getMove(currSquareIndex, this); } public void setSequence(Sequence s) { sequence = s; currTurn = 0; //currStep = 2; } public Sequence getSequence() { return sequence; } public void setRandomColor() { col = color((int)random(100)+140, (int)random(100)+140, (int)random(250)); } public void setWildcard(int wild) { //println("wild: " + wild); Turn wildy = sequence.getTurn(wild); int tot = wildy.getNumMoves(); //println ("tot: " + tot); int ran = (int)random(wildy.getOriginalNumMoves()); //println("Psycho random wildcard: " + ran); wildy.setNumMoves(ran); } public int getWildcard() { int wildTurn = sequence.getWildTurn(); return sequence.getTurn(wildTurn).getNumMoves(); } }