Professional Documents
Culture Documents
Assignment 7
Requirements:
● Create a Java project named StudentId_Assignment7
● Read instructions and create classes needed.
● All instance variables are private. Please use public methods to access private instance variables.
Description:
Now, you are a game interface programmer, you need to implement an OOXX game.
The game center has been done, so you just need to design the interface and call the game function to let it
work. You should watch the video in the link below to understand all the requirements for this assignment.
https://www.youtube.com/watch?v=XKXMQjy9FgI
OXGameManager class
OXGameManager
String play(int) When a player takes a step, it will do the record on that
position and return the player symbol.
String checkWin() It will confirm if there is a winner. If not, it will return null.
1
Programming Language II 111-2
2
Programming Language II 111-2
You need to draw the layout of the GUI and implement all the buttons.
When a player presses the board, the index button will be placed to “O” or “X”.
Every time there is a winner, the winner’s score will increase.
When you press the ReStart button, the game board will be reset.
When you press the Finish button, the game window will be closed.
Submission: Submit your project as “.zip file” via Moodle. No other submissions will be graded.
3
Programming Language II 111-2
4
Programming Language II 111-2
class Assignment7
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
btns[i] = btn;
}
f.add(score);
f.add(reStart);
f.add(finish);
for (int i=0; i<9; i++) { f.add(btns[i]); }
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
5
Programming Language II 111-2
class OXGameManager
public class OXGameManager {
private boolean state = true;
private boolean finish = false;
private int count = 0;
private int[] checkerboard = new int[9];
private String winner = null;
private int scoreO = 0;
private int scoreX = 0;
count++;
if(state) {
state = false;
checkerboard[index] = 1;
return "O";
}else {
state = true;
checkerboard[index] = -1;
return "X";
}
}
// Get O score
public int getScoreO() {
return scoreO;
}
// Get X score
public int getScoreX() {
return scoreX;
}
6
Programming Language II 111-2
{6, 7, 8},
{0, 3, 6},
{1, 4, 7},
{2, 5, 8},
{0, 4, 8},
{2, 4, 6}
};
return winner;
}