B. Program Description for Developers

Assumptions made and/or used in software design

  • The touchscreen is the only option for user input
  • The entirety of the touchscreen’s surface area is available for use as input and output
  • The touchscreen could clearly output various solid colors
  • The user is able to understand on-screen displays
  • The user will provide inputs appropriately (only touches buttons and not the gaps in between them)
  • One game is the moment between pressing “Play” on the main menu and failing to successfully complete a sequence
  • One round begins when a sequence is presented and ends after the user finishes their attempt to repeat the sequence
  • The total number of games/one game session is the number of games played since the Proteus has been powered on
  • Only one button is lit/flashed at a time
  • Sequences are the same length throughout a level
  • The buttons have the same appearance throughout a level

 

Important variables and arrays used in design

  • all_scores – array which stores the score earned by user after each game
  • blue – assigns a numerical value of 2 to the blue button (top-right on screen)
  • game – tracks the number of games played for keeping score statistics
  • green – assigns a numerical value of 3 to the green button (bottom-left on screen)
  • scarlet – assigns a numerical value of 1 to the scarlet button (top-left on screen)
  • score – tracks the user’s score throughout one game session
  • sequence1 – array which stores the order and occurrence of the numerical values assigned to each button, whose source is the randomly generated x-y coordinates
  • sequence2 – array which stores the order and occurrence of the numerical values assigned to each button, whose source is x-y coordinates from user touchscreen input
  • x – x-coordinate of Proteus touchscreen
  • x_touch – dummy variable used to determine user touch release from the touchscreen
  • y – y-coordinate of Proteus touchscreen
  • y_touch – dummy variable used to determine user touch release from the touchscreen
  • yellow – assigns a numerical value of 4 to the yellow button (bottom-right on screen)

 

Class “Statistics”

Only one object, score_recorder, was declared and used throughout the program. The object was used to track the scores of multiple game sessions and includes one constructor function, member functions, and several variables of type int. The functions (explained further below) were used to modify and display scores in the game. Every function was pass by reference and had no inputs or outputs.

 

Functions

  • Statistics()

Constructor function for the class Statistics. Initializes every variable in the class to 0. Called every time an object of class Statistics is declared

Statistics::Statistics()

{

int i;

for (i = 0; i < 14; i++)

{

all_scores[i] = 0;

}

score = 0;

game = 0;

}

 

  • void Game_Counter()

Member function of class Statistics which counts the total number of games played. Adds one to variable game every time a new game is played

void Statistics::Game_Counter()

{

game = game + 1;          // game is incremented by 1 every time function is called

}

Initially, if game = 0, calling the function when ending a new game results in game = 1.

 

  • void Score_Setter()

Member function of class Statistics which adds 10 to the value of score every time the user successfully completes one round

void Statistics::Score_Setter()

{

score = score + 10;          // Player’s score increases by 10 for every repeated

sequence

}

Initially, if score = 0, calling the function after the user successfully completes a round results in score = 10.

 

  • void Stats()

Member function of class Statistics which records the score after each game into array all_scores

void Statistics::Stats()

{

all_scores[game – 1] = score;          // Each game’s score is stored as an element in the

corresponding cell in the array after player loses

// 1 is subtracted from the value of game to account

for array indexing beginning at 0

}

Upon calling the function at the end of the first game, the user’s score is stored in array all_scores[0].

 

  • void Reset_Score()

Member function of class Statistics which resets the score variable (score) to 0 when a user decides to replay the game after finishing a game

void Statistics::Reset_Score()

{

score = 0;          // Score is set to 0  before every new game

}

Upon calling the function at the start of a new game, score = 0 regardless of the value of score initially.

 

  • void Display_Current_Score()

Member function of class Statistics which displays the score on the screen after a game is finished

void Statistics::Display_Current_Score()

{

LCD.Write(score);          // Score is displayed on screen after player loses

}

Upon calling the function at the end of a game, the current value of score is displayed on the screen.

 

  • void Display_All_Scores ()

Member function of class Statistics which displays scores from all games played by displaying the values of all_scores; called when player views the Statistics option in main menu

void Statistics::Score_Setter()

{

int i;

for ( i = 0; i < 14; i++)          // Display 14 most recent scores in a list

{

LCD.Write(“Game “);

LCD.Write(i + 1);          // Offset index by 1 to account for array addressing

beginning at 0

LCD.WriteLine(all_scores[i]);

}

}

 

Program Performance and Limitations

“Simon” is a program written in C/C++ for the Proteus. The device only accepts user touch to its touchscreen as input, which means that user touch drives the execution of the program. Upon powering up the Proteus, a one-time introduction to the game is displayed on the screen. The main menu of the game displays four possible options for the user:

  • Play: Allows user to play the game
  • Rules: Displays on screen the game’s rules
  • Statistics: Displays on screen the scores of up to the last 14 games played
  • Credits: Displays on screen the developers and those in aid of the developers of the game

Once the user chooses an option by providing an input to the screen, the screen reads in the location of the input and matches it with the region of the screen that is assigned the user’s option. This is how every user input is processed in the program. If the user decides to play the game, they are prompted to choose between playing the easy version or the hard version of the game. The easy version requires the user to memorize 3 elements in a sequence, while the hard version requires the user to memorize 6 elements in a sequence. Regardless of the user’s choice, the program will begin randomly generating pairs of coordinates for the given sequence. These coordinate pairs are used to determine which region of the touchscreen (assigned an integer between 1-4) is part of the sequence, which is then stored in an array. The color of the region is flashed on screen. These regions are “buttons” in the game:

  • Top left: Scarlet, assigned an integer value of 1
  • Top right: Blue, assigned an integer value of 2
  • Bottom left: Green, assigned an integer value of 3
  • Bottom right: Yellow, assigned an integer value of 4

One pair of coordinates are generated at a time. X-coordinates range from 0 to 320 (320 being the maximum length of the screen) and y-coordinates range from 0 to 240 (240 being the maximum width of the screen). Coordinate pairs will be randomly generated for the defined number of iterations of the definite loop in which these commands are contained (which is the number of elements in the sequence). The user then provides their input as part of the game play. User input data is stored in a second array. The user’s input is compared to the corresponding randomly generated output. The game continues if these two values are equal, and the user continues supplying output for the length of the array storing the given randomly generated sequence. The score, initially at 0, increases by 10. The score increases by 10 for every successful round. If these two values are not equal, the game ends. The score is shown to the user and the user is given the option to quit or to play the game again. If the user chooses to replay the game, the score is reset and a new set of coordinates will be randomly generated. If the user chooses to quit, the game returns to the main menu. The game’s score is recorded to a storage array either way, which is displayed if the user chooses the Statistics option in the main menu. The storage array only can store up to the last 14 games played since the Proteus was powered on. When the device is powered off, all of the statistics are reset. The storage array only holds the scores of 14 previous games as this is the maximum amount of text the touchscreen can display.

If the user chooses options other than “Play”, its corresponding information is displayed on screen. Another input from the user will return them back to the main menu.