Back to Blog

The Gems Said NO ๐Ÿšซ๐Ÿ’Ž | Gaming Life Ep.5

Celest KimCelest Kim
โ€ข

Video: The Gems Said NO ๐Ÿšซ๐Ÿ’Ž | Gaming Life Ep.5 by Taught by Celeste AI - AI Coding Coach

Take the quiz on the full lesson page
Test what you've read ยท interactive walkthrough
โ†’

The Gems Said NO ๐Ÿšซ๐Ÿ’Ž | Gaming Life Ep.5

In this episode, Bug and Loopi try their hand at a match-3 puzzle game that refuses to cooperate. The gems unpredictably slide too far, reshuffle combos, and even dodge the player's touch, turning a simple game into a chaotic challenge.

Code

// Simple simulation of a match-3 board where gems "dodge" the player's moves
const boardSize = 5;
let board = [];

// Initialize board with random gem colors
function initBoard() {
  const colors = ['๐Ÿ”ด', '๐Ÿ”ต', '๐ŸŸข', '๐ŸŸก', '๐ŸŸฃ'];
  for (let i = 0; i < boardSize; i++) {
    board[i] = [];
    for (let j = 0; j < boardSize; j++) {
      board[i][j] = colors[Math.floor(Math.random() * colors.length)];
    }
  }
}

// Attempt to swap two gems, but gems might "dodge" and swap different positions
function attemptSwap(x1, y1, x2, y2) {
  // 50% chance gems dodge and swap different random positions instead
  if (Math.random() < 0.5) {
    const rx1 = Math.floor(Math.random() * boardSize);
    const ry1 = Math.floor(Math.random() * boardSize);
    const rx2 = Math.floor(Math.random() * boardSize);
    const ry2 = Math.floor(Math.random() * boardSize);
    console.log(`Gems dodge! Swapping (${rx1},${ry1}) and (${rx2},${ry2}) instead.`);
    [board[rx1][ry1], board[rx2][ry2]] = [board[rx2][ry2], board[rx1][ry1]];
  } else {
    console.log(`Swapping (${x1},${y1}) and (${x2},${y2}) as requested.`);
    [board[x1][y1], board[x2][y2]] = [board[x2][y2], board[x1][y1]];
  }
}

// Display the board in console
function printBoard() {
  for (let row of board) {
    console.log(row.join(' '));
  }
  console.log('---');
}

// Demo gameplay
initBoard();
console.log('Initial board:');
printBoard();

// Player tries to swap two adjacent gems
attemptSwap(1, 1, 1, 2);
printBoard();

// Player tries another swap
attemptSwap(2, 2, 2, 3);
printBoard();

Key Points

  • Match-3 games rely on predictable gem swaps to create combos and clear the board.
  • Introducing randomness or "dodge" behavior can frustrate players by breaking expected game mechanics.
  • Simulating gem dodging involves swapping unexpected positions instead of the player's intended move.
  • Such unpredictable behavior can be used humorously or to increase game difficulty.
  • Visual and gameplay feedback is essential to communicate when the game is "rebelling" against the player.
Ready? Take the quiz on the full lesson page โ†’
Test what you've learned. Watch the lesson and try the interactive quiz on the same page.
โ†’