High Level Design

Game Instructions

The basic in-game controls can be summarized as follows:
Keyboard: The keyboard uses the following command keys:

w Move cursor up
s Move cursor down
a Move cursor left
d Move cursor right
p Pause game
Enter Select menu option/select card to flip over/reset game upon completion

 

Sega Controller: The Sega Genesis controller uses the following buttons for game control:

Up Move cursor up
Down Move cursor down
Left Move cursor left
Right Move cursor right
Start Select title screen menu option
A Reset game upon completion
B Pause game
C Select card to flip over


The game opens with a standard title screen, giving the user three options to choose from: "Easy," "Hard," or "High Scores." The cursor to select these options can be moved by pressing the up and down directional keys on either device. A selection of an option can be made by pressing Start on the controller or Enter on the keyboard. Title screen selections can be summarized as follows:

  • Easy: Start playing an easy game with 20 cards dealt to the
    playing field
  • Hard: Start playing a hard game with 36 cards dealt to the playing
    field
  • High Scores: Display the current high scores; Start or Enter can
    be pressed to return back to the title screen

Once either the easy or hard difficulty is chosen, a loading screen is displayed while the cards in the deck are extensively shuffled. The appropriate number of cards is then dealt onto the playing field and a selection cursor is displayed around the upper-leftmost card. This selection cursor can be moved around the playing field using the directional keys on either control device. By pressing either C on the controller or Enter on the keyboard, the card that is currently surrounded by the selection cursor will be flipped over. Once two cards have been flipped over in this manner, they are removed from the playing field if their faces match. If a match is not present, they are flipped back over. The high scores in this game are solely based on the time it takes the player to complete one game. Therefore, once two cards have been flipped over, the player can either force them to be immediately flipped back over (by pressing any button) or wait the default 2 seconds before they are automatically flipped back over. This allows the player to attempt to complete the game as fast as possible.

The game can also be paused while there are still cards left on the playing field. By either pressing B on the controller or "p" on the keyboard, the game clock is stopped, text in the upper left-hand corner of the display indicates the game is paused, and a menu is made available at the bottom of the screen. While paused, the player can select to either resume the current game or quit to the title screen. The cursor to select either of these options can be moved by pressing the left and right directional keys on either device. If resume is selected, the pause menu is erased and the game clock starts again, thereby letting the player resume his or her game. If quit is selected, the game is reset and the title screen is displayed once again. Because the ability to pause the game allows the user to stop the game clock, this would make cheating to get a very short time very easy. The user could theoretically flip two cards over, pause the game, write down where they are located, and repeat the process to clear the playing field in a unreasonably short amount of time. To discourage this type of cheating, the player can become ineligible for a high score if he or she pauses a single game three times or more.

After the entire playing field has been cleared, the game clock is stopped and the player will be informed whether or not he or she has gotten the high score for the current difficulty level. The player is then prompted to press either A on the controller or Escape on the keyboard to reset the game and return to the title screen. If a high score was attained, the player can now view his or her high score by selecting the appropriate option on the title screen.


Block Diagram

The block diagram located here, illustrates at a very high level, the basic functionality of our project. Further details of our code and program functionality can be found in the Program Design section.

User Interface

One of our main concerns in developing Memory was to provide the user with an easy and intuitive interface. Not only did we want the user to easily understand all of our menus and instructions, but also we wanted to make the game fun to play. Since Memory is a game without a lot of moving video content and action, we wanted to integrate some kind of eye-catching video animation. Therefore, we designed a very smooth and convincing animation of a single card being flipped over and also the reverse animation of a card being flipped back over. This card animation gave us the catchy video game feel that we were looking for when developing the game. To further make both the game and the user's experience more unique, an entire new character set was defined to be used for the pictures on the faces of all of the cards. While all of these pictures are nonetheless basic, they provide for a very visual gaming experience. Also, as mentioned in our project goals, we decided to allow the user to control the game using either the PC keyboard or a 3-button Sega Genesis controller. The game was designed so that either of these control methods can be used at any time. By providing the user with these alternatives for game control and allowing him or her to choose the method of control that is most comfortable, we were able to provide the user with a more dynamic experience.

Hardware/Software Tradeoffs

In coming up with the idea for our project, we realized that many of the realizable projects that could be completed in the allocated 4 weeks tended to be weighty on either hardware or software, and not both. Since we really wanted to make a project that would be fun and enjoyable to use upon completion, we decided to take on a project that was heavily software-based. The only hardware that was needed for this project was a simple 2-bit digital to analog converter (to send all video signals to the television) and a soldered DB9 plug to allow a good connection to the Sega controller. While this is a minimal amount of hardware, close to 3200+ lines of code were necessary to get our game to function as we desired. Therefore, we traded simple hardware for more complex and lengthy software.

NTSC Signals

The standard signals defined by the National Television Standards Committee (NTSC) are the driving force behind all of the black and white pixels that show up on the screen while playing our game.

Timer 1 was exclusively used for this project in order to produce all of the sync signals that were required to start lines or frames of content. Instead of the NTSC standard for producing sync pulses every 63.5 microseconds, we used a timer interval of 63.625 microseconds to cause each frame to take exactly 1/60 seconds. This slight change made it much more convenient to include a sufficiently accurate software-based timer. In producing each sync pulse, the Timer 1 output compare A interrupt was used to detect a match between the TCNT1 and OCR1A registers. As TCNT1 reached a count of 1018 machine cycles (63.625 microseconds with a 16 MHz timing crystal), the Timer 1 ISR was called in order to produce a single horizontal or vertical sync pulse. Since pin 5 of Port D was used for these sync signals, this pin was driven either high or low upon entry to the ISR and was later returned to its original logic value just before exiting the ISR. This short amount of time that pin 5 on Port D is driven to a different voltage level is an adequately generated sync pulse that can be interpreted by the television. The number of the current line being displayed on the screen was the determining factor of whether or not to generate a horizontal or vertical sync pulse. If the variable named "LineCount" was between 1 and 248, then a horizontal sync pulse is generated. Between lines 248 and 251, a vertical sync pulse is generated. Lastly, between lines 251 and 262, a horizontal sync pulse is generated. This scheme properly sets up the beginning of each line and the beginning of each new frame.