import java.applet.Applet; import java.awt.*; //=========================================== public class CatchFox extends Applet { public static int DIMENSION=10; //Warning! Dimension cannot be more than 10; // Otherwise pnlForest.action and pnlForest.FindIndexes will not work. public static int FOXQNTTY=5; public static int FOX=FOXQNTTY+1; public static int Forest[][]=new int[DIMENSION][DIMENSION]; static PanelMonitor pnlMonitor; static PanelControl pnlControl; static PanelForest pnlForest; // static PanelM pnlM; public static int StepCounter; public static int CaughtFoxesCounter; //---------------------------- public void init() { setLayout(new BorderLayout()); setBackground(Color.gray); add("North", pnlMonitor=new PanelMonitor()); add("South",pnlControl=new PanelControl()); add("Center", pnlForest=new PanelForest()); add("West", new Panel()); add("East", new Panel()); } //---------------------------- public void start() { StartNewGame(); repaint(); } //---------------------------- public void update(Graphics g) { paint(g); } //---------------------------- public void paint(Graphics g) { /* for(int i=0;i=0) // RedrawForestCell(Column,Row); // } //---------------------------- private static void DropFoxes() { int Position; try { Position=(int)Math.abs(DIMENSION*DIMENSION*(Math.random()-0.0001)); if(Forest[Position/DIMENSION][Position%DIMENSION]>0) DropFoxes(); else Forest[Position/DIMENSION][Position%DIMENSION]=FOX; } catch(ArrayIndexOutOfBoundsException e){DropFoxes();} // very crazy recursion } //---------------------------- public static void IncreaseStep() { StepCounter++; pnlMonitor.lblStep.setText(Integer.toString(StepCounter)); } //---------------------------- public static void DecreaseFoxCounter() { CaughtFoxesCounter--; pnlMonitor.lblCaughtFoxes.setText(Integer.toString(CaughtFoxesCounter)); if(CaughtFoxesCounter==0) Congratulations(); } //---------------------------- private static void Congratulations() { int i,j; pnlControl.FinishedFlag=true; Font Temp=new Font(pnlForest.getFont().getName(),(Font.BOLD),pnlForest.getFont().getSize()); for(i=0;iColumn) j=Row-Column; else i=Column-Row; while((i=0)&&(j>=0)) { if(CatchFox.Forest[i][j]==CatchFox.FOX) Foxes++; i++; j++; } return Foxes; } //----------------------------- private int UNIXDiagonalFoxes(int Column,int Row) { int Foxes=0; int i=Column; int j=Row; while((i>=0)&&(j=0)) { if(CatchFox.Forest[i][j]==CatchFox.FOX) Foxes++; i++; j--; } return Foxes; } //----------------------------- private void CaughtFox(int Column, int Row) { btnForest[Column][Row].setForeground(Color.red); btnForest[Column][Row].setLabel("Fox"); } //----------------------------- } //=========================================== class PanelMonitor extends Panel { public Label lblStep; public Label lblCaughtFoxes; //----------------------------- public PanelMonitor() { add(new Label("Step:")); add(lblStep=new Label("0")); add(new Label(" ")); add(new Label("Hidden Foxes:")); add(lblCaughtFoxes=new Label(Integer.toString(CatchFox.FOXQNTTY))); } //----------------------------- } //=========================================== class PanelControl extends Panel { private static Button btnNewGame; public static Button btnMarkSure; public static boolean MarkFlag=false; public static boolean FinishedFlag=false; //----------------------------- public PanelControl() { add(btnNewGame=new Button("New Game")); add(btnMarkSure=new Button("Mark/Unmark Empty Cells")); } //----------------------------- public boolean action(Event e, Object o) { if(e.target.equals(btnNewGame)) { CatchFox.StartNewGame(); } else if (e.target.equals(btnMarkSure)) { if(!FinishedFlag) { if(!MarkFlag){ Graphics g=btnMarkSure.getGraphics(); g.setColor(Color.red); g.fillRoundRect(5,5,4,4,4,4); btnMarkSure.setLabel("Stop Marking"); } else btnMarkSure.setLabel("Mark/Unmark Empty Cells"); MarkFlag=!MarkFlag; } } return true; } //----------------------------- } //=========================================== /* class PanelM extends Panel { static public Label lblM1; static public Label lblM2; static public Label lblM3; static public Label lblM4; public PanelM() { setLayout(new GridLayout(4,1)); add(lblM1=new Label("1000")); add(lblM2=new Label("1000")); add(lblM3=new Label("1000")); add(lblM4=new Label("1000")); } } */ //===========================================