Initialize files from GitLab repository

This commit is contained in:
2025-11-04 20:22:10 -07:00
commit 4050e30ae8
30 changed files with 3328 additions and 0 deletions

53
lib/items/Armor.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include "../../include/items/Armor.h"
#include <iostream>
using namespace std;
// This constructor just initializes the Armor to null.
Armor::Armor()
{
name = "No Armor Equipped";
health = 0;
hits_remaining = 0;
upgrades_remaining = 0;
value = 0;
}
// This constructor just initializes the Armor to the passed values.
Armor::Armor(string armor_name, int health_added, int cost)
{
name = armor_name;
health = health_added;
hits_remaining = 150;
upgrades_remaining = 3;
value = cost;
}
// SETTER FUNCTIONS
// GETTER FUNCTIONS
string Armor::getArmorName()
{
return name;
}
int Armor::getArmorHealth()
{
return health;
}
int Armor::getArmorHitsRemaining()
{
return hits_remaining;
}
int Armor::getArmorUpgradesRemaining()
{
return upgrades_remaining;
}
int Armor::getArmorValue()
{
return value;
}

58
lib/items/Potion.cpp Normal file
View File

@@ -0,0 +1,58 @@
#include "../../include/items/Potion.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// This constructor just initializes the User to null.
Potion::Potion()
{
name = "No Potion Stocked";
heal_amount = 0;
value = 0;
}
Potion::Potion(string potion_name, int amount_provided, int cost)
{
name = potion_name;
heal_amount = amount_provided;
value = cost;
}
//SETTER FUNCTIONS
void Potion::setPotionName(string potion_name)
{
name = potion_name;
}
void Potion::setPotionValue(int cost)
{
value = cost;
}
// GETTER FUNCTIONS
string Potion::getPotionName()
{
return name;
}
int Potion::getPotionValue()
{
return value;
}
int Potion::getPotionAmount()
{
return heal_amount;
}

95
lib/items/Weapon.cpp Normal file
View File

@@ -0,0 +1,95 @@
#include "../../include/items/Weapon.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// This constructor just initializes the Weapon to null.
Weapon::Weapon()
{
name = "No Secondary Equipped";
base_damage = 0;
max_damage = 0;
hits_remaining = 0;
upgrades_remaining = 0;
value = 0;
}
Weapon::Weapon(string weapon_name, int base, int max, int cost)
{
name = weapon_name;
base_damage = base;
base_heavy_damage = base;
max_damage = max;
max_heavy_damage = max;
hits_remaining = 200;
upgrades_remaining = 3;
value = cost;
}
//SETTER FUNCTIONS
void Weapon::setWeaponValue(int cost)
{
value = (cost / 2) * 1.5;
}
void Weapon::setUpgradesRemaining(int upgrades_remaining)
{
upgrades_remaining = upgrades_remaining - 1;
}
void Weapon::setWeaponBaseHeavyDamage(int level, int base, int random)
{
base_heavy_damage = base + random + (level * 10);
}
void Weapon::setWeaponMaxHeavyDamage(int level, int max, int random)
{
max_heavy_damage = max + random + (level * 10);
}
// GETTER FUNCTIONS
string Weapon::getWeaponName()
{
return name;
}
int Weapon::getWeaponValue()
{
return value;
}
int Weapon::getWeaponBaseDamage()
{
return base_damage;
}
int Weapon::getWeaponBaseHeavyDamage()
{
return base_heavy_damage;
}
int Weapon::getWeaponMaxDamage()
{
return max_damage;
}
int Weapon::getWeaponMaxHeavyDamage()
{
return max_heavy_damage;
}
int Weapon::getWeaponHitsRemaining()
{
return hits_remaining;
}
int Weapon::getWeaponUpgradesRemaining()
{
return upgrades_remaining;
}

71
lib/people/Opponent.cpp Normal file
View File

@@ -0,0 +1,71 @@
#include "../../include/people/Opponent.h"
#include <iostream>
#include <iomanip>
#include <string>
// This constructor just initializes the User to null.
Opponent::Opponent()
{
name = "Stick McStickington";
current_health = 0;
max_health = 0;
level = 1;
base_damage = 1;
max_damage = 1;
}
Opponent::Opponent(string opponent_name, int opponent_level, int base, int max)
{
name = opponent_name;
current_health = opponent_level * 100;
max_health = current_health;
level = opponent_level;
base_damage = base;
max_damage = max;
}
//SETTER FUNCTIONS
void Opponent::setOpponentHealth(int damage_taken)
{
current_health = current_health - damage_taken;
}
// GETTER FUNCTIONS
string Opponent::getOpponentName()
{
return name;
}
int Opponent::getOpponentHealth()
{
return current_health;
}
int Opponent::getOpponentMaxHealth()
{
return max_health;
}
int Opponent::getOpponentLevel()
{
return level;
}
int Opponent::getOpponentBaseDamage()
{
return base_damage;
}
int Opponent::getOpponentMaxDamage()
{
return max_damage;
}

