1)create a 6x6 grid.
2)ask the user to choose from 6 colours to fill a square (i have written an enum and had them declared already- see below)
3)test to see if one row or column has 5 colours in and autocomplete with the final colour. also it should not allow the user to click on any squares in that row or column if it is complete.
4) if a square has already been filled in and gets clicked again it should go back to blank/empty colour.
5) if a square is going to be coloured the same as one already in that row/column the square should be left blank and an error message displayed saying why and allowing the user to try again
the starting pattern is to be read in from a file i.e.
R1 C2 Green
where R1 is 1st row and C2 is second column.
the file reading seems ok but i have no idea where to go from there. i have a little bit of code which is below
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class ColourInfo extends JButton {
private static int emptySquares=0;
public static final Color red;
public static final Color yellow;
public static final Color green;
public static final Color blue;
public final Color purple = new Color( 128, 0, 128);
public final Color brown = new Color(139,69,19);
static enum Colours {RED, BLUE, GREEN, YELLOW, PURPLE, BROWN}
private Colours colour = null;
private void setColour(Colours c){
colour = c;
}
}
here is the main class where the game will be created etc
import assignmentv2.ColourInfo;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class ColourGame extends JFrame{
public final int SIZE = 6;
//An array of buttons which can be searched for wins
private ColourInfo [][] cinfo;
//The constructor
public ColourGame() {
// Initializes the various components
// Could be a separate method called initComponents()
//Set up the frame details
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setTitle("COM162 Assignment 1 Student ID 100157842");
setLocationRelativeTo(null);
setLayout(new GridLayout(SIZE,SIZE));
//Creates space to store the arry of buttons
cinfo = new ColourInfo [SIZE][SIZE];
for (int row = 0; row < SIZE; row++)
for (int column = 0; column < SIZE; column++) {
cinfo[row][column] = new ColourInfo(this, row, column);
add(cinfo[row][column]);
}
// Finish the frame
pack();
}
}

New Topic/Question
Reply



MultiQuote







|