-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen.java
More file actions
82 lines (65 loc) · 1.8 KB
/
Screen.java
File metadata and controls
82 lines (65 loc) · 1.8 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
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JPanel;
/**
*
* @author Marisabel Chang
*
*This panel contains 4 boards of the fruit punch game. The boards are store in sequence, so when the score board appears,
*the next board is the initial board
*
*/
public class Screen extends JPanel {
private final int WIDTH = 1000;
private final int HEIGHT = 600;
private GameBoard board;//game board
private InitBoard start;
private InstructionBoard instruction;
private GameOverBoard gameOver;
public Screen() {
setPreferredSize(new Dimension(WIDTH, HEIGHT));
start = new InitBoard();
start.setUser();
instruction= new InstructionBoard();
board = new GameBoard();
gameOver = new GameOverBoard(board,start);
add(start);
add (instruction);
add(board);
add(gameOver);
}
@Override
protected void paintComponent(Graphics g) {
checkStartBoard();
checkInstructionBoard();
checkGameBoard();
checkGameOverBoard();
}
private void checkStartBoard() {
if (!start.isVisible()) {
start.resetVisibility();
start.setUserVisibility(false);// Disappear the text field that contains the name of
// the player
}
}
private void checkInstructionBoard() {
if (!instruction.isVisible()) {
instruction.resetVisibility();
}
}
private void checkGameBoard() {
if (!board.isVisible()) {
board = new GameBoard();
remove(2);//Remove the game board from the panel
add(board, 2);//Add the new game board to the position of the preview game board
}
}
private void checkGameOverBoard() {
if (!gameOver.isVisible()) {
gameOver.setBoard(board);
gameOver.resetVisibility();
}
}
}