project09 - snake game functional!

This commit is contained in:
2025-11-09 13:01:01 -05:00
parent 59f9433b2b
commit 9c5d755f03
7 changed files with 683 additions and 0 deletions

54
09/Snake/Random.jack Normal file
View File

@@ -0,0 +1,54 @@
/*
Random Number Generator
Original author: Taylor Wacker
Modified by: Connor McKay, Sean O'Connor
https://gist.github.com/greneholt/2212294
This is a pseudo random number generator that uses the
Linear Congruential Generator (LCG) to generate random
numbers.
*/
class Random {
static int x;
/*
Sets a new seed value.
*/
function void seed(int seed) {
let x = seed;
return;
}
/*
Returns a mod b. b must be positive.
*/
function int mod(int a, int b) {
if (a < 0) {
let a = -a;
}
while ((a + 1) > b) {
let a = a - b;
}
return a;
}
/*
Returns the next random number. Can be negative or positive.
*/
function int next() {
let x = 7919 + (17*x);
return x;
}
/*
Returns a random value between x (inclusive) and y (non-inclusive).
y must be greater than x.
*/
function int between(int x, int y) {
var int diff;
let diff = y - x;
return Random.mod(Random.next(), diff) + x;
}
}