-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOuterGamePanel.java
More file actions
215 lines (192 loc) · 7.38 KB
/
OuterGamePanel.java
File metadata and controls
215 lines (192 loc) · 7.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
/**
* Represent the CardLayout class, connects each game and the welcome panel together.
* @author Acosta and Chen
* @version 1.5 4/8/14
*/
public class OuterGamePanel extends JPanel
{
private CardLayout c1;
private JPanel outerPane, mainPanel, tttInstructions, tetrisOptions;
private JLabel welcome1, welcome2, screenTwoGreet;
private JButton playTTT, playTetris, zeroP, oneP, fourP; //P stands for pieces to see ahead for tetris
private TetrisPanel tetris;
private TicTacToePanel ttt;
/**
* Constructor, creates and implements all the game and instruction panels.
*/
public OuterGamePanel()
{
c1 = new CardLayout();
outerPane = new JPanel();
outerPane.setLayout(c1);
//Set Welcome Panel called outerPane
mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
welcome1 = new JLabel("Welcome to Cesar and Chen's Arcade!");
welcome1.setFont(new Font("Broadway", Font.BOLD, 33));
welcome1.setAlignmentX(Component.CENTER_ALIGNMENT);
welcome2 = new JLabel("Please select a game to play:");
welcome2.setFont(new Font("Arial", Font.BOLD, 20));
welcome2.setAlignmentX(Component.CENTER_ALIGNMENT);
playTetris = new JButton(new ImageIcon("tetrisLogo.png"));
playTetris.setAlignmentX(Component.CENTER_ALIGNMENT);
playTetris.addActionListener(new CardListener());
playTTT = new JButton(new ImageIcon("ticTacToeLogo.gif"));
playTTT.setAlignmentX(Component.CENTER_ALIGNMENT);
playTTT.addActionListener(new CardListener());
mainPanel.add(Box.createRigidArea(new Dimension(0,100)));
mainPanel.add(welcome1);
mainPanel.add(welcome2);
mainPanel.add(Box.createRigidArea(new Dimension(0,50)));
mainPanel.add(playTetris);
mainPanel.add(Box.createRigidArea(new Dimension(0,50)));
mainPanel.add(playTTT);
mainPanel.setBackground(Color.orange);
mainPanel.setMinimumSize(new Dimension(780,500));
//Set TTT Instructions Panel called tttInstructions
tttInstructions = new JPanel();
tttInstructions.setLayout(new BoxLayout(tttInstructions, BoxLayout.Y_AXIS));
JTextArea tttInstr = new JTextArea();
tttInstr.setBackground(Color.CYAN);
tttInstr.setFont(new Font("Times New Roman", Font.BOLD, 20));
tttInstr.setText("\n\tInstructions of TicTacToe:\n\n"
+ "\tTwo players (Player X and Player O) can play this game\n"
+ "\t\tby putting X's and O's on the board.\n\n"
+ "\tPlayer X starts first, and then it alternates between players.\n"
+ "\tIf a player has three of his/her shape (X's or O's) in a row,\n"
+ "\t\tthis player wins for this turn.\n"
+ "\tIf the board is filled up, then it is a tie.\n"
+ "\tIn the next game, the other player will start first.\n\n"
+ "\tThe scores will be recorded.\n"
+ "\tClick Undo or Press Control-Z to undo one step.");
JLabel tttGreet = new JLabel("Click Continue:");
tttGreet.setFont(new Font("Times New Roman", Font.BOLD, 25));
tttGreet.setAlignmentX(Component.CENTER_ALIGNMENT);
TTTContinueListener tcl = new TTTContinueListener();
JButton tttContinue = new JButton("Continue");
tttContinue.addActionListener(tcl);
tttContinue.setAlignmentX(Component.CENTER_ALIGNMENT);
tttInstructions.add(tttInstr);
tttInstructions.add(Box.createRigidArea(new Dimension(0,50)));
tttInstructions.add(tttGreet);
tttInstructions.add(Box.createRigidArea(new Dimension(0,50)));
tttInstructions.add(tttContinue);
tttInstructions.add(Box.createRigidArea(new Dimension(0,70)));
tttInstructions.setBackground(Color.GREEN);
//Set Tetris Instruction and Option Panel called tetrisOptions
tetrisOptions = new JPanel();
tetrisOptions.setLayout(new BoxLayout(tetrisOptions, BoxLayout.Y_AXIS));
JTextArea tetrisInstr = new JTextArea();
tetrisInstr.setBackground(Color.CYAN);
tetrisInstr.setFont(new Font("Times New Roman", Font.BOLD, 20));
tetrisInstr.setText("\n\n\tInstructions of Tetris:\n\n"
+ "\tYou can move a dropping piece and place it in a correct place.\n\n"
+ "\t\tLEFT key to move the piece to the left\n"
+ "\t\tRIGHT key to move the piece to the right\n"
+ "\t\tUP key to rotate the piece\n"
+ "\t\tDOWN key to accelerate the dropping\n\n"
+ "\tIf any row is fully filled, then it clears and you gain a lot of points!\n"
+ "\tYou will have a total of 200 pieces, score as much as you can!");
screenTwoGreet = new JLabel("Please choose an option for the number of pieces"
+ " you want to view ahead: ");
screenTwoGreet.setFont(new Font("Times New Roman", Font.BOLD, 25));
screenTwoGreet.setAlignmentX(Component.CENTER_ALIGNMENT);
TetrisOptionsListener tol = new TetrisOptionsListener();
zeroP = new JButton("No Piece Ahead");
zeroP.addActionListener(tol);
zeroP.setAlignmentX(Component.CENTER_ALIGNMENT);
oneP = new JButton("1 Piece Ahead");
oneP.addActionListener(tol);
oneP.setAlignmentX(Component.CENTER_ALIGNMENT);
fourP = new JButton("4 Pieces Ahead");
fourP.addActionListener(tol);
fourP.setAlignmentX(Component.CENTER_ALIGNMENT);
tetrisOptions.add(tetrisInstr);
tetrisOptions.add(Box.createRigidArea(new Dimension(0,20)));
tetrisOptions.add(screenTwoGreet);
tetrisOptions.add(Box.createRigidArea(new Dimension(0,20)));
tetrisOptions.add(zeroP);
tetrisOptions.add(Box.createRigidArea(new Dimension(0,20)));
tetrisOptions.add(oneP);
tetrisOptions.add(Box.createRigidArea(new Dimension(0,20)));
tetrisOptions.add(fourP);
tetrisOptions.add(Box.createRigidArea(new Dimension(0,50)));
tetrisOptions.setBackground(Color.GREEN);
//Adding the mainPanel to the Card Layout
outerPane.add(mainPanel,"1");
outerPane.setPreferredSize(new Dimension(800,600));
add(outerPane);
}
/**
* ActionListener for the CardLayout
* @author Acosta and Chen
* @version 1.1 4/8/14
*/
private class CardListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == playTetris)
{
outerPane.add(tetrisOptions, "4");
c1.show(outerPane, "4");
}
else if(e.getSource() == playTTT)
{
outerPane.add(tttInstructions, "5");
c1.show(outerPane, "5");
}
}
}
/**
* ActionListener for the TicTacToe Continue Button
* @author Acosta and Chen
* @version 1.0 4/6/14
*/
private class TTTContinueListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
ttt = new TicTacToePanel();
outerPane.add(ttt, "3");
c1.show(outerPane, "3");
ttt.requestFocus();
}
}
/**
* ActionListener for the Tetris Piece(s) display Options
* @author Acosta and Chen
* @version 1.0 4/7/14
*/
private class TetrisOptionsListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == zeroP)
{
tetris = new TetrisPanel(0);
outerPane.add(tetris, "2");
c1.show(outerPane, "2");
tetris.requestFocus();
}
else if (e.getSource() == oneP)
{
tetris = new TetrisPanel(1);
outerPane.add(tetris, "2");
c1.show(outerPane, "2");
tetris.requestFocus();
}
else if (e.getSource() == fourP)
{
tetris = new TetrisPanel(4);
outerPane.add(tetris, "2");
c1.show(outerPane, "2");
tetris.requestFocus();
}
}
}
}