cs106a – Assignment #4 – Task #3

The complete specification of assignment #4 can be found as part of the stream at iTunes.

Reading the lexicon from a data file

Part III of this assignment is by far the easiest and requires considerably less than half a page of code.
Your job in this part of the assignment is simply to reimplement the HangmanLexicon class so that instead of selecting from a meager list of ten words, it reads a much larger word list from a file. The steps involved in this part of the assignment are as follows:

  1. Open the data file HangmanLexicon.txt using a BufferedReader that will allow you to read it line by line.
  2. Read the lines from the file into an ArrayList.
  3. Reimplement the getWordCount and getWord methods in HangmanLexicon so that

they use the ArrayList from step 2 as the source of the words.
The first two steps should be done in a constructor for HangmanLexicon, which you will need to add to the file. The last step is simply a matter of changing the implementation of the methods that are already there.
Here is how the HangmanLexicon constructor should be added to the HangmanLexicon class:
Continue reading “cs106a – Assignment #4 – Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #4 – Task #2

The complete specification of assignment #4 can be found as part of the stream at iTunes.

Adding graphics

For Part II, your task is simply to extend the program you have already written so that it now keeps track of the Hangman graphical display. Although you might want to spice things up in your extensions, the simple version of the final picture for the unfortunate user who has run out of guesses looks like this:

cs106a – assignment #4 – task #2
Continue reading “cs106a – Assignment #4 – Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #4 – Task #1

The complete specification of assignment #4 can be found as part of the stream at iTunes.

Playing a console-based game

In the first part of this assignment, your job is to write a program that handles the user interaction component of the game—everything except the graphical display. To solve the problem, your program must be able to:

  • Choose a random word to use as the secret word. That word is chosen from a word list, as described in the following paragraph.
  • Keep track of the user’s partially guessed word, which begins as a series of dashes and then updated as correct letters are guessed.
  • Implement the basic control structure and manage the details (ask the user to guess a letter, keep track of the number of guesses remaining, print out the various messages, detect the end of the game, and so forth).

Continue reading “cs106a – Assignment #4 – Task #1”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Lecture #14 to #18: Yet more Java

Prerequisites to the fourteenth lecture is reading chapter 7 of “Art and Science of Java”. The lecture explains memory and how variables are stored.

Prerequisites to the fifteenth lecture is reading chapter 12.4 of “Art and Science of Java”. The lecture continues with variables, heaps and stacks and then explains how files and exceptions work.

The sixteenth lecture explains arrays, how to initialize, work with and pass them.

Prerequisites to the seventeenth lecture is reading chapters 11.1 through 11.5 of “Art and Science of Java”. The lecture continues with arrays and array lists.

Prerequisites to the eighteenth lecture is reading chapters 11.6 through 11.8 of “Art and Science of Java”. The lecture continues with arrays and introduces testing and debugging.

Code for these lectures are available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #3 – Extra Task #5

The complete specification of assignment #3 can be found as part of the stream at iTunes.

Keep score

You could easily keep score, generating points for each brick. In the arcade game, bricks were more valuable higher up in the array, so that you got more points for red bricks than cyan bricks. You could display the score underneath the paddle, since it won’t get in the way there.

Add two new instance variables, one for accessing the label and one for storing the actual score. Setup the score label. Finally adjust the score according to the color of the hid brick:
Continue reading “cs106a – Assignment #3 – Extra Task #5”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #3 – Extra Task #4

The complete specification of assignment #3 can be found as part of the stream at iTunes.

Add in the “kicker”

The arcade version of Breakout lured you in by starting off slowly. But, as soon as you thought you were getting the hang of things, the program sped up, making life just a bit more exciting. The applet version implements this feature by doubling the horizontal velocity of the ball the seventh time it hits the paddle, figuring that’s the time the player is growing complacent.

Add a constant to hold the given number of paddle hits for which the velocity should double, and an instance variable to count the hits. Reset this variable when the ball is setup. Finally adjust the collision checker to count the hits and increase the horizontal velocity after the given count of hits:
Continue reading “cs106a – Assignment #3 – Extra Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs106a – Assignment #3 – Extra Task #3

The complete specification of assignment #3 can be found as part of the stream at iTunes.

Improve the user control over bounces

The program gets rather boring if the only thing the player has to do is hit the ball. It is far more interesting, if the player can control the ball by hitting it at different parts of the paddle. The way the old arcade game worked was that the ball would bounce in both the x and y directions if you hit it on the edge of the paddle from which the ball was coming. The web version implements this feature.

First calculate the position where the ball hits the paddle so that -1 signifies a hit on the left corner and +1 a hit on the right corner. Change the horizontal speed so that a hit in the center (0) does not do anything, a hit in the corner from the direction from which the ball arrived changes the direction and a hit on the other corner increases the horizontal speed. Finally to keep the ball from speeding up, adjust the vertical speed so that the overall velocity stayes the same:
Continue reading “cs106a – Assignment #3 – Extra Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail