Skip to content

Commit

Permalink
Today's Debugging Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ejatgit committed May 27, 2024
1 parent a8efec3 commit bc4aa2b
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 82 deletions.
15 changes: 9 additions & 6 deletions CPP/High_Voltage/GlobalVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
//Public cActivePlayer As cPlayer
#include "GlobalVariables.h"
namespace Shared_Vars{
extern int nInterAlive{ 0 };
extern int nInterKilled{ 0 };
extern int nTotalinterceptorsKilled{ 0 };
extern int nInterAlive{};
extern int nInterKilled{};
extern int nTotalinterceptorsKilled{};
extern std::string rMaze[iMazeRows][iMazeCols]{};
extern HANDLE hStdout{};
extern HANDLE hStdin{};
Expand All @@ -23,7 +23,8 @@ namespace Shared_Vars{

//reference for below collection
// https://www.codeproject.com/Articles/6381/Creating-a-Collection-Class-in-C
template <class TBase>
/*
template <class TBase>
//class CustomCollection {
//protected:
//The Vector container that will hold the collection of Items
Expand Down Expand Up @@ -65,11 +66,13 @@ namespace Shared_Vars{
}
//Operator Returning a reference to TBase
template <class TBase>
TBase& CustomCollection<TBase>::operator[](int ItemKey)
TBase& CustomCollection<TBase>::operator [](int ItemKey)
{
return m_items[ItemKey];
}
//};
*/
//CustomCollection<cInterceptor> interceptorCollection;
extern CustomCollection<cInterceptor> interceptorCollection{};
// extern CustomCollection<cInterceptor> interceptorCollection{};
extern std::vector<cInterceptor> interceptorCollection{};
}
11 changes: 7 additions & 4 deletions CPP/High_Voltage/GlobalVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ namespace Shared_Vars {

//reference for below collection
// https://www.codeproject.com/Articles/6381/Creating-a-Collection-Class-in-C
template <class TBase>
/*
template <class TBase>
class CustomCollection
{
protected:
//The Vector container that will hold the collection of Items
std::vector<TBase> m_items;
public:
int Add(void); //{ return (m_items.size() - 1); }
int Add(void) ; //{ return (m_items.size() - 1); }
//Function to return the memory address of a specific Item
TBase* GetAddress(int ItemKey);
Expand All @@ -74,15 +75,17 @@ namespace Shared_Vars {
int Count(void);
//Operator Returning a reference to TBase
TBase& operator[](int ItemKey);
TBase& operator [](int ItemKey);
};
*/
//template <class TBase>
//CustomCollection<TBase> interceptorCollection;
extern CustomCollection<cInterceptor> interceptorCollection;
// extern CustomCollection<cInterceptor> interceptorCollection;
//CustomCollection interceptorCollection;
//Public cActivePlayer As cPlayer
//cPlayer cActivePlayer{};
extern std::vector<cInterceptor> interceptorCollection;
}

#endif
24 changes: 24 additions & 0 deletions CPP/High_Voltage/cInterceptor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
//VBA code below. New code and class definition in the header file.
#include"GlobalVariables.h"

bool cInterceptor::Alive() {
return cInterceptor::m_bAlive;
}

void cInterceptor::Alive(bool bNowAlive) {
cInterceptor::m_bAlive = bNowAlive;
}

int cInterceptor::Row() {
return cInterceptor::m_iRow;
}

void cInterceptor::Row(int iNowRow) {
cInterceptor::m_iRow = iNowRow;
}

int cInterceptor::Column() {
return cInterceptor::m_iColumn;
}

void cInterceptor::Column(int iNowCol) {
cInterceptor::m_iColumn = iNowCol;
}
/*VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Expand Down
9 changes: 6 additions & 3 deletions CPP/High_Voltage/cInterceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ class cInterceptor{
int m_iColumn{};

public:
bool Alive{ true };// () const { return m_bAlive; }
int Row{0};// () const { return m_iRow; }
int Column{0};// () const { return m_iColumn; }
bool Alive();// () const { return m_bAlive; }
void Alive(bool bNowAlive);
int Row();// () const { return m_iRow; }
void Row(int iNowRow);
int Column();// () const { return m_iColumn; }
void Column(int iNowCol);
};


Expand Down
29 changes: 29 additions & 0 deletions CPP/High_Voltage/cPlayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
//VBA code below. New code and class definition in the header file.
#include"GlobalVariables.h"

bool cPlayer::Alive() {
return cPlayer::m_bAlive;
}

void cPlayer::Alive(bool bNowAlive) {
cPlayer::m_bAlive = bNowAlive;
}

int cPlayer::Row() {
// cPlayer::m_iRow = iNowRow;
return cPlayer::m_iRow;
}

void cPlayer::Row(int iNowRow) {
cPlayer::m_iRow = iNowRow;
//return cPlayer::m_iRow;
}

int cPlayer::Column() {
//cPlayer::m_iColumn = iNowCol;
return cPlayer::m_iColumn;
}

void cPlayer::Column(int iNowCol) {
cPlayer::m_iColumn = iNowCol;
// return cPlayer::m_iColumn;
}

/*Option Explicit
Expand Down
9 changes: 6 additions & 3 deletions CPP/High_Voltage/cPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ class cPlayer
int m_iColumn{};

public:
bool Alive{ true };// () const { return m_bAlive; }
int Row{0};// () const { return m_iRow; }
int Column{0};// () const { return m_iColumn; }
bool Alive();// () const { return m_bAlive; }
void Alive(bool bNowAlive);
int Row();// () const { return m_iRow; }
void Row(int iNowRow);// () const { return m_iRow; }
int Column();// () const { return m_iColumn; }
void Column(int iNowCol);// () const { return m_iColumn; }
};
#endif
45 changes: 33 additions & 12 deletions CPP/High_Voltage/mBuildMaze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void SpawnPlayer(){
//Dim iColumn As Integer
//
//Set cActivePlayer = New cPlayer
cPlayer cActivePlayer;
// cPlayer cActivePlayer;
//
//iCount = 1
//
Expand All @@ -28,9 +28,9 @@ void SpawnPlayer(){
if (rMaze[iRow][iColumn] == sOpenAreaSymbol)
{
// cActivePlayer.Row = iRow
cActivePlayer.Row = iRow;
cActivePlayer.Row(iRow);
// cActivePlayer.Column = iColumn
cActivePlayer.Column = iColumn;
cActivePlayer.Column(iColumn);
// Exit Do
break;
}
Expand All @@ -40,7 +40,7 @@ void SpawnPlayer(){
//Loop While iCount < 1000
}//
//rMaze.Cells(cActivePlayer.Row, cActivePlayer.Column).Value = sPlayerSymbol
rMaze[cActivePlayer.Row][cActivePlayer.Column] = sPlayerSymbol;
rMaze[cActivePlayer.Row()][cActivePlayer.Column()] = sPlayerSymbol;
//Range("nPlayerCell").Value = rMaze.Cells(cActivePlayer.Row, cActivePlayer.Column).Address
//
//End Sub
Expand Down Expand Up @@ -69,12 +69,13 @@ void Spawninterceptors() {
// If rMaze.Cells(iRow, iColumn).Value = sOpenAreaSymbol Then
if (rMaze[iRow][iColumn] == sOpenAreaSymbol){
// cNowinterceptor.Row = iRow
cNowinterceptor.Row = iRow;
cNowinterceptor.Row(iRow);
// cNowinterceptor.Column = iColumn
cNowinterceptor.Column = iColumn;
cNowinterceptor.Column(iColumn);
// Call interceptorCollection.Add(cNowinterceptor)
int iCount = interceptorCollection.Add();
interceptorCollection[iCount] = cNowinterceptor;
//int iCount = interceptorCollection.Add();
//interceptorCollection[iCount] = cNowinterceptor;
interceptorCollection.push_back(cNowinterceptor);
// Exit Do
break;
// End If
Expand All @@ -86,6 +87,14 @@ void Spawninterceptors() {
//For Each cNowinterceptor In interceptorCollection
// rMaze.Cells(cNowinterceptor.Row, cNowinterceptor.Column).Value = sinterceptorSymbol
//Next cNowinterceptor
for (int i = 0; i < interceptorCollection.size(); ++i) {
cInterceptor cNowInterceptor;
cNowInterceptor = interceptorCollection[i];
// rMaze.Cells(cNowinterceptor.Row, cNowinterceptor.Column).Value = sinterceptorSymbol
rMaze[cNowInterceptor.Row()][cNowInterceptor.Column()] = sInterceptorSymbol;

}
nInterAlive = interceptorCollection.size() + 1;
//
//End Sub
}
Expand All @@ -104,7 +113,7 @@ void InstallHighVoltageBarriers(){
// iBarrierCount = 0
iBarrierCount = 0;
// For iCol = 1 To rMaze.Columns.Count
for (int iCol = 0; iRow < iMazeCols; ++iCol) {
for (int iCol = 0; iCol < iMazeCols; ++iCol) {
// If iRow = 1 Or iRow = rMaze.Rows.Count Then
if ((iRow == 0) || (iRow == iMazeRows - 1))
{
Expand Down Expand Up @@ -161,7 +170,7 @@ void ClearMaze(){
//For iRow = 1 To rMaze.Rows.Count
for (int iRow = 0; iRow < iMazeRows; ++iRow) {
// For iCol = 1 To rMaze.Columns.Count
for (int iCol = 0; iRow < iMazeCols; ++iCol) {
for (int iCol = 0; iCol < iMazeCols; ++iCol) {
// rMaze.Cells(iRow, iCol).Value = sOpenAreaSymbol
rMaze[iRow][iCol] = sOpenAreaSymbol;
// Next iCol
Expand Down Expand Up @@ -189,7 +198,7 @@ void InitialFillMaze(){
//Range("nInterKilled").Value = 0
//
//Call ClearMaze
ClearMaze();
//ClearMaze();
//Call InstallHighVoltageBarriers
InstallHighVoltageBarriers();
//Call Spawninterceptors
Expand All @@ -199,4 +208,16 @@ void InitialFillMaze(){
SpawnPlayer();
//Application.Calculation = xlCalculationAutomatic
//End Sub
};
DrawTheMaze();
}

void DrawTheMaze()
{
for (int iRow = 0; iRow < iMazeRows; ++iRow) {
for (int iCol = 0; iCol < iMazeCols; ++iCol) {
//rMaze[iRow][iCol] = sOpenAreaSymbol;
std::cout << rMaze[iRow][iCol];
}
std::cout << std::endl;
}
}
2 changes: 1 addition & 1 deletion CPP/High_Voltage/mBuildMaze.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ void Spawninterceptors();
void InstallHighVoltageBarriers();
void ClearMaze();
void InitialFillMaze();

void DrawTheMaze();
#endif
24 changes: 13 additions & 11 deletions CPP/High_Voltage/mController.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include"mController.h"
#include"mFunctions.h"
#include"mMoveCharacters.h"
#include"mBuildMaze.h"
//#include"High_Voltage.h"
#include"GlobalVariables.h"
bool UnLoadMe{ false };
bool UnLoadMe{};

void mController_Show() {
MsgBox("Make your move: ", "MsgBox0");
Output_A_Message("Make your move: ", "MsgBox0");
UnLoadMe = false;
std::string sNowInput{ "" };
do
{
Expand Down Expand Up @@ -58,17 +60,17 @@ void mController_Show() {
else
{
//do nothing
MsgBox("I don't understand.", "MsgBox0");
Output_A_Message("I don't understand.", "MsgBox0");
}
} while (UnLoadMe==false);
} while (UnLoadMe == false);
}



void CommandButton0_Click() {
int iRow{ ((rand() % iMazeRows) + 1) - Shared_Vars::cActivePlayer.Row };
int iColumn{ ((rand() % iMazeCols) + 1) - Shared_Vars::cActivePlayer.Column };
MsgBox("Super Jump!!!", "MsgBox0");
int iRow{ ((rand() % iMazeRows) + 1) - Shared_Vars::cActivePlayer.Row()};
int iColumn{ ((rand() % iMazeCols) + 1) - Shared_Vars::cActivePlayer.Column()};
Output_A_Message("Super Jump!!!", "MsgBox0");
MovePlayer(iRow, iColumn);
MoveInterceptors();
WhoIsAlive();
Expand Down Expand Up @@ -134,14 +136,14 @@ void CommandButtonExit_Click(){
}

void WhoIsAlive(){

if (Shared_Vars::cActivePlayer.Alive == false) {
MsgBox("You are dead. You lose.", "nMsgbox2");
DrawTheMaze();
if (Shared_Vars::cActivePlayer.Alive() == false) {
Output_A_Message("You are dead. You lose.", "nMsgbox2");
//Call Unload(Me)
UnLoadMe = true;
}
else if (CheckInterceptorsAlive() == false) {
MsgBox("All the interceptors are dead. You win.", "nMsgbox2");
Output_A_Message("All the interceptors are dead. You win.", "nMsgbox2");
//Call Unload(Me)
UnLoadMe = true;
}
Expand Down
Loading

0 comments on commit bc4aa2b

Please sign in to comment.