Assuming that the system is a closed system, the mass of the system is constant througout the
process.Hence the volume of the system doesnot change making it an isochoric process.
So, win = 0 kJ/kg
Solution
Assuming that the system is a closed system, the mass of the system is constant througout the
process.Hence the volume of the system doesnot change making it an isochoric process.
So, win = 0 kJ/kg.
import java.util.Scanner; import java.util.Random; public clas.pdf
1. import java.util.Scanner;
import java.util.Random;
public class TicTacToe implements ActionListener {
final String VERSION = "3.0"
//Setting up ALL the variables
JFrame window = new JFrame("Tic-Tac-Toe " + VERSION);
JMenuBar mnuMain = new JMenuBar();
JMenuItem mnuNewGame = new JMenuItem("New Game"),
mnuInstruction = new JMenuItem("Instructions"),
mnuExit = new JMenuItem("Exit"),
mnuAbout = new JMenuItem("About");
JButton btn1v1 = new JButton("Player vs Player"),
btn1vCPU = new JButton("Player vs Computer"),
btnQuit = new JButton("Quit"),
btnSetName = new JButton("Set Player Names"),
btnContinue = new JButton("Continue..."),
btnTryAgain = new JButton("Try Again?");
JButton btnEmpty[] = new JButton[10];
JPanel pnlNewGame = new JPanel(),
pnlMenu = new JPanel(),
pnlMain = new JPanel(),
pnlTop = new JPanel(),
pnlBottom = new JPanel(),
pnlQuitNTryAgain = new JPanel(),
pnlPlayingField = new JPanel();
JLabel lblTitle = new JLabel("Tic-Tac-Toe"),
lblTurn = new JLabel(),
lblStatus = new JLabel("", JLabel.CENTER),
lblMode = new JLabel("", JLabel.LEFT);
JTextArea txtMessage = new JTextArea();
final int winCombo[ ][ ] = new int[ ][ ] {
{1, 2, 3}, {1, 4, 7}, {1, 5, 9},
{4, 5, 6}, {2, 5, 8}, {3, 5, 7},
3. pnlQuitNTryAgain.add(btnQuit);
//Adding menu items to menu bar
mnuMain.add(mnuNewGame);
mnuMain.add(mnuInstruction);
mnuMain.add(mnuAbout);
mnuMain.add(mnuExit);// Menu Bar is Complete
//Adding buttons to NewGame panel
pnlNewGame.setLayout(new GridLayout(4, 1, 2, 10));
pnlNewGame.add(btnContinue);
pnlNewGame.add(btn1v1);
pnlNewGame.add(btn1vCPU);
pnlNewGame.add(btnSetName);
//Setting Button propertied
btnTryAgain.setEnabled(false);
btnContinue.setEnabled(false);
//Setting txtMessage Properties
txtMessage.setBackground(new Color(mainColorR-30, mainColorG-30, mainColorB-30));
txtMessage.setForeground(Color.white);
txtMessage.setEditable(false);
//Adding Action Listener to all the Buttons and Menu Items
mnuNewGame.addActionListener(this);
mnuExit.addActionListener(this);
mnuInstruction.addActionListener(this);
mnuAbout.addActionListener(this);
btn1v1.addActionListener(this);
btn1vCPU.addActionListener(this);
btnQuit.addActionListener(this);
btnSetName.addActionListener(this);
btnContinue.addActionListener(this);
btnTryAgain.addActionListener(this);
//Setting up the playing field
pnlPlayingField.setLayout(new GridLayout(3, 3, 2, 2));
pnlPlayingField.setBackground(Color.black);
for(int i=1; i<=9; i++) {
btnEmpty[i] = new JButton();
btnEmpty[i].setBackground(new Color(btnColorR, btnColorG, btnColorB));
4. btnEmpty[i].addActionListener(this);
pnlPlayingField.add(btnEmpty[i]);// Playing Field is Compelte
}
//Adding everything needed to pnlMenu and pnlMain
lblMode.setForeground(Color.white);
pnlMenu.add(lblMode);
pnlMenu.add(mnuMain);
pnlMain.add(lblTitle);
//Adding to window and Showing window
window.add(pnlMenu, BorderLayout.NORTH);
window.add(pnlMain, BorderLayout.CENTER);
window.setVisible(true);
}
public static void main(String[] args) {
new TicTacToe();// Calling the class construtor.
// PROGRAM STARTS HERE!
}
/*
-------------------------
Start of all METHODS. |
-------------------------
*/
public void showGame() { // Shows the Playing Field
// *IMPORTANT*- Does not start out brand new (meaning just shows what it had before)
clearPanelSouth();
pnlMain.setLayout(new BorderLayout());
pnlTop.setLayout(new BorderLayout());
pnlBottom.setLayout(new BorderLayout());
pnlTop.add(pnlPlayingField);
pnlBottom.add(lblTurn, BorderLayout.WEST);
pnlBottom.add(lblStatus, BorderLayout.CENTER);
pnlBottom.add(pnlQuitNTryAgain, BorderLayout.EAST);
pnlMain.add(pnlTop, BorderLayout.CENTER);
pnlMain.add(pnlBottom, BorderLayout.SOUTH);
pnlPlayingField.requestFocus();
inGame = true;
5. checkTurn();
checkWinStatus();
}
//-------------------------------------------------------------------------------------------------------------------
----------------
public void newGame() { // Sets all the game required variables to default
// and then shows the playing field.
// (Basically: Starts a new 1v1 Game)
btnEmpty[wonNumber1].setBackground(new Color(btnColorR, btnColorG, btnColorB));
btnEmpty[wonNumber2].setBackground(new Color(btnColorR, btnColorG, btnColorB));
btnEmpty[wonNumber3].setBackground(new Color(btnColorR, btnColorG, btnColorB));
for(int i=1; i<10; i++) {
btnEmpty[i].setText("");
btnEmpty[i].setEnabled(true);
}
turn = 1;
win = false;
showGame();
}
//-------------------------------------------------------------------------------------------------------------------
----------------
public void quit() {
inGame = false;
lblMode.setText("");
btnContinue.setEnabled(false);
clearPanelSouth();
setDefaultLayout();
pnlTop.add(pnlNewGame);
pnlMain.add(pnlTop);
}
//-------------------------------------------------------------------------------------------------------------------
----------------
public void checkWin() { // checks if there are 3 symbols in a row vertically, diagonally, or
horizontally.
// then shows a message and disables buttons. If the game is
over then it asks
6. // if you want to play again.
for(int i=0; i<8; i++) {
if(
!btnEmpty[winCombo[i][0]].getText().equals("") &&
btnEmpty[winCombo[i][0]].getText().equals(btnEmpty[winCombo[i][1]].getText()) &&
// if {1 == 2 && 2 == 3}
btnEmpty[winCombo[i][1]].getText().equals(btnEmpty[winCombo[i][2]].getText())) {
/*
The way this checks the if someone won is:
First: it checks if the btnEmpty[x] is not equal to an empty string- x being the array
number
inside the multi-dementional array winCombo[checks inside each of the 7 sets][the
first number]
Secong: it checks if btnEmpty[x] is equal to btnEmpty[y]- x being winCombo[each set][the
first number]
y being winCombo[each set the same as x][the second number] (So basically checks
if the first and
second number in each set is equal to each other)
Third: it checks if btnEmtpy[y] is eual to btnEmpty[z]- y being the same y as last time and
being
winCombo[each set as y][the third number]
Conclusion: So basically it checks if it is equal to the btnEmpty is equal to each set of numbers
*/
win = true;
wonNumber1 = winCombo[i][0];
wonNumber2 = winCombo[i][1];
wonNumber3 = winCombo[i][2];
btnEmpty[wonNumber1].setBackground(clrBtnWonColor);
btnEmpty[wonNumber2].setBackground(clrBtnWonColor);
btnEmpty[wonNumber3].setBackground(clrBtnWonColor);
break;
}
}
if(win || (!win && turn>9)) {
if(win) {
if(btnEmpty[wonNumber1].getText().equals("X")) {
14. public class TicTacToe implements ActionListener {
final String VERSION = "3.0"
//Setting up ALL the variables
JFrame window = new JFrame("Tic-Tac-Toe " + VERSION);
JMenuBar mnuMain = new JMenuBar();
JMenuItem mnuNewGame = new JMenuItem("New Game"),
mnuInstruction = new JMenuItem("Instructions"),
mnuExit = new JMenuItem("Exit"),
mnuAbout = new JMenuItem("About");
JButton btn1v1 = new JButton("Player vs Player"),
btn1vCPU = new JButton("Player vs Computer"),
btnQuit = new JButton("Quit"),
btnSetName = new JButton("Set Player Names"),
btnContinue = new JButton("Continue..."),
btnTryAgain = new JButton("Try Again?");
JButton btnEmpty[] = new JButton[10];
JPanel pnlNewGame = new JPanel(),
pnlMenu = new JPanel(),
pnlMain = new JPanel(),
pnlTop = new JPanel(),
pnlBottom = new JPanel(),
pnlQuitNTryAgain = new JPanel(),
pnlPlayingField = new JPanel();
JLabel lblTitle = new JLabel("Tic-Tac-Toe"),
lblTurn = new JLabel(),
lblStatus = new JLabel("", JLabel.CENTER),
lblMode = new JLabel("", JLabel.LEFT);
JTextArea txtMessage = new JTextArea();
final int winCombo[ ][ ] = new int[ ][ ] {
{1, 2, 3}, {1, 4, 7}, {1, 5, 9},
{4, 5, 6}, {2, 5, 8}, {3, 5, 7},
{7, 8, 9}, {3, 6, 9}
/*Horizontal Wins*/ /*Vertical Wins*/ /*Diagonal Wins*/
};
final int X = 535, Y = 342,
16. mnuMain.add(mnuAbout);
mnuMain.add(mnuExit);// Menu Bar is Complete
//Adding buttons to NewGame panel
pnlNewGame.setLayout(new GridLayout(4, 1, 2, 10));
pnlNewGame.add(btnContinue);
pnlNewGame.add(btn1v1);
pnlNewGame.add(btn1vCPU);
pnlNewGame.add(btnSetName);
//Setting Button propertied
btnTryAgain.setEnabled(false);
btnContinue.setEnabled(false);
//Setting txtMessage Properties
txtMessage.setBackground(new Color(mainColorR-30, mainColorG-30, mainColorB-30));
txtMessage.setForeground(Color.white);
txtMessage.setEditable(false);
//Adding Action Listener to all the Buttons and Menu Items
mnuNewGame.addActionListener(this);
mnuExit.addActionListener(this);
mnuInstruction.addActionListener(this);
mnuAbout.addActionListener(this);
btn1v1.addActionListener(this);
btn1vCPU.addActionListener(this);
btnQuit.addActionListener(this);
btnSetName.addActionListener(this);
btnContinue.addActionListener(this);
btnTryAgain.addActionListener(this);
//Setting up the playing field
pnlPlayingField.setLayout(new GridLayout(3, 3, 2, 2));
pnlPlayingField.setBackground(Color.black);
for(int i=1; i<=9; i++) {
btnEmpty[i] = new JButton();
btnEmpty[i].setBackground(new Color(btnColorR, btnColorG, btnColorB));
btnEmpty[i].addActionListener(this);
pnlPlayingField.add(btnEmpty[i]);// Playing Field is Compelte
}
//Adding everything needed to pnlMenu and pnlMain
17. lblMode.setForeground(Color.white);
pnlMenu.add(lblMode);
pnlMenu.add(mnuMain);
pnlMain.add(lblTitle);
//Adding to window and Showing window
window.add(pnlMenu, BorderLayout.NORTH);
window.add(pnlMain, BorderLayout.CENTER);
window.setVisible(true);
}
public static void main(String[] args) {
new TicTacToe();// Calling the class construtor.
// PROGRAM STARTS HERE!
}
/*
-------------------------
Start of all METHODS. |
-------------------------
*/
public void showGame() { // Shows the Playing Field
// *IMPORTANT*- Does not start out brand new (meaning just shows what it had before)
clearPanelSouth();
pnlMain.setLayout(new BorderLayout());
pnlTop.setLayout(new BorderLayout());
pnlBottom.setLayout(new BorderLayout());
pnlTop.add(pnlPlayingField);
pnlBottom.add(lblTurn, BorderLayout.WEST);
pnlBottom.add(lblStatus, BorderLayout.CENTER);
pnlBottom.add(pnlQuitNTryAgain, BorderLayout.EAST);
pnlMain.add(pnlTop, BorderLayout.CENTER);
pnlMain.add(pnlBottom, BorderLayout.SOUTH);
pnlPlayingField.requestFocus();
inGame = true;
checkTurn();
checkWinStatus();
}
//-------------------------------------------------------------------------------------------------------------------
18. ----------------
public void newGame() { // Sets all the game required variables to default
// and then shows the playing field.
// (Basically: Starts a new 1v1 Game)
btnEmpty[wonNumber1].setBackground(new Color(btnColorR, btnColorG, btnColorB));
btnEmpty[wonNumber2].setBackground(new Color(btnColorR, btnColorG, btnColorB));
btnEmpty[wonNumber3].setBackground(new Color(btnColorR, btnColorG, btnColorB));
for(int i=1; i<10; i++) {
btnEmpty[i].setText("");
btnEmpty[i].setEnabled(true);
}
turn = 1;
win = false;
showGame();
}
//-------------------------------------------------------------------------------------------------------------------
----------------
public void quit() {
inGame = false;
lblMode.setText("");
btnContinue.setEnabled(false);
clearPanelSouth();
setDefaultLayout();
pnlTop.add(pnlNewGame);
pnlMain.add(pnlTop);
}
//-------------------------------------------------------------------------------------------------------------------
----------------
public void checkWin() { // checks if there are 3 symbols in a row vertically, diagonally, or
horizontally.
// then shows a message and disables buttons. If the game is
over then it asks
// if you want to play again.
for(int i=0; i<8; i++) {
if(
!btnEmpty[winCombo[i][0]].getText().equals("") &&
19. btnEmpty[winCombo[i][0]].getText().equals(btnEmpty[winCombo[i][1]].getText()) &&
// if {1 == 2 && 2 == 3}
btnEmpty[winCombo[i][1]].getText().equals(btnEmpty[winCombo[i][2]].getText())) {
/*
The way this checks the if someone won is:
First: it checks if the btnEmpty[x] is not equal to an empty string- x being the array
number
inside the multi-dementional array winCombo[checks inside each of the 7 sets][the
first number]
Secong: it checks if btnEmpty[x] is equal to btnEmpty[y]- x being winCombo[each set][the
first number]
y being winCombo[each set the same as x][the second number] (So basically checks
if the first and
second number in each set is equal to each other)
Third: it checks if btnEmtpy[y] is eual to btnEmpty[z]- y being the same y as last time and
being
winCombo[each set as y][the third number]
Conclusion: So basically it checks if it is equal to the btnEmpty is equal to each set of numbers
*/
win = true;
wonNumber1 = winCombo[i][0];
wonNumber2 = winCombo[i][1];
wonNumber3 = winCombo[i][2];
btnEmpty[wonNumber1].setBackground(clrBtnWonColor);
btnEmpty[wonNumber2].setBackground(clrBtnWonColor);
btnEmpty[wonNumber3].setBackground(clrBtnWonColor);
break;
}
}
if(win || (!win && turn>9)) {
if(win) {
if(btnEmpty[wonNumber1].getText().equals("X")) {
message = Player1 + " has won";
player1Won++;
}
else {