Gameplay in HTML5: Homework #5
Create a PlayingCards.js module that provides some constants and functions for handling the standard set of (French/English) playing cards. Consider these ideas:
- What is the simplest way to represent a card?
- What is the simplest way to represent a deck of cards?
- Write a function,
newDeck() that returns a deck of cards. (Use a parameter to specify a sort or shuffled deck.)
- Write a function that provides a string representation of a card. (This is very handy for testing and debugging.) Consider one that writes a long name like "10 of Spades" and one that writes something more compact like "10♠". (Yes, Unicode includes symbols for card suits.)
- For FreeCell, what other information about a card (or the cards in general) might be useful to make public?
Create a FreeCellModel.js module that maintains and manages the state of a game of FreeCell. Consider these ideas:
- Cards can be in the deck, tableaux, cells, and foundations. How should these be represented?
- What must happen before the player can begin playing?
- The main operations of the game are moving cards from one of these places to another. What situations or rules govern this?
- What is a simple way to represent these locations?
- You should separate the action of picking up a card from that of putting it down. What rules govern each?
- What should you do when the player attempts to violate these rules? (I am not suggesting punishment.)
- Can a card not be in any of the four location groups listed earlier? What information will the model need to know in that case?
- When is the game over?
- Think primarily in terms of the public API. What will the View need to know about the model? What will the Controller need to be able to do?
- For this type of game, the Model should not be concerned with where or how things are displayed on the screen.
In the above module, write a
print() function that uses
console.log() to display the current state of the game. Use it to test the
- Archive your files. E.g.:
tar -czvf Gameplay_5_MyName.tgz directory
(Please do not include jquery.js or modernizr.js files in the archive. Links are OK.)
E-mail the archive to the instructor.