Nemesis game, stats

Files at this revision

API Documentation at this revision

Comitter:
musallambseiso
Date:
Wed May 03 20:03:17 2017 +0000
Parent:
10:c5ef17e93872
Commit message:
Removed redundant code, perfected Doxygen, added inline comments.

Changed in this revision

Stats.cpp Show annotated file Show diff for this revision Revisions of this file
Stats.h Show annotated file Show diff for this revision Revisions of this file
--- a/Stats.cpp	Tue May 02 22:13:28 2017 +0000
+++ b/Stats.cpp	Wed May 03 20:03:17 2017 +0000
@@ -2,30 +2,37 @@
 
 Stats::Stats()
 {
-
 }
 
 Stats::~Stats()
 {
+}
 
-}
+
+// Draws initial inner and outer borders to the LCD:
 
 void Stats::draw_grid(N5110 &lcd)
 {
-    lcd.drawRect(0, 0, WIDTH, HEIGHT-8, FILL_TRANSPARENT);  // outer border
-    lcd.drawLine(WIDTH-1, HEIGHT-8, WIDTH-1, HEIGHT, 1);    // health border, right side
-    lcd.drawLine(WIDTH-11, HEIGHT-8, WIDTH-11, HEIGHT, 1);  // health border, left side
-    lcd.drawLine(18, HEIGHT-1, WIDTH, HEIGHT-1, 1);         // bottom border
-    lcd.drawLine(18, HEIGHT-8, 18, HEIGHT, 1);              // wave counter border, right side
+    lcd.drawRect(0, 0, WIDTH, HEIGHT-8, FILL_TRANSPARENT);  // Outer border.
+    lcd.drawLine(WIDTH-1, HEIGHT-8, WIDTH-1, HEIGHT, 1);    // Health border, right side.
+    lcd.drawLine(WIDTH-11, HEIGHT-8, WIDTH-11, HEIGHT, 1);  // Health border, left side.
+    lcd.drawLine(18, HEIGHT-1, WIDTH, HEIGHT-1, 1);         // Bottom border.
+    lcd.drawLine(18, HEIGHT-8, 18, HEIGHT, 1);              // Wave counter border.
 }
 
+
+// Draws the wave counter onto the LCD:
+
 void Stats::draw_wave_counter(N5110 &lcd, int wave_counter)
 {
     char buffer[14];
     int length = sprintf(buffer,"%2d",wave_counter);
-    lcd.printString(buffer,0,5);
+    lcd.printString(buffer,0,5);    // Draws constantly-updating value for waves survived onto the bottom left corner of the grid.
 }
 
+
+// Draws the health bar heart onto the LCD (initially empty):
+
 void Stats::draw_health(N5110 &lcd)
 {
     lcd.drawLine(76,40,77,40,1);
@@ -40,8 +47,12 @@
     lcd.setPixel(78,46);
 }
 
+
+// Draws the first rocket onto the LCD:
+
 void Stats::draw_rocket1(N5110 &lcd, int state)
 {
+    // State is input when method is used:
     lcd.drawLine(27, HEIGHT-3, 30, HEIGHT-3, state);
     lcd.drawLine(28, HEIGHT-4, 40, HEIGHT-4, state);
     lcd.drawLine(29, HEIGHT-5, 41, HEIGHT-5, state);
@@ -49,8 +60,12 @@
     lcd.drawLine(27, HEIGHT-7, 30, HEIGHT-7, state);
 }
 
+
+// Draws the second rocket onto the LCD:
+
 void Stats::draw_rocket2(N5110 &lcd, int state)
 {
+    // State is input when method is used:
     lcd.drawLine(42, HEIGHT-3, 45, HEIGHT-3, state);
     lcd.drawLine(43, HEIGHT-4, 55, HEIGHT-4, state);
     lcd.drawLine(44, HEIGHT-5, 56, HEIGHT-5, state);
@@ -58,8 +73,12 @@
     lcd.drawLine(42, HEIGHT-7, 45, HEIGHT-7, state);
 }
 
