Lecture 11

An Intro to Modern Software Engineering with Snake: IDEs, Git, GUIs, and Agentic Coding

A reader-oriented guide to setting up a real development workflow, understanding GUI programming in Java Swing, working with Git and GitHub, and building a Snake game with both inline and agentic AI.

Java 17 VS Code Git + GitHub Swing Copilot / Claude
Mental Model

In this course, Snake is not just a game project. It is the vehicle for learning how modern software is actually built: with editors, terminals, repositories, libraries, prompts, tests, debugging, and revision.

Read these slides as a textbook chapter. Every major term is defined when it first matters.

Part 1

The Big Picture

What this project is really teaching about software, tools, and workflow.

Part 2

Core Ideas Before Setup

Before installing tools, define the vocabulary. If the terms are vague, the workflow becomes vague too.

The Git Cycle

flowchart LR A[Edit files in VS Code] --> B[git add] B --> C[git commit] C --> D[git push] D --> E[GitHub stores history] E --> A
The most common beginner confusion is the difference between commit and push. A commit saves history on your machine. A push sends that history to GitHub.
Part 3

Install Java and VS Code

The point of setup is not to collect tools. The point is to make sure your machine can compile and run Java reliably before the project gets more complex.

Java in One Small Diagram

flowchart TD JDK[JDK
what you install] --> COMP[javac compiler] JDK --> LIB[standard library
includes Swing] JDK --> RUN[runtime tools]
For this class, the only safe beginner rule is simple: install the JDK, not just a runtime.
Part 4

Create the Repository and Open It in VS Code

This is where the work stops being "a file on my laptop" and becomes a real project with history.

What VS Code Should Look Like Now

Explorer

You should see the snake-game folder and its files in the Explorer panel.

Good sign: README.md is visible.
Bad sign: you only opened one file, not the folder.
Source Control

Source Control should be available in the sidebar because the open folder is a Git repository.

Good sign: the branch and repo are recognized.
Bad sign: VS Code says the folder is not under source control.
If the folder is not recognized as a repository, stop and fix that before writing project code.

Your First Commit in the Real Project

git add .
git commit -m "Add HelloSnake.java setup check"
git push
A useful commit message should say what changed. Avoid vague messages such as fixed stuff.
Part 5

What Swing Is and Why It Matters

GUI code can look unfamiliar at first, but it is still ordinary Java plus a library for building windows and drawing components.

Important Swing Terms

JFrame

The main application window. If the program opens a visible window, that outer window is often a JFrame.

JPanel

A rectangular area inside a window. For a simple game, the panel is often where drawing happens.

Component

A visible GUI element. Frames, panels, buttons, and labels are all components.

paintComponent

A method that Swing calls when a panel needs to redraw itself.

Graphics

An object that gives drawing commands such as rectangles, colors, and text.

Event

Something that happens while the program is running, such as a key press, a mouse click, or a timer tick.

Timer

A Swing object that can trigger code repeatedly after a chosen delay. In Snake, that repeated trigger becomes the game loop.

repaint

A request that tells Swing a component should be drawn again. It does not draw directly; it asks Swing to schedule a redraw.

The Smallest Useful Swing Example


import java.awt.*;
import javax.swing.*;

public class SimpleWindow extends JPanel {
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.GREEN);
        g.fillRect(40, 40, 120, 40);
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Simple Window");
        frame.setSize(400, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new SimpleWindow());
        frame.setVisible(true);
    }
}
  
Read this code as ordinary Java. The only major new thing is what kinds of objects are being created and what those objects know how to do.
Part 6

Editing a Tiny Swing Program with AI

This is where the difference between a small local edit and a larger structured request becomes concrete.

Starting File: SnakeStarter.java


import java.awt.*;
import javax.swing.*;

public class SnakeStarter extends JPanel {
    private final int gridSize = 20;
    private final int cellSize = 25;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(new Color(22, 28, 39));
        g.fillRect(0, 0, gridSize * cellSize, gridSize * cellSize);
    }
}
  
This file does not do much yet. That is intentional. Small, stable starting points are easier to extend safely.

Agentic AI Exercise: A Larger Structured Change

In SnakeStarter.java, add a main method that opens a 600x600 JFrame titled Snake Starter. Keep everything in one file. Add a starting snake that is three segments long and draw it in green on the panel. Do not add movement yet.

