Due: Friday, Oct. 9th by 8:00pm
As with previous CS 105 MPs, we have provided a base set of files for you inside of a ZIP file that you must extract:
For the project, there is one file and then several directories inside of the ZIP file:
players directory contains the code for the players you will
create for the Hunger Games.
js directory contains files needed to run the contest. It
is all JavaScript so you can look at it to see all of the things JavaScript can do,
but you will not need to edit anything inside of this directory.
res directory contains resource files for the contest.
This includes images, stylesheets (CSS), and other things that make this
contest look somewhat pretty.
cs105HungerGames.html file is the HTML file you will open
in your web browser to run the contest on your computer.
In the players directory, you will find
hueTheHunter.js contains the following code:
var player = {
// Enter the name of this player in CS 105's Hunger Games
// (When submitted, this `name` WILL appear on the contest page. You can
// use whatever name you would like, it should probably not be your real name,
// but it should be clean and not disrespectful.)
name: "Hue the Hunter",
// Program the makeDecision function to play in the contest!
makeDecision: function(me, partner, capital) {
return "h";
}
};
This is the code for Hue the Hunter. The player variable
is a JavaScript object that contains two keys: name (a String) and
makeDecision (a function). The makeDecision will
be called every time a hunting decision needs to be made:
makeDecision must return "h"
makeDecision must return "s"
makeDecision returns any other value (or no value at all),
is it incorrect.
Since Hue the Hunter always hunts, the makeDecision returns "h".
We need at least two players to play CS 105's Hunger Games. Let's create Sam the Slacker who will always slack off:
players directory, copy hueTheHunter.js,
paste it, and rename the new version samTheSlacker.js.
samTheSlacker.js in a text editor like Atom.
name to "Sam the Slacker"
makeDecision to "s"
The last thing we must do is add Sam the Slacker to CS 105's Hunger Games. We do this by adding an HTML script tag to tell the web browser where to find the code for the player:
cs105HungerGames.html in a text editor.
<!-- Players in the CS 105 Hunger Games Goes Here -->
<script type="text/javascript" src="players/samTheSlacker.js"></script>
If you completed everything correctly so far, you can run your very first CS 105 Hunger Games!
cs105HungerGames.html in a web browser.
If everything works, you should be able to watch CS 105's Hunger Games unfold before your very eyes! Specifically, Hue the Hunter should always be hunting and Sam the Slacker should always be slacking: