C. Program Description for Developers

Adventure

The games commands for the program were rather simple. The player is given the choice to pick their own base statistics, with the screen encouraging them to choose values based on their skill level. A “Kill Monsters!” command is then given when the game initially starts, telling the players that the survival has now begun. Players are also told that they MUST be next to a monster to attack it, and if they occupy a space where a monster is, the monster becomes invisible. Then they must find and kill the invisible monster before proceeding to the next round. The game alerts the player every Round 5 of the appearance of the Boss Monster. There is no difference in monster appearance, so players must tread carefully. A basic command of the game is giving the player the option of which direction they want to move in. These are controlled by the keys W, S, A, D, which move the player Up, Down, Left, Right, when pushed. The player is alerted when they cannot move in a particular direction anymore based on their position on the grid. Another basic command is giving the user the option to attack a monster or not, requiring an input of (Y, y) for Yes or (N. n) for No. The game alerts users of when a monster is defeated and/or when it is hit/evades an attack, as well as when the player is misses an attack and/or is hit/evades an attack. After being hit, players are then told how much health they have remaining. The game displays when a new level/round is also reached.

There were many variables used in the creation of this code. The names of each variable used is included, and directly corresponds to what it affects, unless otherwise noted.

  • playerattack, playerdefense, playerhealth
  • p1,p2 (Player’s character/image)
  • bosshealth, monsterhealth, monsterattack, monsterdefense, boss attack, boss defense
  • v, m (monster 1)
  • o,p (monster 2 ; spawns in later levels and boss rounds)
  • w, a, s, d (movement)
  • Y, y (Yes)
  • N ,n (No)
  • totalhurt (damage player takes)

The first section of code asks for the user to input their desired values for health, attack, and defense. These values must equal and not exceed 45. The second section of code loads the game board and the player on the board at a random location. Images for the player and monster characters are loaded and placed randomly on the board. The code generalizes that the player must be next to the monster in order to attack it and that invisible monsters must be found and defeated to move to the next round. The third section defines variables and goes into detail using while loops and if statements to determine how many monsters appear, a monster’s stats( attack, health, defense) based on the level and round a player has reached. A base monster’s health is 1, its attack equals the level the player is on, and its defense equals the level plus 20. This only occurs when playerhealth is greater than 0, and the round is less than or equal to 5 multiplied by the level – 2, while there is no boss. However, on round 5, a boss is introduced, placed on the board, and its stats are calculated differently than regular monsters. A boss monsters defense equals the level multiplied by 2 + 24. Its attack and health are the level times 2. This only occurs when playerhealth is greater than 0, and the round is 5.

Movement is detailed and asks for specific user input with letters that correspond with a direction. Players are allowed to move into any blank space that they see, but if they cannot move in that desired direction, the game will release an output alerting the user of this. A choice is given to users to attack a monster or not. If “yes” is the chosen input, there is a random roll between 1-10 that adds to the players attack stat. If the player’s attack is greater than the attacked monster’s defense, that monster is defeated or losses 1 from its health stat. A monster is defeated when its health reaches 0. If “no” is the chosen input, the player can then choose where they wish to move to next, without engaging in a fight. When monsters attack, they get a random dice roll to add to their attack stat as well. If that stat, labeled as “totalhurt” is greater than the player’s defense stat, the player losses 1 health. The game then displays how much health the player has left, unless the player has 0 health, which then leads to a “Game Over” output. Players and monsters also randomly evade attacks. After each increment of 5 levels has been reached, the player gains +2 to each stat category (attack,health,defense).

Connect Four

As stated previously the games code takes place within a while loop that is dependent on the turn variable.  While turn is less than 43 the loop continues and once that loop ends so does the game.  The turn variable also keeps track of who’s turn it is through the modulo operation.  The turn is divided by two so that if it is odd the code will only allow player 1 to play and the same for player 2 with even numbered turns.  This prevents the player movements from getting out of sync when a user inputs an invalid move for their turn.  The validity of each turn is determined by multiple if else statements that are started after the player inputs their move, assigning it to the variable BColumn.  BColumn is then tested through seven if else statements, the first statement checks if it is a whole number 1 through 7 and then the following statements check each row in that column from bottom to top.  The board of column and rows is represented by the variable Board{} and the variables redchip and blackchip each represent the images of their namesake.  Once the if statement reaches a row on Board{} in BColumn that doesn’t have a chip assigned to it the code assigns one depending on which player stated the column.  Player 1 places black chips and player 2 places red.

  • Board{} = The image of the board with a grid of coordinates for the different spots on the board
  • blackchip and redchip = The images of the playing pieces
  • turn = Keeps track of what turn the game is at (and gets increased faster to end the game on a connect four)
  • BColumn = The column that the player inputs on their turn
  • a, m, n, k = used in the for loops to check for four in a row

The code checks for a win using a different for loop for each direction; up, down, increasing diagonal, and decreasing diagonal.  Each for loop has a different variable that increases by one 3-4 times.  In the for loops the variable adds +1 to the row or column each turn while the other remains constant.  The for loops allow for the script to be much more condensed as the code doesn’t have to include every single location a four in a row might be.  This not only saves space in the code but it also reduces the chance of mistakes when typing it.