/lab-javascript-clue

An exercise to practice JavaScript objects (as hashes) and arrays

Primary LanguageJavaScript

logo_ironhack_blue 7

JS | Clue - Mixing objects and arrays

Do you remember de classic detective game?

Clue was a very popular game in the 90's. The plot starts with Mr. Boddy being killed by one of his guests. He was the very rich owner of Tudor Close, who takes the stock character of a generic victim. After his dead, Clue players have to discover who murdered him, with what implement, and where the crime scene took place in his mansion.

Hasbro, the toy maker company and owner of Cluedo, recently changed some of the characters bio. Use the bio to gather information from the characters.

Clue Picture

Requirements

  • Fork this repo
  • Clone this repo

Submission

  • Upon completion, run the following commands

    git add .
    git commit -m "done"
    git push origin master
    
  • Create Pull Request so your TAs can check up your work.

Deliverables

Write your JavaScript in the provided src/clue.js file.

Iteration 1 - Creating the cards

Clue has three different types of cards: suspects, rooms, and weapons. These three types of cards are always separated. Use data structures to model and create these cards.

In order to do this, you will need to know the game's characters (possible killers), available weapons and house rooms.

Game Characters

This Clue board game has a new roster of playable characters. All of them have first names, last names, occupations, age, description, and images. On the clue.js file you will find all the info about them.

Available Weapons

There are nine weapons. Each of them has different weight, same as the characters, you will find all the info needed on the clue.js file.

House Rooms

The game board represents the blueprints of a mansion and features fifteen different rooms. Yes, you guess, on the clue.js file you have all the info.

Data Structuring

Create one data structure for each of the people, weapons, and rooms described above. Each document must have all the info.

After creating the data structure, create an array for each type of data and push every document into their corresponding array.

For example:

const mrGreen = {
  first_name: "Jacob",
  last_name: "Green"
  // ...
};

const rope = {
  // properties
};

// etc

After creating the data structure, put every document into their corresponding array. charactersArray, weaponsArray, roomsArray.

Iteration 2 - Creating the mystery

At the beginning of the game, players shuffle each one of the card stacks to create a combination of suspect, weapon and room. This will be the mystery to solve.

Remember our tests!

We will be working with test again! You need to open the SpecRunner.html file in order to see them. The following instructions will guide you through all the functions and functionality your code should have to pass all the tests.

Random Selector

Create a function randomSelector to randomly select one element from a card stack. The method should receive an array as an argument, and return randomly one of the elements of the array.

Create the mystery

We need to create a pickMystery function that will call randomSelector for each card stack, and return an object with the 3 picked cards, a suspect, a weapon and a room. Our mystery should be stored on a mysteryEnvelope variable.

Iteration 3 - Revealing the mystery

Finally, we need to reveal the mystery. Create a revealMystery function, that will receive our mysteryEnvelope object as an argument and return the revealed mystery like this:

<FIRST NAME> <LAST NAME> killed Mr. Boddy using the <WEAPON> in the <ROOM>!!!!

Extra Resources