All subjects

PF 101 · BSIT

Object-Oriented Programming

Midterm is the Fighter Arena roster. Pre-final is a new garage: Ride Start — Jeepney, habal, tsinelas with start() and sakay(n).

Four pillars → arena roster → a new garage

  1. DAY 01

    Name the four pillars and the Git basics

  2. DAY 02

    A class that runs in Node and lives on GitHub

  3. DAY 03

    See the Fighter Arena finish line

  4. DAY 04

    Read the starter hierarchy file by file

  5. DAY 05

    Uncomment until two fighters can fight

  6. MIDTERM

    Add Warrior, Witch, and more — ship your roster

  7. PRE-FINAL

    Ride Start garage — start() + sakay(n), then Day 2 #maxPax + fare()

How to use this page

  1. 1

    Open each deck and walk it the same way we did in class.

  2. 2

    For every class in the arena, say which pillar it demonstrates before you open the file.

  3. 3

    For midterm: keep the starter working, add 3+ characters, then demo Warrior vs Witch (or your pair).

  4. 4

    For pre-final Day 1: new folder. Type start() and sakay(n). Close the laptop and write habal maxPassengers().

  5. 5

    For Day 2: same repo. Lock #maxPax. Add fare(n). Prove outside code cannot rewrite capacity.

Prelims coverage

From the four pillars and your first GitHub push through the Fighter Arena reveal, starter walkthrough, and guided uncomment lab.

01

What OOP is — and why Git matters

Four pillars + four Git words

Presentations from class

What you must be able to explain

  • OOP organizes code around objects that hold data and behavior together
  • The four pillars: classes & objects, inheritance, polymorphism, encapsulation
  • A class is a blueprint; an object is a living instance created with new
  • Inheritance builds a new class on top of an existing one with extends
  • Polymorphism: same method name, different behavior in subclasses
  • Encapsulation: an object protects its own data and exposes safe methods
  • Git fundamentals: repository, commit, remote, push — and why this course requires history
Student.jsblueprint + instance
class Student {
  constructor(name) {
    this.name = name;
  }

  greet() {
    return `Hi, I'm ${this.name}`;
  }
}

const jm = new Student('JM');
console.log(jm.greet());

Lines worth memorising

Class = blueprint. Object = the thing you actually use.

If you can name the four pillars with one example each, you are ready for the concept questions.

02

Write it, run it, protect it

VS Code + Node + first GitHub push

Presentations from class

What you must be able to explain

  • Install and configure VS Code, Node.js (LTS), and Git identity
  • Create a project folder and write a class file
  • Instantiate objects and call methods from Node
  • git init → add → commit → push to GitHub
  • The loop you will repeat all term: edit → run → commit → push
terminalfirst snapshot
git init
git add .
git commit -m "Add first Student class"
git branch -M main
git remote add origin https://github.com/YOU/repo.git
git push -u origin main

Lines worth memorising

If it runs in Node, commit it before you leave class.

A working file with no commit history is incomplete work in this course.

03

Fighter Arena — the finish line

Vision, scope, and where the pillars land in the game

Presentations from class

What you must be able to explain

  • Capstone goal: a local 2-player fighter built with JavaScript classes
  • Required gameplay: move, attack, health, win condition, on-screen feedback
  • Required OOP: Entity, Fighter, at least one subclass, Game (Arena encouraged)
  • What the project is not: online multiplayer, frameworks, huge character roster
  • Git history must show incremental work — starter-only submission is not enough

Lines worth memorising

Keep it simple. Ship it working.

All four pillars must appear in your own code — not only in the starter you uncommented.

04

How the starter is organized

One class per file — base classes before subclasses

Presentations from class

What you must be able to explain

  • Script order matters: Entity before Fighter before Melee/Ranged before Game
  • Entity holds position on the arena
  • Fighter adds encapsulation with #health, getHealth(), takeDamage()
  • MeleeFighter and RangedFighter override attack() — inheritance + polymorphism
  • Game owns the match (composition); UI reads game state onto the screen
  • Controls: P1 A/D + F · P2 ←/→ + L · R restart
fighter.jsencapsulation
class Fighter extends Entity {
  #health = 100;

  getHealth() {
    return this.#health;
  }

  takeDamage(amount) {
    this.#health = Math.max(0, this.#health - amount);
  }

  attack(target, now) {
    throw new Error('Subclass must implement attack()');
  }
}

Lines worth memorising

Swing first, check range second — attack begins, then distance decides the hit.

Private fields start with # — that is encapsulation in JavaScript.

05

Guided uncomment — build the game

STEP 1 → 5 until both fighters play

Presentations from class

What you must be able to explain

  • Fork/clone the student-starter into your own GitHub repo
  • Uncomment full class blocks in order: Entity → Fighter → subclasses → Arena → Game
  • Save and refresh after each step; commit after each step that works
  • When all steps are enabled, the arena is playable in the browser
  • Next: extend beyond uncomment-only work (new characters, polish, jump, UI)
