I had a hard time understand exactly what an observer pattern was, but I produced the following code for my project. It uses SDL. I am using the boost library to implement signals and therefore implementing my observer pattern. Does this look correct?
/* This is setting up our signal for sending observations */ boost::signals2::signal<void (char, int, int)> sig; /* Subjects the Observer will connect with */ sig.connect(&setChest); sig.connect(&setNonTraverse); sig.connect(&setEntry); sig.connect(&setExit); std::cout << "Waiting for user-interaction. Press on the 'X' to quit" << std::endl; while ( !quit ) { status = SDL_WaitEvent(&event); //wait for an event to occur switch (event.type) { //check the event type case SDL_KEYDOWN: //Check if a key was pressed. key = SDL_GetKeyName(event.key.keysym.sym); break; case SDL_MOUSEBUTTONUP: sig(key[0],event.button.x/32,event.button.y/32); break; case SDL_QUIT: // Click on the 'X' to close the window. exit ( 1 ); break; } } //while return true; }