+
+// Draws the third rocket onto the LCD:
+
 void Stats::draw_rocket3(N5110 &lcd, int state)
 {
+    // State is input when method is used:
     lcd.drawLine(57, HEIGHT-3, 60, HEIGHT-3, state);
     lcd.drawLine(58, HEIGHT-4, 70, HEIGHT-4, state);
     lcd.drawLine(59, HEIGHT-5, 71, HEIGHT-5, state);
@@ -68,8 +87,11 @@
 }
 
 
+// Draws the star onto the LCD:
+
 void Stats::draw_star(N5110 &lcd, int state)
 {
+    // State is input when method is used:
     lcd.drawLine(20, HEIGHT-6, 24, HEIGHT-6, state);
     lcd.drawLine(20, HEIGHT-4, 24, HEIGHT-4, state);
     lcd.drawLine(21, HEIGHT-3, 21, HEIGHT-7, state);
@@ -81,11 +103,13 @@
 }
 
 
+// Checks and draws the health bar (for high health):
 
-void Stats::check_health(N5110 &lcd, int collisions)
+void Stats::check_health_high(N5110 &lcd, int collisions)
 {
+    // Collisions is input and checked when method is used:
     if (collisions == 0) 
-    {
+    {   
         lcd.drawLine(76,41,80,41,1);
         lcd.drawLine(76,42,80,42,1);
         lcd.drawLine(76,43,80,43,1);
@@ -99,7 +123,15 @@
         lcd.drawLine(77,44,79,44,1);
         lcd.setPixel(78,45);
     }
-    else if (collisions == 2) 
+}
+
+
+// Checks and draws the health bar (for low health):
+
+void Stats::check_health_low(N5110 &lcd, int collisions)
+{
+    // Collisions is input and checked when method is used:
+    if (collisions == 2) 
     {
         lcd.drawLine(76,43,80,43,1);
         lcd.drawLine(77,44,79,44,1);
@@ -113,14 +145,15 @@
     else if (collisions == 4)
     {
         lcd.setPixel(78,45);
-    }     
-    else if (collisions >= 5)
-    {
     }
 }
 
+
+// Checks and draws the rockets:
+
 void Stats::check_rocket(N5110 &lcd, int ammo)
 {
+    // Ammo is input and checked when method is used:
     if (ammo == 3) {
         draw_rocket1(lcd, 1);
         draw_rocket2(lcd, 1);
@@ -140,15 +173,18 @@
     }
 }
 
+
+// Checks and draws the star:
+
 void Stats::check_star(N5110 &lcd, bool star)
 {
+    // Star is input and checked when method is used:
     if (star == true) 
     {
         draw_star(lcd, 1);
     } 
-    else
+    else 
     {
         draw_star(lcd, 2);
     }
-}
-
+}
\ No newline at end of file
--- a/Stats.h	Tue May 02 22:13:28 2017 +0000
+++ b/Stats.h	Wed May 03 20:03:17 2017 +0000
@@ -6,6 +6,18 @@
 #include "Gamepad.h"
 #include "Friendly.h"
 
+/** Friendly Class
+@brief Used for drawing the weapons bar, the health bar, and the wave counter in the Nemesis game.
+@brief Constantly checks and redraws elements based on user input and progress in the game.
+@brief Incorporates N5110.h file by Craig A. Evans.
+
+@brief Revision 1.0
+
+@author Musallam M. M. Bseiso
+@date   3rd May 2017
+*/
+
+
 class Stats
 {
 
@@ -24,6 +36,8 @@
     /** Draw Grid
     *   
     *   Draws the outer rectangular border, health border, wave counter border, and weapon border onto the LCD.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     */
     void draw_grid(N5110 &lcd);
     
@@ -31,6 +45,8 @@
     /** Draw Wave Counter
     *   
     *   Draws the wave counter onto the LCD.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     *   @param wave_counter - counter that stores which wave the game is in
     */
     void draw_wave_counter(N5110 &lcd, int wave_counter);
@@ -39,6 +55,8 @@
     /** Draw Health
     *   
     *   Draws the outside border of the health bar heart onto the LCD.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     */
     void draw_health(N5110 &lcd);
     
@@ -47,6 +65,8 @@
     *   
     *   Draws the first rocket from the left in the weapons bar onto the LCD. It is drawn full black or dotted
     *   depending on the "state" variable. Further explained in the "check_rocket" method.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     *   @param state - variable that determines if line is drawn full black (1) or dotted (2)
     */
     void draw_rocket1(N5110 &lcd, int state);
@@ -56,6 +76,8 @@
     *   
     *   Draws the second rocket from the left in the weapons bar onto the LCD. It is drawn full black or dotted
     *   depending on the "state" variable. Further explained in the "check_rocket" method.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     *   @param state - variable that determines if line is drawn full black (1) or dotted (2)
     */
     void draw_rocket2(N5110 &lcd, int state);
@@ -65,6 +87,8 @@
     *   
     *   Draws the third rocket from the left in the weapons bar onto the LCD. It is drawn full black or dotted
     *   depending on the "state" variable. Further explained in the "check_rocket" method.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     *   @param state - variable that determines if line is drawn full black (1) or dotted (2)
     */
     void draw_rocket3(N5110 &lcd, int state);
@@ -74,19 +98,35 @@
     *   
     *   Draws the star onto the LCD. It is drawn full black or dotted depending on the "state" variable.
     *   Further explained in the "check_rocket" method.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     *   @param state - variable that determines if line is drawn full black (1) or dotted (2)
     */
     void draw_star (N5110 &lcd, int state);
     
     
-    /** Check Health
+    /** Check Health (high)
     *   
     *   Draws the health bars onto the LCD depending on how much health the player has (depending on the variable "collisons").
     *   If zero collisions, health bar is full, i.e the heart is filled black. As collisions increase, the health bar
-    *   goes down, i.e less of the heart is filled black.
+    *   goes down, i.e less of the heart is filled black. This method only deals with the health when it is high.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     *   @param collisions - variable that stores how many collisions have been registered
     */
-    void check_health(N5110 &lcd, int collisions);
+    void check_health_high(N5110 &lcd, int collisions);
+    
+    
+    /** Check Health (low)
+    *   
+    *   Draws the health bars onto the LCD depending on how much health the player has (depending on the variable "collisons").
+    *   If zero collisions, health bar is full, i.e the heart is filled black. As collisions increase, the health bar
+    *   goes down, i.e less of the heart is filled black. This method only deals with the health when it is low.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
+    *   @param collisions - variable that stores how many collisions have been registered
+    */
+    void check_health_low(N5110 &lcd, int collisions);
     
     
     /** Check Rocket
@@ -95,6 +135,8 @@
     *   "ammo"). If full ammo, all 3 rockets are drawn full black, i.e drawn with the state set to 1. After one shot (ammo = 2),
     *   the first two are still drawn full black and the third one is drawn dotted, i.e the first two are drawn with a state of 1,
     *   and the third one is drawn with a state of 2, etc.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     *   @param ammo - variable that stores how many rockets are available
     */
     void check_rocket(N5110 &lcd, int ammo);
@@ -105,6 +147,8 @@
     *   Draws the star in the weapons bar onto the LCD depending on if the player has one available (depending on the variable
     *   "star"). If "star" is set to true, it is drawn full black, i.e drawn with the state set to 1, if it is set to false, it
     *   is drawn dotted, i.e drawn with the state set to 2.
+    *   @param N5110 - nokia LCD library
+    *   @param lcd - pointer to nokia LCD library
     *   @param star - variable that stores whether a star is available or not
     */
     void check_star(N5110 &lcd, bool star);