melee-fighter.jspolymorphism
class MeleeFighter extends Fighter {
  attack(target, now) {
    if (!this.canAttack(now)) return false;
    this.beginAttackAttempt(now);
    if (this.distanceTo(target) > this.attackRange) return false;
    target.takeDamage(this.attackDamage);
    return true;
  }
}

Lines worth memorising

Uncomment the whole class block — half a class leaves the game broken.

Commit after each working step so your history proves you built it.

Midterm coverage

Continue the finished Fighter Arena — add Warrior, Witch, and more via inheritance, wire them into createGame(), and demo your roster. Follow ACTIVITY-add-characters.md (live preview on this site — same file as your fork).

Student guide

ACTIVITY-add-characters.md

Recipe, stats table, Witch/Dragon examples, facing (`artFacing`), submit checklist, and common mistakes — synced from the student-starter repo.

Open full guide
M1

Midterm

Add your fighters

Starter is done — midterm extends the playable arena

Presentations from class

What you must be able to explain

  • Midterm is not a Student.js restart or console-only redo
  • Baseline gate: Entity → Game uncommented and the match already plays
  • New leaves under MeleeFighter / RangedFighter — Warrior, Witch, Knight…
  • You do not rewrite Game or Arena — only add character classes and choose who fights
  • Guide of record: ACTIVITY-add-characters.md — open the live preview from this page or from your fork
class treewhere your characters sit
Entity
  └── Fighter
        ├── MeleeFighter
        │     ├── Warrior   ← you create
        │     └── Dragon
        └── RangedFighter
              └── Witch     ← you create

Lines worth memorising

Stop uncommenting. Start inventing.

Midterm bar: at least three original character classes in a playable match.

M2

Midterm

Warrior · Witch lab

File → script tag → createGame() → playable matchup

Presentations from class

What you must be able to explain

  • Create js/warrior.js that extends MeleeFighter with sprite + tuned stats
  • Load character scripts in index.html after the parent class
  • Swap constructors inside createGame() so your classes actually fight
  • Add Witch extends RangedFighter — demo Warrior vs Witch
  • Optional stretch: override attack() for a special rule (true polymorphism)
js/warrior.jsinherit attack, change numbers
class Warrior extends MeleeFighter {
  constructor(name, x, controls) {
    super(name, x, controls);
    this.spritePath = 'images/characters/warrior.png';
    this.attackStyle = 'melee';
    this.speed = 5;
    this.attackRange = 75;
    this.attackDamage = 18;
  }
}
globalThis.Warrior = Warrior;

Lines worth memorising

Wrong script order → Warrior is not defined.

If createGame still uses MeleeFighter/RangedFighter defaults, the roster is not wired.

M3

Midterm

Roster checkpoint

3+ characters · playable match · demo + README

Presentations from class

What you must be able to explain

  • Submit your fork URL and demo a match with two of your characters
  • README lists each class → what it extends → flavor/stats
  • Commit after each working character — not one dump named final
  • Explain inheritance and polymorphism using your own roster aloud
  • Optional stretch only: character select variables, armor takeDamage, custom Fighter attack
  • Bonus (extra credit if offered): animated sprite sheets — see Module B+ and ACTIVITY-sprite-animations-bonus.md
js/main.jsdemo pair
const p1 = new Warrior('Warrior', 80, P1_CONTROLS);
const p2 = new Witch('Witch', arenaEl.clientWidth - 140, P2_CONTROLS);
return new Game(p1, p2, new Arena(arenaEl.clientWidth));

Lines worth memorising

Rename-only copies of Melee/Ranged without real changes do not pass.

A playable browser match is the midterm proof — not a console print alone.

B+

Bonus · Midterm stretch

Sprite attack animations

Optional stretch — animated Warrior & Witch after PNG roster is done

Presentations from class

What you must be able to explain

  • Bonus does not replace the midterm bar — finish 3+ PNG characters first
  • Copy images/sprites/, sprite-clips.js, sprite-renderer.js from the demo branch
  • Replace fighter img with canvas; load new scripts before character classes
  • Add spriteClips + display width/height on Warrior and Witch only
  • Knight / Dragon / Samurai without spriteClips keep static PNG on canvas
  • Reference branch: feature/add-character-sprites — compare, understand, then implement
js/warrior.js hookafter midterm stats
this.spriteClips = WARRIOR_SPRITES;
this.artFacing = WARRIOR_SPRITES.display.artFacing;
this.width = WARRIOR_SPRITES.display.width;
this.height = WARRIOR_SPRITES.display.height;

Bonus activity guide

ACTIVITY-sprite-animations-bonus.md

Copy sprite sheets + renderer, switch to canvas markup, wire spriteClips on Warrior/Witch. PNG roster still required for midterm.

Open guide

Lines worth memorising

Game still calls attack() — you only upgraded how fighters look.

Sheet artFacing differs from PNG: Warrior sheets = 1, Witch sheets = -1.

Pre-final · Ride Start

New project. Not another fighter. You type Jeepney, Tricycle, Habal, and friends. Garage calls start() and sakay(n) and never asks the type. Habal max 3 — ten sakay is illegal recruitment.

