mirror of
https://github.com/soconnor0919/eceg431.git
synced 2025-12-11 22:54:43 -05:00
project09 - snake game functional!
This commit is contained in:
56
09/Snake/Point.jack
Normal file
56
09/Snake/Point.jack
Normal file
@@ -0,0 +1,56 @@
|
||||
// Simple coordinate class for clean position handling
|
||||
// Provides basic x,y operations for snake and food placement
|
||||
class Point {
|
||||
field int x, y;
|
||||
|
||||
// create point at given coordinates
|
||||
constructor Point new(int ax, int ay) {
|
||||
let x = ax;
|
||||
let y = ay;
|
||||
return this;
|
||||
}
|
||||
|
||||
// free memory
|
||||
method void dispose() {
|
||||
do Memory.deAlloc(this);
|
||||
return;
|
||||
}
|
||||
|
||||
// get x coordinate
|
||||
method int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
// get y coordinate
|
||||
method int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
// update coordinates
|
||||
method void setX(int newX) {
|
||||
let x = newX;
|
||||
return;
|
||||
}
|
||||
|
||||
method void setY(int newY) {
|
||||
let y = newY;
|
||||
return;
|
||||
}
|
||||
|
||||
// check if this point equals another
|
||||
method boolean equals(Point other) {
|
||||
return (x = other.getX()) & (y = other.getY());
|
||||
}
|
||||
|
||||
// move point by offset
|
||||
method void move(int dx, int dy) {
|
||||
let x = x + dx;
|
||||
let y = y + dy;
|
||||
return;
|
||||
}
|
||||
|
||||
// copy this point to new point
|
||||
method Point copy() {
|
||||
return Point.new(x, y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user