Original Post
Hi, I cannot figure this one out...
#include "SDL_MainWindow.hpp"
#include "MasterMind.hpp"
void initialize_tacs(std::vector<MasterMind::Tac>*, MasterMind::Board&);
void display_tacs(std::vector<MasterMind::Tac>::iterator, MasterMind::Board&);
using std::cerr;
using std::endl;
int main(int args, char** argv)
{
try
{
SDL_Window window(SCREEN_WIDTH, SCREEN_HEIGHT, BPP,
SDL_HWSURFACE | SDL_DOUBLEBUF, "MasterMind");
MasterMind::Board board;
std::vector<MasterMind::Tac>* pTacs = new std::vector<MasterMind::Tac>;
pTacs->reserve(board.size());
initialize_tacs(pTacs, board);
std::vector<MasterMind::Tac>::iterator iTacs(pTacs->begin());
cerr << "vec size: " << pTacs->size() << endl;
bool quit = false;
while (quit == false)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
quit = true;
if (event.type == SDL_MOUSEBUTTONDOWN)
{
}
}
iTacs = pTacs->begin();
display_tacs(iTacs, board);
board.drawOn(window.me());
SDL_Flip(window.me());
}
delete[] pTacs;
}
catch(...)
{
cerr << "An error occurred" << endl;
}
return 0;
}
void initialize_tacs(std::vector<MasterMind::Tac>* pTacs, MasterMind::Board& board)
{
for (int i = 0; i < 8 ; i++)
{
MasterMind::Tac tac((Color)i, board); //i represents the color constant.
pTacs->push_back(tac);
cerr << i << endl;
}
return;
}
void display_tacs(std::vector<MasterMind::Tac>::iterator iter, MasterMind::Board& board)
{
for (int i = 0 ; i < board.numberOfTacs; i++)
{
cerr << "me" << endl;
iter->drawOn(board.me());
cerr << "me too" << endl;
iter++;
}
return;
}
Output:
1
2
3
4
5
6
7
vec size: 8
me
Fatal signal: Segmentation Fault (SDL Parachute Deployed)