Skip to content

Commit b412e66

Browse files
Michael BalasMichael Balas
authored andcommitted
Document the NPC methods and access modifiers
There were no comments describing any of the access modifiers, as well as the methods: npcSpawn() and npcKill(). This commit provides documentation that describes what the NPC methods do, and also provides context for some mutators that can be potentially ambiguous (e.g. setMap(String Map_str)). This makes the code much easier to understand, especially since the integer values describing colour are hard to understand without supporting documentation (e.g. 500 is red). Not all access modifiers are documented since many are self-explanatory and would only create code clutter.
1 parent 3f3e075 commit b412e66

File tree

1 file changed

+60
-50
lines changed

1 file changed

+60
-50
lines changed

src/com/redomar/game/Game.java

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,58 +32,58 @@ public class Game extends Canvas implements Runnable {
3232
private static final long serialVersionUID = 1L;
3333
private static final String game_Version = "v1.8.3 Alpha"; // Current version of the game
3434
private static final int WIDTH = 160; // The width of the screen
35-
private static final int HEIGHT = (WIDTH / 3 * 2); // The height of the screen (two thirds of the width)
36-
private static final int SCALE = 3; // Scales the size of the screen (in either the x-direction, y-direction, or both)
35+
private static final int HEIGHT = (WIDTH / 3 * 2); // The height of the screen (two thirds of the width)
36+
private static final int SCALE = 3; // Scales the size of the screen (in either the x-direction, y-direction, or both)
3737
private static final String NAME = "Game"; // The name of the JFrame panel
3838
private static Game game;
3939
private static Time time = new Time(); // Date object that represents the calender's time value, in hh:mm:ss
4040

4141
// The properties of the player, npc, and fps/tps
42-
private static int Jdata_Host; // The host of a multiplayer game (only available in earlier versions)
42+
private static int Jdata_Host; // The host of a multiplayer game (only available in earlier versions)
4343
private static String Jdata_UserName = ""; // The player's username (initialized as an empty string)
44-
private static String Jdata_IP = "127.0.0.1"; // Displays an IP address
44+
private static String Jdata_IP = "127.0.0.1"; // Displays an IP address
4545
private static boolean changeLevel = false; // Determines whether the level should change (initialized to not change)
46-
private static boolean npc = false; // Non-player character (NPC) initialized to non-existing
47-
private static int map = 0; // Map of the level, initialized to no map (0)
48-
private static int shirtCol; // The colour of the character's shirt
49-
private static int faceCol; // The colour (ethnicity) of the character (their face)
46+
private static boolean npc = false; // Non-player character (NPC) initialized to non-existing
47+
private static int map = 0; // Map of the level, initialized to no map (0)
48+
private static int shirtCol; // The colour of the character's shirt
49+
private static int faceCol; // The colour (ethnicity) of the character (their face)
5050
private static boolean[] alternateCols = new boolean[2]; // Boolean array with 2 elements (for determining shirt and face colour), all initialized to false
51-
private static int fps; // The frame rate (frames per second), frequency at which images are displayed on the canvas
52-
private static int tps; // The ticks (ticks per second), unit measure of time for one iteration of the game logic loop.
51+
private static int fps; // The frame rate (frames per second), frequency at which images are displayed on the canvas
52+
private static int tps; // The ticks (ticks per second), unit measure of time for one iteration of the game logic loop.
5353
private static int steps;
54-
private static boolean devMode; // Determines whether the game is in developer mode
55-
private static boolean closingMode; // Determines whether the game will exit
54+
private static boolean devMode; // Determines whether the game is in developer mode
55+
private static boolean closingMode; // Determines whether the game will exit
5656

5757
// Audio, input, and mouse handler objects
58-
private static JFrame frame; // Frame with support for JFC/swing component architecture
58+
private static JFrame frame; // Frame with support for JFC/swing component architecture
5959
private static AudioHandler backgroundMusic; // AudioHandler object that can play music in the background (but can't turn it off)
60-
private static boolean running = false; // Determines whether the game is currently in process (i.e. whether the game is running)
61-
private static InputHandler input; // InputHandler object that accepts keyboard input and follows the appropriate actions
62-
private static MouseHandler mouse; // MouseHandler object that tracks mouse movement and clicks, and follows the appropriate actions
63-
private static InputContext context; // InputContext object that provides methods to control text input facilities
60+
private static boolean running = false; // Determines whether the game is currently in process (i.e. whether the game is running)
61+
private static InputHandler input; // InputHandler object that accepts keyboard input and follows the appropriate actions
62+
private static MouseHandler mouse; // MouseHandler object that tracks mouse movement and clicks, and follows the appropriate actions
63+
private static InputContext context; // InputContext object that provides methods to control text input facilities
6464
private int tickCount = 0;
6565

6666
// Graphics
67-
private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, // Describes a rasterized image with dimensions WIDTH and HEIGHT, and RGB colour
68-
BufferedImage.TYPE_INT_RGB); // Set to TYPE_INT_ARGB to support transparency
67+
private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, // Describes a rasterized image with dimensions WIDTH and HEIGHT, and RGB colour
68+
BufferedImage.TYPE_INT_RGB);
6969
private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()) // Array of red, green and blue values for each pixel, as well as an alpha value (if there is an alpha channel)
7070
.getData();
71-
private int[] colours = new int[6 * 6 * 6]; // Array of 216 unique colours
71+
private int[] colours = new int[6 * 6 * 6]; // Array of 216 unique colours
7272
private BufferedImage image2 = new BufferedImage(WIDTH, HEIGHT - 30,
7373
BufferedImage.TYPE_INT_RGB);
7474
private Screen screen; // Screen object that accepts a width, height, and sprite sheet - to generate and render a screen
7575
private WindowHandler window;
7676
private LevelHandler level; // LevelHandler object that loads and renders levels along with tiles, entities, projectiles and more.
7777

