MCPcopy Create free account
hub / github.com/MolinDeng/Princeton-algs4 / BoggleGame

Class BoggleGame

LabEnv/09Lab/BoggleGame.java:51–1009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49import edu.princeton.cs.algs4.SET;
50
51public class BoggleGame extends JFrame {
52 private static final int GAME_TIME = 180; // in seconds
53 private static final int SECONDS_PER_MINUTE = 60; // number of seconds in one minute
54 private static final int FOUND_WORDS_DISPLAY_COUNT = 17; // how many rows to display for the two side columns
55 private static final int ALL_WORDS_DISPLAY_COUNT = 7; // how many rows to display for the middle all-words list
56
57 // sizes of GUI elements, in pixels
58 private static final int DEF_HEIGHT = 550;
59 private static final int DEF_WIDTH = 700;
60 private static final int WORD_PANEL_WIDTH = 205;
61 private static final int WORD_PANEL_HEIGHT = 325;
62
63 // colors for displaying words found only by player, opponent, and both
64 private static final Color PLAYER_POINT_WORD = new Color(0xBFBFBF);
65 private static final Color OPP_POINT_WORD = new Color(0xBFBFBF);
66 private static final Color NONPOINT_WORD = new Color(0xBFBFBF);
67
68 // game levels
69 // keep these in sync - should be a text description for each level!
70 // if making adjustments to levels, endGame (~line 400) contains hard-coded elements
71 // menu items will be adjusted automatically
72 private static final int NUMBER_OF_LEVELS = 5;
73 private static final String[] LEVEL_DESCRIPTION = {
74 "Nursery",
75 "Shakespeare",
76 "Algorithms 4/e",
77 "Hard",
78 "Impossible"
79 };
80 private static final int NURSERY = 0;
81 private static final int SHAKESPEARE = 1;
82 private static final int ALGORITHMS = 2;
83 private static final int HARD = 3;
84 private static final int IMPOSSIBLE = 4;
85
86 // keep these two values in sync!
87 // used to force the JTextfield and the JList to be the same length
88 private static final int DEF_COLUMNS = 10;
89 private static final String MAX_WORD_SIZE = "INCONSEQUENTIALLY";
90
91
92 // keeps track of the level
93 private int gameDifficulty = 0;
94
95 // number and rows and columns of board
96 private int BOARD_ROWS;
97 private int BOARD_COLS;
98
99 // game values
100 private boolean inGame = true;
101 private int elapsedTime = 0; // elapsed time (in seconds)
102 private int points = 0; // current number of points
103 private Timer timer = new Timer();
104
105 private String[] emptyList = new String[0];
106
107 private LinkedHashSet<String> foundWords; // to keep words in same order as entered
108 private TreeSet<String> validWords;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected