Question
FloodIt Game Java I have attached a URL with the instructions of what to do and I have attached all of my classes http://www.site.uottawa.ca/~gvj/Courses/ITI1121/assignments/04/index.pdf DOTBUTTON.JAVA
FloodIt Game Java
I have attached a URL with the instructions of what to do and I have attached all of my classes
http://www.site.uottawa.ca/~gvj/Courses/ITI1121/assignments/04/index.pdf
DOTBUTTON.JAVA
import javax.swing.*; import java.awt.*;
public class DotButton extends JButton { private ImageIcon greyM; private ImageIcon orangeM; private ImageIcon blueM; private ImageIcon greenM; private ImageIcon purpleM; private ImageIcon redM; private ImageIcon greyS; private ImageIcon orangeS; private ImageIcon blueS; private ImageIcon greenS; private ImageIcon purpleS; private ImageIcon redS; private ImageIcon greyL; private ImageIcon orangeL; private ImageIcon blueL; private ImageIcon greenL; private ImageIcon purpleL; private ImageIcon redL; private int row; private int column; private int color; private final int iconSize; public DotButton(int row, int column, int color, int iconSize) { this.row = row; this.column = column; this.color = color; this.iconSize = iconSize; if (iconSize == 0) { this.setPreferredSize(new Dimension(11, 11)); if (color == 0) { greyS = new ImageIcon("data/S/ball-0.png"); setIcon(greyS); }else if (color == 1) { orangeS = new ImageIcon("data/S/ball-1.png"); setIcon(orangeS); }else if (color == 2) { blueS = new ImageIcon("data/S/ball-2.png"); setIcon(blueS); }else if (color == 3) { greenS = new ImageIcon("data/S/ball-3.png"); setIcon(greenS); }else if (color == 4) { purpleS = new ImageIcon("data/S/ball-4.png"); setIcon(purpleS); }else if (color == 5) { redS = new ImageIcon("data/S/ball-5.png"); setIcon(redS);} }else if (iconSize == 1){ this.setPreferredSize(new Dimension(28, 28)); if (color == 0) { greyM = new ImageIcon("data/M/ball-0.png"); setIcon(greyM); }else if (color == 1) { orangeM = new ImageIcon("data/M/ball-1.png"); setIcon(orangeM); }else if (color == 2) { blueM = new ImageIcon("data/M/ball-2.png"); setIcon(blueM); }else if (color == 3) { greenM = new ImageIcon("data/M/ball-3.png"); setIcon(greenM); }else if (color == 4) { purpleM = new ImageIcon("data/M/ball-4.png"); setIcon(purpleM); }else if (color == 5) { redM = new ImageIcon("data/M/ball-5.png"); setIcon(redM); } } setOpaque(true); setBorderPainted(false); setFocusPainted(false); setContentAreaFilled(false); setBackground(Color.WHITE); }public DotButton(int color, int iconSize) { this.color = color; this.iconSize = iconSize; this.setPreferredSize(new Dimension(40, 40)); if (color == 0) { greyL = new ImageIcon("data/L/ball-0.png"); setIcon(greyL); setActionCommand("0"); }else if (color == 1) { orangeL = new ImageIcon("data/L/ball-1.png"); setIcon(orangeL); setActionCommand("1"); }else if (color == 2) { blueL = new ImageIcon("data/L/ball-2.png"); setIcon(blueL); setActionCommand("2"); }else if (color == 3) { greenL = new ImageIcon("data/L/ball-3.png"); setIcon(greenL); setActionCommand("3"); }else if (color == 4) { purpleL = new ImageIcon("data/L/ball-4.png"); setIcon(purpleL); setActionCommand("4"); }else if (color == 5) { redL = new ImageIcon("data/L/ball-5.png"); setIcon(redL); setActionCommand("5"); } setContentAreaFilled(false); setBackground(Color.WHITE); setOpaque(true); setBorderPainted(false); }public void setColor(int color) { this.color = color; }public int getColor() { return color; }public int getRow() { return row; }public int getColumn() { return column; } }
DOTINFO.JAVA
public class DotInfo { private final int x; private final int y; protected int color; private boolean captured; public DotInfo(int x, int y, int color) { this.x = x; this.y = y; this.color = color; }public int getX() { return x; }public int getY() { return y; }public boolean isCaptured() { return captured; }public void setCaptured(boolean captured) { this.captured = captured; }public int getColor() { return color; } }
FLOODIT.JAVA
public class FloodIt { public static void main(String[] args) { StudentInfo.display(); if (args.length > 0) { if (Integer.parseInt(args[0]) < 10) { GameController controller = new GameController(12); } else { GameController controller = new GameController(Integer.parseInt(args[0])); } } else { GameController controller = new GameController(12); } } }
GAMECONTROLLER.JAVA
import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import static javax.swing.JOptionPane.NO_OPTION; import static javax.swing.JOptionPane.YES_OPTION; public class GameController implements ActionListener, Stack
GAMEMODEL.JAVA
import java.util.*; public class GameModel { public static final int COLOR_0 = 0; public static final int COLOR_1 = 1; public static final int COLOR_2 = 2; public static final int COLOR_3 = 3; public static final int COLOR_4 = 4; public static final int COLOR_5 = 5; public static final int NUMBER_OF_COLORS = 6; final Random random; final int size; int numberOfSteps; int currentSelectedColor; final DotInfo[][] board;
public GameModel(int size) { this.size = size; random = new Random(); board = new DotInfo[size][size]; reset(); }public int getSize() { return size; }public int getColor(int i, int j) { return board[i][j].getColor(); }public boolean isCaptured(int i, int j) { return board[i][j].isCaptured(); }public void capture(int i, int j) { board[i][j].setCaptured(true); }public int getNumberOfSteps() { return numberOfSteps; }public void reset() { numberOfSteps = 0; currentSelectedColor = -1; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { board[i][j] = new DotInfo(i, j, random.nextInt(NUMBER_OF_COLORS)); board[i][j].setCaptured(false); } } board[0][0].setCaptured(true); }public int getCurrentSelectedColor() { return currentSelectedColor; }public void setCurrentSelectedColor(int val) { currentSelectedColor = val; }public void step() { numberOfSteps++; }public DotInfo get(int i, int j) { return board[i][j]; }public boolean isFinished() { for (int i = 0; i < size; i++) { for (int j = 0; j < size - 1; j++) { if (board[i][j].getColor() != board[i][j + 1].getColor()) { return false; } } }return true; }public String toString() { String captured = ""; String color = ""; for (int i = 0; i < board.length; i++) { for (int j = 0; j < board.length; j++) { captured += isCaptured(i, j) + " "; color += getColor(i, j) + " "; if (j == board.length - 1) { captured += " "; color += " "; } } }return color; } }
GAMEVIEW.JAVA
import javax.swing.*; import java.awt.*;
public class GameView extends JFrame {
private final GameModel model; private final GameController gameController; private final JButton reset; private final JButton quit; private final JPanel boardPanel; private final JPanel colorSelectionPanel; private final JPanel controlPanel; private final JPanel southPanel; private final DotButton greyP; private final DotButton orangeP; private final DotButton blueP; private final DotButton greenP; private final DotButton purpleP; private final DotButton redP; private final DotButton[][] board; private int iconSize;
public GameView(GameModel model, GameController gameController) { setTitle("ITI1121 FloodIt"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.model = model; this.gameController = gameController;
reset = new JButton("reset"); reset.addActionListener(this.gameController); reset.setContentAreaFilled(false); reset.setBackground(Color.WHITE); reset.setOpaque(true); quit = new JButton("quit"); quit.addActionListener(this.gameController); quit.setContentAreaFilled(false); quit.setBackground(Color.WHITE); quit.setOpaque(true);
boardPanel = new JPanel(new GridLayout(model.getSize(), model.getSize())); colorSelectionPanel = new JPanel(); controlPanel = new JPanel(); southPanel = new JPanel(new BorderLayout());
iconSize = -1;
board = new DotButton[model.getSize()][model.getSize()];
if (model.getSize() <= 25 && model.getSize() >= 10) { iconSize = 1; } else if (model.getSize() > 25) { iconSize = 0; }
for (int i = 0; i < model.getSize(); i++) { for (int j = 0; j < model.getSize(); j++) { board[i][j] = new DotButton(model.get(i, j).getX(), model.get(i, j).getY(), model.getColor(i, j), iconSize); boardPanel.add(board[i][j]); } }
controlPanel.setBackground(Color.WHITE); controlPanel.setOpaque(true);
controlPanel.add(new JLabel("Number of steps Done:" + Integer.toString(model.getNumberOfSteps()))); controlPanel.add(reset); controlPanel.add(quit);
colorSelectionPanel.setBackground(Color.WHITE); colorSelectionPanel.setOpaque(true);
greenP = new DotButton(3, 2); purpleP = new DotButton(4, 2); redP = new DotButton(5, 2); greyP = new DotButton(0, 2); orangeP = new DotButton(1, 2); blueP = new DotButton(2, 2); greenP.addActionListener(this.gameController); purpleP.addActionListener(this.gameController); redP.addActionListener(this.gameController); greyP.addActionListener(this.gameController); orangeP.addActionListener(this.gameController); blueP.addActionListener(this.gameController);
colorSelectionPanel.setBackground(Color.WHITE); colorSelectionPanel.setOpaque(true); colorSelectionPanel.setBorder(BorderFactory.createLineBorder(Color.GRAY, 3));
colorSelectionPanel.add(greenP); colorSelectionPanel.add(purpleP); colorSelectionPanel.add(redP); colorSelectionPanel.add(greyP); colorSelectionPanel.add(orangeP); colorSelectionPanel.add(blueP);
southPanel.add(colorSelectionPanel, BorderLayout.CENTER); southPanel.add(controlPanel, BorderLayout.SOUTH);
add(boardPanel, BorderLayout.CENTER); add(southPanel, BorderLayout.SOUTH);
pack(); setLocationRelativeTo(null); setResizable(false); setVisible(true); }
public void update() { boardPanel.removeAll(); for (int i = 0; i < model.getSize(); i++) { for (int j = 0; j < model.getSize(); j++) { board[i][j] = new DotButton(i, j, model.getColor(i, j), iconSize); boardPanel.add(board[i][j]); } } controlPanel.removeAll(); controlPanel.add(new JLabel("Number of steps Done: ")); controlPanel.add(new JLabel(Integer.toString(model.getNumberOfSteps()))); controlPanel.add(reset); controlPanel.add(quit); revalidate(); repaint(); } }
STACK.JAVA
public interface Stack
public abstract boolean isEmpty();
public abstract E peek();
public abstract E pop();
public abstract void push(E element);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started