CS2 JavaScript Project 2024 🎰

<<< Back to main site

Due Date: Thursday, November 7, 2024

Need help? Remember to check out Edstem and our Website for TA help assistance.

Background 🎰

Be sure to read all background notes, as they are vital to do the assignment.

Assignment Goals

Resources

Reminder: This project must be completed by yourself, without the help of any other students or resources not mentioned in the resource section.

Project Description 🎰

Oh no! Don's Casino is packed with customers and the dealers are overwhelmed. We need your help to deliver the poker chips to the playing tables. Your task is to use what you've learned in the Javascript lab to navigate around the maze-like casino floor.

Tasks 🎰

Setup

Task 0: Double click your "CS2" folder on your desktop, and create (or enter) your folder for JavaScript. Then, create a new folder inside called JavaScript Project. All your files for the project should live in this folder.

Task 1: Begin by downloading the stencil here.

This project consists of four files:

  1. index.html
  2. donsCasino.js
  3. donsCasino.css
  4. stencil.js

Put all downloaded files into your JavaScript folder. This is the folder you will zip at the end of the assignment to turn in on Canvas.

To view what the casino looks like, simply open your index.html file in Chrome.

IMPORTANT NOTE: The required tasks do NOT require you to alter any files other than the stencil.js file. The only code you write should be in stencil.js.

Documentation

We have provided some code for you to use in the project. This code is located in donsCasino.js. It's okay if you don't completely understand what is happening in the functions in this file!! We have provided general descriptions of these functions below. You can call these functions on the variables to make them do things in stencil.js.

Poker Chip Functions 🎰

These all must be called on the pokerChip object.

Casino Functions 🎰

This must be called on the casino object.

General Functions 🎰

How To Call Functions

There are two ways these functions can be called

  1. Functions for specific objects (eg. poker chip or casino) are called as follows:
object.function(param);

Example: To make the poker chip move left we would call its moveleft function using this syntax:

chip.moveleft();

And to call the casino’s changeCasinoBackground(color) we would use the syntax:

casino.changeCasinoBackground("red");
  1. General functions are called normally:
function(param);

Example: To get a random color, we would use the syntax:

getRandomColor();

You will be writing code in stencil.js. You do NOT need to modify anything in donsCasino.js. These functions are meant to be called within stencil.js.

Making Poker Chips

To complete an order successfully, you first need to prepare the poker chips.

Task 2: Drawing the Poker Chip
Open stencil.js. Begin by drawing red poker chips at location x=1, y=1. “Drawing” the poker chips is equivalent to placing a red square on the maze. Once you have completed this task, you should see a red square in the top left corner of the casino maze.

Uh oh! Sometimes you mess up the order or the dealer changes their mind about what value chip they want. When that happens you need to start all over again!

Task 3: Restarting an Order
Fill in the restart() function in stencil.js. To add the restart button functionality, you will need to write code in the function that reloads the whole page when the maze is restarted.

Remember to add an event listener for the restart button! This should be done at the bottom of the stencil file in the event handlers section. Think back to the Document Object Model that we learned in lab. What is the ID for the restart button in the HTML file?

Hint

You should look into reload for more information on how to do this.

Your poker chip must get from one end of the casino floor to the other in order to successfully deliver it to the dealer.

Task 4: Delivering Poker Chips to a Dealer
Add the ability to control the poker chips with the arrow keys by filling in the keyDown function and adding an event listener. This has two main components:

  1. The chips should be able to move with the 4 arrow keys in their respective directions. This will consist of 4 conditionals, 1 for each key event. You can use this website to find out which key maps to which keyCode value. To check a keycode value (in an if statement, for example), you’d write something like this:
if (keyCode === 38) { chip.moveUp(); }
  1. You will also have to add an event listener to the window corresponding to the function you just wrote. See this link for examples of how to use the keydown listener in JavaScript.

    Here’s an example of adding a listener to the window that listens to the function doSomething when keys are pressed:

window.addEventListener('keydown', doSomething);

Buttons

Task 5a: Changing the Casino Background
When the "New Casino" button is clicked, the casino background should be changed to a random color.

Recall that we have provided both a changeCasinoBackground() and a getRandomColor() function.

Hint

Remember to add an event listener for the button, as you did above with the restart button!

Do not create your own random color function; use our existing random color function (see Documentation)

Task 5b: Changing the Poker Chip values:
When the "New Poker Chip" button is clicked, the chips should be changed to a random color. This should look very similar to the function in Task 5a!

Debugging Advice

Completing the Order

Once your poker chip has reached the dealer, you should make sure they are happy with the order.

Task 6: Delivering Your Order
Try solving your maze! Once your poker chip square reaches the end of the maze, a popup should appear that reads “Congrats! You succesfully delivered the chips!” This is already implemented for you.

Extra Credit 🎰

3 points: Add an extra button with JavaScript functionality of your choice.

This would require you to change the index.html file to add a button and id. Your chosen functionality must be sufficiently different from the project requirements (e.g. a button to make the background blue wouldn't count), and it MUST use some sort of Javascript. It cannot just link to a website (this can be done in HTML). Some ideas are:

2 Points: Add a score tracker. This would require you to add an element to the index.html file that displays the number of steps your chip has taken in the format “Score: x” where x is the number of key strokes made to solve the maze. You would need a score counter variable in your Javascript file that increments every time you move your poker chip.

Hand-In 🎰

To Hand-In Project 4:

For this assignment, your submission should include the JavaScript file stencil.js with the completed functions. Be sure to also include the original HTML file and the original CSS and JS files with no changes (unless you made edits for extra credit).

Your files should look like this at submission:

    JavaScript Project
    ├── donsCasino.css
    ├── donsCasino.js
    ├── index.html
    ├── stencil.js
  1. Make sure your source files do not contain your name. This is especially important in order to maintain the course’s anonymous grading policy that ensures your assignments are graded fairly. We will deduct points if your files contain identification data.

  2. Make sure you have the correct, most up-to-date files before zipping. We’ve had students in the past send in older versions that didn’t contain all their finished work! You will receive a 10pt deduction if TAs must regrade your work due to incorrect files.

  3. Create a .zip file from your JavaScript Project folder.

    Windows:

    In Windows Explorer, go to the folder containing the files you want to zip. Select the files, then right-click on any of the selected files and select Send To… -> Compressed (zipped) Folder.

    Mac:

    In Mac Finder, go to the folder containing the files you want to zip. (This would be your “JavaScript Project” folder) Select the files, then right-click on any of the selected files and select Compress Items.

  4. Right click on the newly created zip file to rename it. The name of your file should be BannerID_JavaScriptProject.zip (replace "BannerID" with your own banner id, starting with B0...)

  5. Submit on Canvas under the JavaScript Project assignment!

Congrats! You just finished the Javascript Project! :slot_machine:

If you have any issues with completing this assignment, please reach out the course HTAs: cs0020headtas@lists.brown.edu

If you need to request an extension, contact Professor Stanford directly: don.stanford@gmail.com