01

Pre-final

Ride Start

Same Start button — different shout per ride

What you must be able to explain

  • Pre-final is a new folder. Fighter, Game, and attack() stay in midterm
  • Jeepney, Tricycle, Motorcycle extend Ride — same pillars, PH objects
  • start() is the method name. Different string per ride
  • Garage has rides — composition, not another fighter subclass
  • Simple UI: pick a ride, press Start
start()memorise these
Jeepney     →  "Para!"
Tricycle    →  "Broom broom"
Motorcycle  →  "Vroom"   // habal-habal
Tsinelas    →  "Slap slap — late na!"

Lines worth memorising

If Garage writes instanceof, the magic is dead.

Adding Tsinelas must not change Garage.

02

Pre-final

Sakay and capacity

Habal max 3 — ten is illegal recruitment

What you must be able to explain

  • maxPassengers() is different per ride
  • sakay(n) lives on Ride — checks the max, then boardOk()
  • Habal-habal max is 3. Bike and tsinelas max is 1
  • Garage only calls sakay(n) — it does not know Habal vs Jeep
Ride.sakay(n)parent logic
if (n > this.maxPassengers()) {
  return 'Pffft… illegal recruitment. Max '
    + this.maxPassengers() + ' lang dito.';
}
return this.boardOk(n);

Lines worth memorising

Capacity is polymorphism too — same sakay name, different max.

Students should demo 10 then 2 on habal.

03

Pre-final

Defend the garage

Start + Sakay on screen. Max on paper.

What you must be able to explain

  • Demo Start and Sakay for at least three rides
  • Paper: write Motorcycle.maxPassengers() from memory
  • Renaming Warrior to Jeepney is a fail — new project
  • Stretch: more rides (lantsa, nwow, tsinelas) — Garage unchanged

Lines worth memorising

Looks fine on screen + blank paper = they never owned the code.

04

Pre-final

Private, Fare, Boarded

#maxPax + #boarded. fare() + startAll()

What you must be able to explain

  • Day 2 is the same repo (~90–120 min) — Track B after Day 1 works
  • #label, #maxPax, #fareRate, #boarded — outsiders cannot cheat
  • fare() uses private rate; fareTag() is the polymorphic flavor
  • sakay / alight update #boarded via seatsLeft()
  • Garage.startAll() loops every ride — still no instanceof
startAll()Day 2
startAll() {
  return this.#rides
    .map((r) => r.label + ': ' + r.start())
    .join(' · ');
}

Lines worth memorising

Private means outside code cannot rewrite capacity or aboard count.

startAll() is polymorphism in a loop — one call, many shouts.

Cheat sheet

Midterm names the arena. Pre-final names start() and sakay(n). Exams can ask for both.

The four pillars

01

Classes & Objects

A class is the blueprint; an object is a living instance created with new.

class Fighter { … } → new MeleeFighter(…)

02

Inheritance

A subclass reuses and extends a parent with extends and super.

MeleeFighter extends Fighter

03

Polymorphism

Same method name, different behavior depending on the subclass.

melee.attack() ≠ ranged.attack()

04

Encapsulation

Data stays private; outsiders use safe methods to read or change it.

#health + getHealth() / takeDamage()

Class → object

class Student {
  constructor(name) {
    this.name = name;
  }

  greet() {
    return `Hi, I'm ${this.name}`;
  }
}

const a = new Student('Ana');
const b = new Student('Ben');

The class is the blueprint. new builds a living object you can call methods on.

Inheritance + polymorphism

class Fighter extends Entity {
  attack(target, now) {
    throw new Error('Subclass must implement attack()');
  }
}

class MeleeFighter extends Fighter {
  attack(target, now) { /* close range */ }
}

class RangedFighter extends Fighter {
  attack(target, now) { /* longer range */ }
}

Both fighters share attack(), but melee and ranged behave differently when that method runs.

Encapsulation — private health

class Fighter extends Entity {
  #health = 100;

  getHealth() {
    return this.#health;
  }

  takeDamage(amount) {
    this.#health = Math.max(0, this.#health - amount);
  }
}

Outside code cannot write fighter.#health = 0. It must go through takeDamage() or read via getHealth().

Fighter Arena class map

ClassFileRole
Entityjs/entity.jsBase position on the arena
Fighterjs/fighter.jsPrivate health, move, attack hook
MeleeFighterjs/melee-fighter.jsClose-range attack() override
RangedFighterjs/ranged-fighter.jsLonger-range attack() override
Arenajs/arena.jsKeep fighters on stage / bounds
Gamejs/game.jsOwns the match, loop, win check

Enable order in the guided lab: Entity → Fighter → Melee/Ranged → Arena → Game

Git words you need

repository

The project folder Git is tracking — local or on GitHub.

commit

A named snapshot of your files at a moment in time.

remote

The copy of the repo hosted on GitHub.

push

Upload your local commits to the remote.

Check yourself

Answer out loud first, then reveal. If you can explain these without notes, you are ready.