170
lib/people/User.cpp Normal file
View File

@@ -0,0 +1,170 @@
#include "../../include/people/User.h"
#include "../../include/items/Weapon.h" // include the Weapon header file
#include "../../include/items/Armor.h"
#include "../../include/items/Potion.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
// This constructor just initializes the User to null.
User::User(string username, Weapon current_weapons[], Armor current_armor[], Potion current_potions[])
{
name = username;
current_health = 100;
max_health = 100;
level = 1;
xp_points = 0;
xp_needed = 500;
credits = 500;
for (int i = 0; i < 2; i++)
{
equipped_weapon[i] = current_weapons[i];
}
for (int i = 0; i < 3; i++)
{
equipped_armor[i] = current_armor[i];
}
for (int i = 0; i < 4; i++)
{
equipped_potions[i] = current_potions[i];
}
}
//SETTER FUNCTIONS
void User::setUserName(string username)
{
name = username;
}
void User::setUserHealth(int damage_taken)
{
current_health = current_health - damage_taken;
// Set Health to zero if it goes below 0
if (current_health < 0)
{
current_health = 0;
}
}
void User::setHealthAfterPurchase(int armor_amount_added)
{
current_health += armor_amount_added;
}
void User::setUserHealthFull(int full_health)
{
current_health = full_health;
}
void User::setMaxHealth(Armor current_armor[])
{
int armor_rating = 0;
for (int i = 0; i < 3; i++)
{
armor_rating += current_armor[i].getArmorHealth();
}
max_health = 100 + armor_rating;
}
void User::setUserCredits(int current_credits)
{
credits = current_credits;
}
void User::giveUserCredits(int credits_added)
{
credits += credits_added;
}
void User::setUserXP(int xp_earned)
{
xp_points += xp_earned;
}
void User::resetUserXP(int xp_remaining)
{
xp_points = xp_remaining;
}
void User::setUserXPNeeded(int level)
{
xp_needed = (level * pow(100, 1.2)) + (level * 100) + (level * 10) + (level * pow(1, 2));
xp_needed = floor(xp_needed); // Round down to nearest whole number
}
void User::usePotion(int potion_amount)
{
current_health += potion_amount;
// Make sure potion doesn't overheal
if (current_health > max_health)
{
current_health = max_health;
}
}
void User::levelUpUser(int current_level)
{
level = current_level + 1;
}
// GETTER FUNCTIONS
string User::getUserName()
{
return name;
}
int User::getUserHealth()
{
return current_health;
}
int User::getUserMaxHealth()
{
return max_health;
}
int User::getUserLevel()
{
return level;
}
int User::getUserXP()
{
return xp_points;
}
int User::getUserCredits()
{
return credits;
}
int User::getUserXPNeeded()
{
return xp_needed;
}
Weapon User::getUserWeapon(int input)
{
while (input < 0 && input > 1) // assuming the array size is 2
{
cout << "Please enter a valid input" << endl;
cin >> input;
}
return equipped_weapon[input];
}

274
lib/ship/Map.cpp Normal file
View File