7878
//The entities of the game
79-
private Player player; // This is the actual player
80-
private Dummy dummy; // This is a dummy npc (follows the player around)
81-
private Vendor vendor; // This is a vendor npc (random movement)
82-
private Font font = new Font(); // Font object capable of displaying 2 fonts: Arial and Segoe UI
79+
private Player player; // This is the actual player
80+
private Dummy dummy; // This is a dummy npc (follows the player around)
81+
private Vendor vendor; // This is a vendor npc (random movement)
82+
private Font font = new Font(); // Font object capable of displaying 2 fonts: Arial and Segoe UI
8383
private String nowPlaying;
8484
private boolean notActive = true;
8585
private int trigger = 0;
86-
private Printing print = new Printing(); // Print object that can display various messages and error logs
86+
private Printing print = new Printing(); // Print object that can display various messages and error logs
8787

8888
/**
8989
* @author Redomar
@@ -97,31 +97,38 @@ public Game() {
9797
setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
9898
setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
9999

100-
setFrame(new JFrame(NAME)); // Creates the frame
101-
getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Exits the program when user closes the frame
102-
getFrame().setLayout(new BorderLayout()); // Border lays out a container
103-
getFrame().add(this, BorderLayout.CENTER); // The centre layout constraint (middle of container)
104-
getFrame().pack(); // Sizes the frame so that all its contents are at or above their preferred sizes
105-
getFrame().setResizable(false); // Prevents the user from resizing the frame
106-
getFrame().setLocationRelativeTo(null); // Centres the window on the screen
107-
getFrame().setVisible(true); // Displays the frame
100+
setFrame(new JFrame(NAME)); // Creates the frame
101+
getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Exits the program when user closes the frame
102+
getFrame().setLayout(new BorderLayout()); // Border lays out a container
103+
getFrame().add(this, BorderLayout.CENTER); // The centre layout constraint (middle of container)
104+
getFrame().pack(); // Sizes the frame so that all its contents are at or above their preferred sizes
105+
getFrame().setResizable(false); // Prevents the user from resizing the frame
106+
getFrame().setLocationRelativeTo(null); // Centres the window on the screen
107+
getFrame().setVisible(true); // Displays the frame
108108

109109
requestFocus();
110110
setDevMode(false);
111111
setClosing(false);
112112
}
113113

114+
/*
115+
* This method will spawn a dummy NPC into the level only if they are allowed to be spawned in.
116+
* They will be spawned at position (100, 150) with a red shirt and caucasian face.
117+
*/
114118
public static void npcSpawn() {
115-
if (isNpc() == true) {
116-
game.setDummy(new Dummy(game.level, "Dummy", 100, 150, 500,
117-
543));
118-
game.level.addEntity(Game.getDummy());
119+
if (isNpc() == true) { // If NPCs are allowed in the level
120+
game.setDummy(new Dummy(game.level, "Dummy", 100, 150, 500, // Set a new dummy NPC on the current game level, with name 'Dummy'
121+
543)); // at position (100, 150), with shirt colour equal to 500 (red) and face colour equal to 543 (caucasian)
122+
game.level.addEntity(Game.getDummy()); // Add the previously defined dummy NPC to the game level
119123
}
120124
}
121125

126+
/*
127+
* This method will remove a dummy NPC from the level only if they are not allowed to be in it.
128+
*/
122129
public static void npcKill() {
123-
if (isNpc() == false) {
124-
game.level.removeEntity(Game.getDummy());
130+
if (isNpc() == false) { // If NPCs are not allowed in the level
131+
game.level.removeEntity(Game.getDummy()); // Remove the current dummy NPC from the level
125132
}
126133
}
127134

@@ -187,21 +194,21 @@ public static int getMap() {
187194

188195
public void setMap(String Map_str) {
189196
setLevel(new LevelHandler(Map_str));
190-
if (alternateCols[0]) {
191-
Game.setShirtCol(240);
197+
if (alternateCols[0]) { // If the first element (shirt colour) is set to True
198+
Game.setShirtCol(240); // The player's shirt colour is set to 240 (green)
192199
}
193-
if (!alternateCols[0]) {
194-
Game.setShirtCol(111);
200+
if (!alternateCols[0]) { // If the first element (shirt colour) is set to False
201+
Game.setShirtCol(111); // The player's shirt colour is set to 111 (black)
195202
}
196-
if (alternateCols[1]) {
197-
Game.setFaceCol(310);
203+
if (alternateCols[1]) { // If the last element (face colour) is set to True
204+
Game.setFaceCol(310); // The player's face colour is set to 310 (African)
198205
}
199-
if (!alternateCols[1]) {
200-
Game.setFaceCol(543);
206+
if (!alternateCols[1]) { // If the last element (face colour) is set to False
207+
Game.setFaceCol(543); // The player's face colour is set to 543 (caucasian)
201208
}
202-
setPlayer(new Player(level, 100, 100, input,
203-
getJdata_UserName(), shirtCol, faceCol));
204-
level.addEntity(player);
209+
setPlayer(new Player(level, 100, 100, input, // Create a new player on the current level, at position (100, 100), with an InputHandler (i.e. keyboard),
210+
getJdata_UserName(), shirtCol, faceCol)); // Username, shirt colour and face colour.
211+
level.addEntity(player); // Add the specified player to the level
205212
}
206213

207214
public static void setMap(int map) {
@@ -272,14 +279,17 @@ public static boolean[] getAlternateCols() {
272279
return alternateCols;
273280
}
274281

282+
// Sets alternateCols to a new boolean array (with size 2)
275283
public static void setAlternateCols(boolean[] alternateCols) {
276284
Game.alternateCols = alternateCols;
277285
}
278286

287+
// Sets the second/last element (face colour) of alternateCols to true or false
279288
public static void setAlternateColsR(boolean alternateCols) {
280289
Game.alternateCols[1] = alternateCols;
281290
}
282291

292+
// Sets the first element (shirt colour) of alternateCols to true or false
283293
public static void setAlternateColsS(boolean alternateCols) {
284294
Game.alternateCols[0] = alternateCols;
285295
}

0 commit comments

Comments
 (0)