import java.awt.*; import javax.swing.*; import java.awt.event.*; /********************************** This is the main class of a Java program to play a game based on hexagonal tiles. The mechanism of handling hexes is in the file hexmech.java. ***********************************/ public class hexgame { private hexgame() { initGame(); createAndShowGUI(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new hexgame(); } }); } //constants and global variables final static Color COLOURBACK = Color.WHITE; final static Color COLOURCELL = Color.ORANGE; final static Color COLOURGRID = Color.BLACK; final static Color COLOURONE = new Color(255,255,255,200); final static Color COLOURONETXT = Color.BLUE; final static Color COLOURTWO = new Color(0,0,0,200); final static Color COLOURTWOTXT = new Color(255,100,255); final static int EMPTY = 0; final static int BSIZE = 12; //board size. final static int HEXSIZE = 60; //hex size in pixels final static int BORDERS = 15; final static int SCRSIZE = HEXSIZE * (BSIZE + 1) + BORDERS*3; //screen size (vertical dimension). int[][] board = new int[BSIZE][BSIZE]; void initGame(){ hexmech.setXYasVertex(false); //RECOMMENDED: leave this as FALSE. hexmech.setHeight(HEXSIZE); //Either setHeight or setSize must be run to initialize the hex hexmech.setBorders(BORDERS); for (int i=0;i0) hexmech.fillHex(i,j,COLOURTWO, board[i][j],g2); hexmech.fillHex(i,j,board[i][j],g2); } } //g.setColor(Color.RED); //g.drawLine(mPt.x,mPt.y, mPt.x,mPt.y); } class MyMouseListener extends MouseAdapter { //inner class inside DrawingPanel public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); //mPt.x = x; //mPt.y = y; Point p = new Point( hexmech.pxtoHex(e.getX(),e.getY()) ); if (p.x < 0 || p.y < 0 || p.x >= BSIZE || p.y >= BSIZE) return; //DEBUG: colour in the hex which is supposedly the one clicked on //clear the whole screen first. /* for (int i=0;i