@@ -0,0 +1,274 @@
#include "../../include/ship/Map.h"
#include <iostream>
Map::Map()
{
resetMap();
}
/*
* Algorithm: Resets positions of player, NPCs, and rooms and clears map_data_
* Set Player position coordinates to 0
* Set npc_count_ to false
* Set room_count_ to 0
* loop i from 0 to max_npcs_
* Set row and col of location to -1
* loop i from 0 to max_rooms
* Set row and col of room location to -1
* loop i from 0 to num_rows_
* loop j from 0 to num_cols_
* Set (i,j) location on map_data_ to '-'
* Parameters: none
* Return: nothing (void)
*/
void Map::resetMap()
{
// resets player position, count values, and initializes values in position arrays to -1
player_position_[0] = 0; //Puts Player in top row
player_position_[1] = num_cols_/2; // Centers Players
// set ship exit
ship_exit_[0] = num_rows_ - 2; // Set Exit to second last row
ship_exit_[1] = num_cols_ / 2; // Set exit in middle
// set bed position on map
ship_bed_[0] = 5;
ship_bed_[1] = 0;
for (int i = 0; i < max_rooms_; i++)
{
room_positions_[i][0] = -1;
room_positions_[i][1] = -1;
}
for (int i = 0; i < num_rows_; i++)
{
for (int j = 0; j < num_cols_; j++)
{
map_data_[i][j] = SHIP;
}
}
map_data_[ship_exit_[0]][ship_exit_[1]] = EXIT;
map_data_[ship_bed_[0]][ship_bed_[1]] = BED;
}
// return player's row position
int Map::getPlayerRow()
{
return player_position_[0];
}
// return player's column position
int Map::getPlayerCol()
{
return player_position_[1];
}
// return ship exit row
int Map::getShipExitRow()
{
return ship_exit_[0];
}
// return ship exit col
int Map::getShipExitCol()
{
return ship_exit_[1];
}
// set player position, if in range
void Map::setPlayerPosition(int row, int col)
{
if (isOnMap(row, col))
{
player_position_[0] = row;
player_position_[1] = col;
}
}
// set ship exit position, if in range
void Map::setShipExit(int row, int col)
{
if (isOnMap(row, col))
{
ship_exit_[0] = row;
ship_exit_[1] = col;
}
}
// set location of players bed
void Map::setShipBed(int row, int col)
{
if (isOnMap(row, col))
{
ship_bed_[0] = row;
ship_bed_[1] = col;
}
}
// returns member variable num_rows_
int Map::getNumRows()
{
return num_rows_;
}
// returns member variable num_cols_
int Map::getNumCols()
{
return num_cols_;
}
/*
* @brief Checks if the given (row, col) position is on the map
*
* Algorithm:
* if 0 <= row < num_rows_ and 0 <= col < num_cols_:
* return true
* else:
* return false
*
* Parameters: row (int), col (int)
* Returns: bool
*/
bool Map::isOnMap(int row, int col)
{
if (0 <= row && row < num_rows_ && 0 <= col && col < num_cols_)
{
return true;
}
return false;
}
/*
* Algorithm: checks if (row, col) is ship_exit_
*
*/
bool Map::isShipExit(int row, int col)
{
if (row == ship_exit_[0] && col == ship_exit_[1])
{
return true;
}
return false;
}
/*
* Algorithm: checks if (row, col) is ship_exit_
*
*/
bool Map::isShipBed(int row, int col)
{
if (row == ship_bed_[0] && col == ship_bed_[1])
{
return true;
}
return false;
}
/*
* Algorithm: Make the player move based on the given command
* if user inputs w and if its not the top row of the map
* Move the player up by one row
* if user inputs s and if its not the bottom row of the map
* Move the player down by one row
* if user inputs a and if its not the leftmost column
* Move the player left by one column
* if user inputs d and if its not the rightmost column
* Move the player right by one column
* if player moved
* if new location is an NPC location
* mark new location as explored
* return true
* else
* return false
*
* Parameters: direction (char)
* Return: boolean (bool)
*/
bool Map::move(char direction)
{
// check input char and move accordingly
switch (tolower(direction))
{
case 'w': // if user inputs w, move up if it is an allowed move
if (player_position_[0] > 0)
{
player_position_[0] -= 1;
}
else // Keep user in bounds
{
return false;
}
break;
case 's': // if user inputs s, move down if it is an allowed move
if (player_position_[0] < num_rows_ - 1)
{
player_position_[0] += 1;
}
else // Keep user in bounds
{
return false;
}
break;
case 'a': // if user inputs a, move left if it is an allowed move
if (player_position_[1] > 0)
{
player_position_[1] -= 1;
}
else // Keep user in bounds
{
return false;
}
break;
case 'd': // if user inputs d, move right if it is an allowed move
if (player_position_[1] < num_cols_ - 1)
{
player_position_[1] += 1;
}
else // Keep user in bounds
{
return false;
}
break;
default:
return false;
}
return true;
}
/*
* Algorithm: This function prints a 2D map in the terminal.
* Loop i from 0 to number of rows
* Loop j from 0 to number of columns
* if player position is at (i,j)
* print 'X'
* else if npc is at (i,j)
* if npc has been found:
* print 'N'
* else
* print '-'
* else
* print the value of (i,j) in map_data_
*
* Parameters: none
* Return: nothing (void)
*/
void Map::displayMap()
{
for (int i = 0; i < num_rows_; i++)
{
for (int j = 0; j < num_cols_; j++)
{
if (player_position_[0] == i && player_position_[1] == j)
{
cout << FIGHTER;
}
else
{
cout << map_data_[i][j];
}
}
cout << endl;
}
}