Why this is agentic work
  • it changes file structure
  • it introduces new imports and state
  • it coordinates several edits at once
What to verify afterward
  • the file still compiles
  • the window opens
  • the snake is actually visible
  • the AI did not add extra features you did not request
Part 7

Snake Deep Dive: The Actual Prompts

Here the prompts are written out explicitly. Each one has a software-design purpose, not just a coding purpose.

Prompt 1: Open a Window and Nothing More

I'm building a Snake game in Java using Swing. Create a single file called SnakeGame.java. It should have a main method that opens a JFrame window that is 600 by 600 pixels and titled Snake. Inside the frame, add a JPanel subclass called GamePanel. Do not add any game logic yet. Just get the window to open correctly.

Why this prompt exists

It creates a shell you can run immediately. If the shell does not work, you should not move on to game logic yet.

What to look for
  • correct imports
  • matching class names
  • a visible window
  • no extra features

Prompt 2: Draw a Board and a Starting Snake

Now extend SnakeGame.java. Keep it as one file. Add a dark background grid and draw a starting snake that is three segments long near the center of the board, facing right. Each cell should be a 30x30 pixel square. Draw the snake in green and the background in dark gray. Do not add movement yet.

This prompt is about representation. Before a game can move, it needs a way to store where things are.

Prompt 3: Add Movement and Keyboard Input

Make the snake move automatically using a Swing timer that ticks every 150 milliseconds. Add arrow key controls so the player can steer, but don't allow the snake to reverse direction. For now, have the snake wrap around the edges instead of dying. Make sure the panel can receive keyboard input.

flowchart LR A[Timer tick] --> B[Read direction] B --> C[Move head] C --> D[Redraw panel] D --> A
This is the central loop of the game. The loop is small, but it is conceptually important: update state, then redraw.

Prompt 4: Add Food, Growth, Score, and Game Over

Add a food pellet that spawns at a random empty cell. When the snake eats it, grow by one segment and spawn new food. Add collision detection: hitting a wall or the snake's own body should end the game, stop movement, and show a "Game Over" message with the final score. Display the current score in the top-left corner during play. When the game is over, let the player press R to reset everything and play again.

Food
creates reward
Game over
creates consequences and rules
Restart
closes the loop for the player
Part 8

Running, Debugging, and Recording the Work

A project is not complete when code exists. It is complete when the code can be run, explained, debugged, and revised deliberately.

A Simple Debugging Loop

flowchart TD A[Write or revise prompt] --> B[Get code] B --> C[Run program] C --> D{Works?} D -- Yes --> E[Commit and document] D -- No --> F[Read error or behavior] F --> G[Ask follow-up with evidence] G --> B
The key word here is evidence. Good follow-up prompts include the actual error message or the actual incorrect behavior.
Part 9

Where Snake Can Grow Next

Once the baseline game works, growth should still be controlled. Better projects are usually the result of disciplined additions, not random accumulation.

Related Projects

Everything you built for Snake lives in one file and one class. The same pattern transfers directly to classic Atari-era games — each one is a step up in complexity, not a different kind of problem.

Pong

Two paddles, one ball, collision detection, and a score counter. A natural first step: the only new idea over Snake is that two objects can both move independently.

LLM prompt strategy: describe the game state as fields first, then ask for the game loop, then drawing, then key input — one step at a time.

Breakout

A paddle, a bouncing ball, and a grid of destructible bricks. Adds a 2-D array for the brick layout and angle-based bounce logic.

LLM prompt strategy: prompt for the brick grid and collision first. Once destruction works, add the paddle and ball. Commit each working milestone.

Asteroids

A ship that rotates and thrusts, asteroids that split on impact, and limited bullets. Introduces double velocity, trigonometry for movement, and object lists.

LLM prompt strategy: ask for ship rotation and thrust before asteroids exist. Add one asteroid that wraps the screen. Then add splitting. Then bullets.

Frogger

A frog moves up a screen of moving traffic and river obstacles. Adds lanes of objects moving at different speeds and a lives system.

LLM prompt strategy: start with a single lane of cars. Once the frog can collide and die, add a second lane moving the opposite direction. The pattern repeats.

Missile Command

Missiles fall toward cities; the player intercepts them with explosions. Introduces mouse input, line-segment math, and a growing / shrinking explosion radius.

LLM prompt strategy: ask for a single falling missile and a click-to-explode response. Add the blast radius check before adding multiple missiles or cities.