PLEASE COULD YOU HELP ME IN CREATING A DOT GAME IN JAVA?
*******************************************************
THIS IS MY ASSIGNMENT
***************************************************
Design and develop an interactive visual 'stand‐alone' event‐driven Java application implementing the “Dots Game”. This is a two‐player game in which each player clicks in turn on a dot from a matrix of dots on the screen. The total number of dots in the matrix MAY NOT be less than 20. The first player makes a dot red. The second player makes a dot blue. If two adjacent dots are the same colour, a line in that colour is drawn between them. The winning player is the one who has the most lines drawn when all the dots have been clicked.
The application should be provided with a menu that includes menu items that display dialogs so that a player can enter name, age, and gender (only one of two possible genders!) and the player details can be saved in a file.

I have done this so far!!! but still confused even i don know how to do menu?

import java.awt.*;
import java.awt.event.*;

public class FourDots
{
   public static void main( String[ ] args)
   {
      new Dots4Win();
   }
}

class Dots4Win extends Frame
{
   private int counter = 0 ;

   private Rectangle[][] dots = new Rectangle[2][2] ;

   /* 0 denotes black; 1 denotes red;  2 denotes blue */
   private int[][] status = new int[2][2] ;

   Dots4Win()
   {
      setTitle( "Colouring a Dot" );
      setLocation( new Point( 100, 100 ) ) ;
      setSize( 400, 300 );
      setResizable( false ) ;  // this prevents re-sizing of window

      for ( int i = 0; i < 2; i++ )
      {
         for ( int j = 0; j < 2; j++ )
         {
            dots[i][j] = new Rectangle( 150 + 30*i, 130 + 30*j, 20, 20 ) ;
         }
      }

      for ( int i = 0; i < 2; i++ )
      {
         for ( int j = 0; j < 2; j++ )
         {
            status[i][j] = 0 ;
         }
      }

      addMouseListener( new MouseCatcher() ) ;        // register a mouse listener
      addWindowListener( new WindowCatcher( ) );      // register a window listener

      setVisible( true );
   }

   public void paint( Graphics gc )
   {
      for ( int i = 0; i < 2; i++ )
      {
         for ( int j = 0; j < 2; j++ )
         {
            if ( status[i][j] == 0 ) 
            {
               gc.setColor( Color.black ) ;
            }
            else if ( status[i][j] == 1 )
            {
               gc.setColor(Color.red ) ;
            }
            else
            {
               gc.setColor( Color.blue ) ;
            }
            gc.fillOval( dots[i][j].x, dots[i][j].y, dots[i][j].width, dots[i][j].height ) ; 
         }
      }
   } 

   class MouseCatcher extends MouseAdapter
   {
      public void mousePressed(MouseEvent evt )
      {
         Point ptMouse = evt.getPoint() ;

         for ( int i = 0; i < 2; i++ )
         {
            for ( int j = 0; j < 2; j++ )
            {
               if ( dots[i][j].contains( ptMouse ) && (status[i][j] == 0) )   // check you're on a black dot
               {
                  if ( counter % 2 == 0 )
                  {
                     status[i][j] = 1 ;
                  }
                  else
                  {
                     status[i][j] = 2 ;
                  }
                  counter++ ;
                  repaint();
               }
            }
         }
      } 
   } 

   class WindowCatcher extends WindowAdapter
   {
      public void windowClosing( WindowEvent evt )
      {
         evt.getWindow( ).dispose( );                // releases this window's resources
         System.exit( 0 );
      } 
   }
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.