Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 93 additions & 5 deletions pacman.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
// Setup initial game stats
let score = 0;
let lives = 2;
let powerPellet = 4;


// Define your ghosts here

// replace this comment with your four ghosts setup as objects

const inky = {
menu_option: '1',
name: 'Inky',
colour: 'Red',
character: 'Shadow',
edible: true
};

const blinky = {
menu_option: '2',
name: 'Blinky',
colour: 'Cyan',
character: 'Speedy',
edible: true
};

const pinky = {
menu_option: '3',
name: 'Pinky',
colour: 'Pink',
character: 'Bashful',
edible: true
};

const clyde = {
menu_option: '4',
name: 'Clyde',
colour: 'Orange',
character: 'Pokey',
edible: true
};

ghosts = [inky, blinky, pinky, clyde]

function is_edible(ghost) {
if (ghost.edible) {
return 'edible'
} else {
return 'inedible'
}
}

// Draw the screen functionality
function drawScreen() {
Expand All @@ -23,12 +62,17 @@ function clearScreen() {
}

function displayStats() {
console.log(`Score: ${score} Lives: ${lives}`);
console.log(`Score: ${score} Lives: ${lives} Power Pellets: ${powerPellet}`);
}

function displayMenu() {
console.log('\n\nSelect Option:\n'); // each \n creates a new line
console.log('(d) Eat Dot');
console.log('\(d) Eat Dot');
console.log('(p) Eat Power Pellet');
console.log(`(1) Eat Inky (${is_edible(ghosts[0])})`);
console.log(`(2) Eat Blinky (${is_edible(ghosts[1])})`);
console.log(`(3) Eat Pinky (${is_edible(ghosts[2])})`);
console.log(`(4) Eat Clyde (${is_edible(ghosts[3])})`);
console.log('(q) Quit');
}

Expand All @@ -44,6 +88,31 @@ function eatDot() {
score += 10;
}

function eatPowerPellet() {
console.log('\nChomp!');
score += 50;
powerPellet --;
}

function isGameOver() {
if (lives == 0) {
process.exit();
}
}

function eatGhost(ghost) {

if (ghost.edible) {
console.log(`\nChomp!\n${ghost.name} is ${ghost.character}`);
score += 200;
ghost.edible = false;
} else {
console.log(`\nChomp!\n${ghost.name} has killed Pac Man`);
lives --;
}
isGameOver();
}


// Process Player's Input
function processInput(key) {
Expand All @@ -55,6 +124,25 @@ function processInput(key) {
case 'd':
eatDot();
break;
case 'p':
if (powerPellet == 0) {
console.log('\nNo Power-Pellets left!');
} else {
eatPowerPellet();
}
break;
case '1':
eatGhost(ghosts[0]);
break;
case '2':
eatGhost(ghosts[1]);
break;
case '3':
eatGhost(ghosts[2]);
break;
case '4':
eatGhost(ghosts[3]);
break;
default:
console.log('\nInvalid Command!');
}
Expand Down