A22.0005 - Computers in Principle & Practice II

Final Project - Spring 1997

Due: by 2:00 p.m., Thursday, May 15th

Projects should be turned in two ways:

1) Posted on your acf5 Web account under the name "final.html"

2) Put on a single 3 1/2" floppy disk, and turned in with complete, COMMENTED listings in an envelope to room 405, Warren Weaver Hall. (Do NOT put this into my mailbox!)

I have a working version of this program (which is much simplified from my original idea, you will be glad to know!), and since I can't post it (because the JavaScript would be visible), you may see it in action if you come by my office on Thursday from 1:15 to 3:15, or Monday (5/12) from 2:30 - 4:30. As promised, those are the hours when I am available to take questions. I will also be around Wednesday(5/14) afternoon, but not for any particular set hours.

Do return to the class home page during this coming week. Addition instructions or hints will be posted as necessary. Good luck and do have fun with this assignment!

The Project

As I hinted broadly, the Final Project is mostly a revision of the "Dice" game which I wrote in class. In essence, you are to write a JavaScript program which will deal a two card hand of Blackjack, and total the points for that hand. Cards are totaled as follows: A card with a face value of 2 through 10, counts the same number of points, 2 through 10. A Jack, Queen or King counts 10 points. Finally, an Ace counts as 11 points, unless there are two of them in a single hand, in which case one of them counts as 1 point only, making the entire hand of two Aces equal to 12 points. Note that a winning hand, or "Blackjack", is a hand that totals 21 points, i.e., a hand that has one Ace and either a 10, a Jack, a Queen or a King.

Part A. Using the supplied gif files of the 13 cards and an additional file representing the back of a card, write a JavaScript program (again, based upon the dice game) which will randomly select two cards and put them on the screen. (To make the game simpler, I have only supplied one suite of cards, the Hearts). Each card is drawn completely randomly from the other. Thus, you might have two Aces of Hearts or two 8's in a single hand, as well as the possibility of having two cards which have different values.

When the screen is first seen, only the "backs "of the two cards are visible. Each time you press the on screen button, two more cards are dealt. (By the way, your layout and colours do NOT have to match my example!)

Once you have dealt the two cards, in a FORM, you should print out the POINTS for each of the two cards, and the TOTAL POINTS for the hand. You should also keep a running count of the number of hands which have been dealt. (Actually, the number of hands which have been dealt since the last time "Blackjack" was dealt, since, as we will see below, the JavaScript program will be restarted each time "Blackjack" occurs.) Note again, that it IS possible for the same two cards to be picked!

Note that I have provided screenshots of my working example, since I couldn't actually post the solution!

(Hint on picking the card and finding its "points": I have carefully chosen the card names as being "2hearts.gif" through "14hearts.gif". Thus, you will choose a random number from 2 thorugh 14, and display the appropriate card. For cards 2 through 11, the POINTS will thus be equal to the hand number. Only for cards 12hearts.gif, 13hearts,gif and 14hearts.gif will this differ. For each of those three cards, the number of POINTS will be equal to 10. When youproceed to total the points for the hand, however, remember the problem of having two aces!)

Part B. Each time "Blackjack" is dealt, you should PAUSE for 3 seconds, and then proceed to a different HTML file, where you will provide a brief celebratory DIRECTOR animation. At the conclusion of that animation, the SHOCKWAVE LINGO will return you to the original screen (we know how to link to a different HTML page through LINGO from our assignment!) The JavaScript code for pausing and linking to a different HTML file is found on page 102 in our JavaScript book.

(Hint on JavaScript: Since you will be both setting variables and checking them, remember that "=" is used to set the value of a variable, while "==" is used in an IF statement to check its value!)

EXTRA CREDIT OPTIONAL Part C. When "Blackjack" is dealt go to one of four different HTML pages with four different animations: one each for a 10, Jack, Queen and King. The problem here will be not only to determine if there is a "Blackjack," but also what kind. In particular, remember that a "Blackjack" that occurs with a queen could be dealt as either Queen-Ace or Ace-Queen.