Overview

This notebook breaks down the arrays and booleans used in GameLevelAquaticGameLevel.js.

Note: the game file is written in JavaScript, not Java. The ideas map directly to Java: arrays are lists of items, and booleans are true or false flags that control logic.

Code Categories in the Aquatic Game Level

This notebook now groups the GameLevelAquaticGameLevel.js code into three major coding categories: Control Structures, Data Types, and Operators.

1. Control Structures

Control structures decide how the code flows.

Iteration

The game uses looping ideas when creating collectible starfish and processing repeated game objects.

const positions = [];
positions.push({ x, y });

This pattern is part of repeated logic: the game keeps generating and storing positions until it has enough valid starfish locations.

Conditionals

Conditionals make decisions based on game state.

if (!this.dialogueSystem) return;
if (questState.accepted) {
  // show quest progress or next dialogue
}

These if statements decide what should happen depending on whether the dialogue system exists and whether the player accepted the quest.

Nested Conditions

The game can also use conditions inside other conditions when it checks one state and then reacts differently inside that branch.

if (questState.accepted) {
  if (!questState.started) {
    // spawn starfish and begin quest
  }
}

This is a nested conditional because one if is placed inside another.

2. Data Types

Data types describe what kind of values the game stores and uses.

Numbers

Numbers are used for coordinates, totals, dimensions, and counters.

starfishTotal: 8,
collected: 0

These values count how many starfish exist and how many the player has collected.

Strings

Strings store text such as dialogue and messages.

dialogues: ['Starfish collected!']
dialogues: ["I've lost all my starfishes..."]

These strings are shown to the player during the quest.

Arrays

Arrays store lists of related values.

const pattern = [
  [5,0], [4,1], [5,1], [6,1]
];

const starfishSprites = [
  createPixelStarfish('#ffb347', '#e07b39'),
  createPixelStarfish('#ff7aa2', '#d85b7e')
];

The pattern array stores pixel locations, and starfishSprites stores multiple sprite variations.

Booleans

Booleans store true or false values.

accepted: false,
started: false,
visible: false

These are used as flags to control quest progress and hidden barriers.

Objects

Objects group related properties together.

const questState = {
  accepted: false,
  started: false,
  starfishTotal: 8,
  collected: 0
};

This object keeps all quest-related information in one place.

{ class: Player, data: playerData }

This object is also used inside this.classes to describe a game object and its data.

Operators in the Aquatic Game Level

Operators tell the program how to combine, compare, or change values.

1. Mathematical Operators

Mathematical operators are used with numbers for counting, coordinates, and calculations.

collected + 1
x + 20
y - 10

These examples show arithmetic like addition and subtraction, which are common in game positioning and score tracking.

2. String Operations

String operations work with text values.

'Starfish collected!'
"I've lost all my starfishes..."

Even when the code is not doing heavy string concatenation, it still uses string values as dialogue, labels, and messages. If combined dynamically, JavaScript would use + to join strings.

'Collected: ' + questState.collected

That kind of operation builds text by combining a string with a number.

3. Boolean Expressions

Boolean expressions evaluate to true or false. They are especially important for quest logic.

if (!this.dialogueSystem) return;
if (questState.accepted) { ... }
if (!questState.started) { ... }

These expressions use logic operators and conditions to control what the game should do next.

4. Comparison and Assignment Ideas

The game also relies on assignment and property updates.

questState.accepted = true;
questState.collected = 0;

The = operator assigns a value. In conditions, the code may also use comparison operators like ===, <, or > when checking progress or object positions.

Why These Categories Matter

Looking at the Aquatic game level through these categories makes the file easier to understand:

  • Control Structures explain the flow of the game.
  • Data Types explain what information the game stores.
  • Operators explain how the code changes and checks that information.

This is a helpful way to read any game file, because it separates what the game knows, what the game does, and how the logic is written.

For more background on these topics, use our CSSE1 lesson pages:

Play the Aquatic Game Level

You can also explore the Aquatic level directly below using the game runner.

Challenge

Lines: 1 Characters: 0
Game Status: Not Started