From 7eb7b10d61207190d899465b56f4a76cbb41fd2b Mon Sep 17 00:00:00 2001 From: JLmike7 Date: Thu, 9 Oct 2014 20:05:18 -0400 Subject: [PATCH] Fleshed out Biped, Team, and World classes --- .../SeniorDesignProject/Biped.cpp | 49 +++++++++-------- .../SeniorDesignProject/Biped.h | 33 +++++++----- .../SeniorDesignProject.vcxproj | 2 - .../SeniorDesignProject.vcxproj.filters | 6 --- .../SeniorDesignProject/Team.cpp | 36 +++++++++---- .../SeniorDesignProject/Team.h | 8 +-- .../SeniorDesignProject/World.cpp | 53 ++++++++++--------- .../SeniorDesignProject/World.h | 9 ++-- 8 files changed, 106 insertions(+), 90 deletions(-) diff --git a/SeniorDesignProject/SeniorDesignProject/Biped.cpp b/SeniorDesignProject/SeniorDesignProject/Biped.cpp index eb28f5e..6fe2d29 100644 --- a/SeniorDesignProject/SeniorDesignProject/Biped.cpp +++ b/SeniorDesignProject/SeniorDesignProject/Biped.cpp @@ -3,14 +3,7 @@ Biped::Biped() { - //stance = Stance->STANDBY; - //weapons[0]; - teamNumber = 1; - cameraHeight = 5.0f; - crawlCameraHeight = 5.0f; - teamColor = 1; - fire = false; - death = false; + Init(); } @@ -20,17 +13,15 @@ Biped::~Biped() void Biped::Init() { - //stance = Stance->STANDBY; - weapons[0]; + stance = walk; teamNumber = 1; - biped = new Biped; cameraHeight = 5.0f; crawlCameraHeight = 5.0f; teamColor = 1; } -/*Stance Biped::getStance() +Biped::Stance Biped::getStance() { return stance; } @@ -38,25 +29,33 @@ void Biped::Init() void Biped::setStance(Stance stance) { Biped::stance = stance; -}*/ - -/*Weapon Biped::getWeapon(){ - return weapons[10]; } -void Biped::setWeapon(Weapon gunType){ -}*/ +Weapon Biped::getWeapon(){ + return weapons.front(); +} +void Biped::pushWeapon(Weapon newWeapon){ + weapons.push_front(newWeapon); +} int Biped::getTeam(){ return teamNumber; } -void Biped::setTeam(int team){ - +void Biped::nextWeapon(){ + weapons.push_back(weapons.front()); + weapons.pop_front(); +} +void Biped::prevWeapon(){ + weapons.push_front(weapons.back()); + weapons.pop_back(); +} +void Biped::setTeam(int _team){ + teamNumber = _team; } int Biped::takeHit(int damage){ - + stats.setHealth(stats.getHealth()-damage); } -bool Biped::fire(){ - return fire; +void Biped::fire(){ + //TODO: implement } @@ -89,8 +88,8 @@ void Biped::setTeamColor(int newColor){ teamColor = newColor; } bool Biped::getDeath(){ - return death; + return dead; } void Biped::setDeath(bool isDead){ - death = isDead; + dead = isDead; } diff --git a/SeniorDesignProject/SeniorDesignProject/Biped.h b/SeniorDesignProject/SeniorDesignProject/Biped.h index 76dea26..71c25cf 100644 --- a/SeniorDesignProject/SeniorDesignProject/Biped.h +++ b/SeniorDesignProject/SeniorDesignProject/Biped.h @@ -1,16 +1,20 @@ #pragma once #include "Object.h" -#include "Stance.h" #include "Weapon.h" +#include class Biped : - public Object -{ + public Object{ + +enum Stance { sprint, walk, crouch }; + public: void Init(); Stance getStance(); - void setStance(Stance iCanMove); - //Weapon getWeapon(); - //void setWeapon(Weapon gunType); + void setStance(Stance stance); + Weapon getWeapon(); + void pushWeapon(Weapon gunType); + void nextWeapon(); + void prevWeapon(); int getTeam(); void setTeam(int team); int takeHit(int damage); @@ -23,7 +27,7 @@ class Biped : void setTeamColor(int newColor); bool getDeath(); void setDeath(bool isDead); - + void fire(); Biped(); ~Biped(); @@ -31,11 +35,12 @@ class Biped : protected: - - Stance stance; - Weapon weapons[10]; - int teamNumber; - float cameraHeight; - float crawlCameraHeight; - int teamColor; + Stance stance; + std::deque weapons; + int teamNumber; + float cameraHeight; + float crawlCameraHeight; + int teamColor; + bool dead; + Stats stats; }; diff --git a/SeniorDesignProject/SeniorDesignProject/SeniorDesignProject.vcxproj b/SeniorDesignProject/SeniorDesignProject/SeniorDesignProject.vcxproj index d3eabdc..55884f6 100644 --- a/SeniorDesignProject/SeniorDesignProject/SeniorDesignProject.vcxproj +++ b/SeniorDesignProject/SeniorDesignProject/SeniorDesignProject.vcxproj @@ -136,13 +136,11 @@ - - diff --git a/SeniorDesignProject/SeniorDesignProject/SeniorDesignProject.vcxproj.filters b/SeniorDesignProject/SeniorDesignProject/SeniorDesignProject.vcxproj.filters index aee7836..361eb8c 100644 --- a/SeniorDesignProject/SeniorDesignProject/SeniorDesignProject.vcxproj.filters +++ b/SeniorDesignProject/SeniorDesignProject/SeniorDesignProject.vcxproj.filters @@ -128,15 +128,9 @@ Header Files - - Header Files - Header Files - - Header Files - Header Files diff --git a/SeniorDesignProject/SeniorDesignProject/Team.cpp b/SeniorDesignProject/SeniorDesignProject/Team.cpp index 36da6a7..f73c28a 100644 --- a/SeniorDesignProject/SeniorDesignProject/Team.cpp +++ b/SeniorDesignProject/SeniorDesignProject/Team.cpp @@ -1,28 +1,44 @@ #pragma once #include "Team.h" -Team::Team() +Team::Team(int teamNumber) { - + Init({}, 0, teamNumber); } +Team::Team(Biped* _members[], int size, int teamNumber) +{ + Init(_members, size, teamNumber); +} Team::~Team() { } -void Team::Init(Biped* _members[],int size){ - if (memberCount <= MAX_MEMBERS){ - for (int i = 0; i < size; i++){ - addMember(_members[i]); - } +void Team::Init(Biped* _members[],int size,int teamNumber){ + teamNum = teamNumber; + for (int i = 0; i < size; i++){ + addMember(_members[i],false); } } -void Team::addMember(Biped* member){ - members[memberCount] = member; - memberCount++; +void Team::addMember(Biped* member,bool forceIntoTeam){ + if (memberCount <= MAX_MEMBERS){ + if (forceIntoTeam){ + member->setTeam(teamNum); + } + if (member->getTeam() == teamNum){ + members[memberCount] = member; + memberCount++; + } + else{ + //TODO: throw an error, player doesn't belong in this team! + } + } + else{ + //TODO: Make error for "not enough room"! + } } Biped* Team::getMember(int index){ diff --git a/SeniorDesignProject/SeniorDesignProject/Team.h b/SeniorDesignProject/SeniorDesignProject/Team.h index f020283..3742c98 100644 --- a/SeniorDesignProject/SeniorDesignProject/Team.h +++ b/SeniorDesignProject/SeniorDesignProject/Team.h @@ -6,17 +6,19 @@ class Team { public: - void Init(Biped* members[MAX_MEMBERS],int memberCount); - void addMember(Biped* member); + void Init(Biped* members[MAX_MEMBERS],int memberCount,int teamNumber); + void addMember(Biped* member,bool forceIntoTeam); Biped* getMember(int index); Biped** getMembers(); - Team(); + Team(int teamNumber); + Team::Team(Biped* _members[], int size, int teamNumber); ~Team(); private: protected: + int teamNum; int memberCount; Biped* members[MAX_MEMBERS]; }; \ No newline at end of file diff --git a/SeniorDesignProject/SeniorDesignProject/World.cpp b/SeniorDesignProject/SeniorDesignProject/World.cpp index ea8ec74..285d95d 100644 --- a/SeniorDesignProject/SeniorDesignProject/World.cpp +++ b/SeniorDesignProject/SeniorDesignProject/World.cpp @@ -15,12 +15,12 @@ World::~World() void World::Init(){ playerIndex = -1; for (int team = 0; team < NUMBER_TEAMS; team++){ - for (int Biped = 0; Biped < TEAM_SIZE; Biped++){ - int i = team*TEAM_SIZE + Biped; + for (int teamBipedIndex = 0; teamBipedIndex < TEAM_SIZE; teamBipedIndex++){ + int i = (team*TEAM_SIZE) + teamBipedIndex; if (playerIndex == -1 && team == FRIENDLY_TEAM){ - playerIndex = i; + setPlayer(i); } - people[i].setTeam(team); + bipeds[i]->setTeam(team); } } } @@ -32,24 +32,28 @@ void World::setPlayer(int index) Biped* World::getPlayer() { - return &people[playerIndex]; + return bipeds[playerIndex]; } Biped* World::getBiped(int index) { - return &people[index]; + return bipeds[index]; } //This method is inneficient. Use sparingly. -/*Biped** World::getTeam(int teamNum, bool aliveOnly){ - //Create a new array of Biped pointers. - //Copy from people[] to team[] if teamIndex matches. - -}*/ +Team* World::getTeam(int teamNum, bool aliveOnly){ + Team* team = new Team(teamNum); + //for each player, put them in the team object + for (int i = 0; i < TEAM_SIZE*NUMBER_TEAMS; i++){ + if (!aliveOnly || !bipeds[i]->getDeath()){ + team->addMember(bipeds[i], false); + } + } +} //This method is inneficient. Use sparingly. int World::getTeamSize(int teamNum, bool aliveOnly){ int peopleInTeam = 0; for (int i = 0; i < TEAM_SIZE*NUMBER_TEAMS; i++){ - if (people[i].getTeam() == teamNum && (!aliveOnly || people[i].getDeath())){ + if (bipeds[i]->getTeam() == teamNum && (!aliveOnly || bipeds[i]->getDeath())){ peopleInTeam++; } } @@ -57,24 +61,21 @@ int World::getTeamSize(int teamNum, bool aliveOnly){ } //Divides the players by team -/*Biped** World::getTeams(bool aliveOnly){ - //Team size must be able to include all players, in the case that a player converted everyone to their team. - Biped* teams[NUMBER_TEAMS][TEAM_SIZE*NUMBER_TEAMS]; - int teamCounts[NUMBER_TEAMS]; - //set all teamCounts to zero - for (int i = 0; i < NUMBER_TEAMS; i++) - teamCounts[i] = 0; - //for each player, put them in an array in teams. +Team** World::getTeams(bool aliveOnly){ + //Initialize teams + Team* teams[NUMBER_TEAMS]; + for (int i = 0; i < NUMBER_TEAMS; i++){ + teams[i] = new Team(i); + } + //for each player, put them in their team object for (int i = 0; i < TEAM_SIZE*NUMBER_TEAMS; i++){ - if (!aliveOnly || people[i].getDeath()){ - int teamNum = people[i].getTeam(); - teams[teamNum][teamCounts[teamNum]] = &people[i]; - teamCounts[teamNum]++; + if (!aliveOnly || !bipeds[i]->getDeath()){ + teams[bipeds[i]->getTeam()]->addMember(bipeds[i],false); } } return teams; -}*/ +} void World::convert(int BipedIndex) { - people[BipedIndex].setTeam(FRIENDLY_TEAM); + bipeds[BipedIndex]->setTeam(FRIENDLY_TEAM); } \ No newline at end of file diff --git a/SeniorDesignProject/SeniorDesignProject/World.h b/SeniorDesignProject/SeniorDesignProject/World.h index 53abac4..9014b77 100644 --- a/SeniorDesignProject/SeniorDesignProject/World.h +++ b/SeniorDesignProject/SeniorDesignProject/World.h @@ -1,5 +1,6 @@ #pragma once -#include "Person.h" +#include "Biped.h" +#include "Team.h" #define TEAM_SIZE 5 #define NUMBER_TEAMS 2 @@ -13,9 +14,9 @@ class World void convert(int BipedIndex); Biped* getPlayer(); Biped* getBiped(int index); - //Biped** getTeam(int teamIndex, bool aliveOnly); + Team* getTeam(int teamIndex, bool aliveOnly); int getTeamSize(int teamIndex, bool aliveOnly); - //Biped** getTeams(bool aliveOnly); + Team** getTeams(bool aliveOnly); World(); @@ -25,5 +26,5 @@ class World protected: int playerIndex; - Person* people[TEAM_SIZE*NUMBER_TEAMS]; + Biped* bipeds[TEAM_SIZE*NUMBER_TEAMS]; }; \ No newline at end of file