12.1b — Grid/Symmetry Jam: Build Day 1
Core-loop day again (10.1b rules, grid edition): by the end of class, a board exists in DATA, one move works end to end, and the win/lose stub prints. The one new idea today is the data structure that runs half the games ever made: a 2D array.
Step 1 — the board as data (list of lists):
const int W = 8; const int H = 8;
private int[,] grid = new int[W, H]; // 0 = empty, 1 = player, 2 = wall...
// or the AP way — a list OF lists:
// grid[ROW][COL] — the exam writes aList[r][c] exactly like this
Print the whole grid to the console each frame for now — Debug.Log(...) row by row. You must be able to READ your board in text before you can trust it in sprites.
Step 2 — one move. The player cursor at (x, y): W/S/A/D changes it by ±1 — but ONLY inside the array's bounds. The two bugs of every grid game, met now:
int nx = x + dx;
int ny = y + dy;
if (nx >= 0 && nx < W && ny >= 0 && ny < H) // BOUNDS — always
{
x = nx;
y = ny;
}
Step 3 — the symmetry hook. Whatever your
pitch promised, wire the CHEAPEST version of it today: mirror
the cursor on the other half (x2 = W - 1 - x — one
line!), or spawn the enemy AI at the mirrored start. That one
line IS the design; everything else elaborates it.
Step 4 — lose/win stub. Touch a hazard cell → print "lose"; reach the far cell → print "win". The loop exists even if nothing is drawn.
Socratic: The Board Exists in Data
- The board exists in data before anything draws it. What did printing the grid let you check that looking at the screen could not?
- Every grid is two numbers standing in for one thing. What is the index of your centre cell, and what would you have to change to make the board twice as wide?
- One move works end to end today. What is the second move, and does your data structure already have room for it or does it need reshaping?
Checkpoint — before moving on, you must be able to:
- Build and PRINT a grid; explain grid[y, x] row-first
- Move a cursor with bounds checks on both sides
- Wire the cheapest version of your symmetry in one line
- End the day with the loop running in text
Reference Docs
Need a deeper explanation? These pages cover the same concepts:
- Lists & Arrays — 2D and bounds patterns
- Unit 12: Season 2 — jam days map
Saved on this device only — the Dashboard tracks your progress.