CConsoleHandler.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "stdafx.h"
  2. #include "CConsoleHandler.h"
  3. #include "CAdvmapInterface.h"
  4. #include "SDL.h"
  5. #include "SDL_thread.h"
  6. #include "CGameInfo.h"
  7. #include "global.h"
  8. #include "CGameState.h"
  9. #include "CCallback.h"
  10. #include "CPathfinder.h"
  11. #include "mapHandler.h"
  12. #include <sstream>
  13. int internalFunc(void * callback)
  14. {
  15. CCallback * cb = (CCallback*)callback;
  16. char * usersMessage = new char[500];
  17. std::string readed;
  18. while(true)
  19. {
  20. std::cin.getline(usersMessage, 500);
  21. std::istringstream readed;
  22. std::string pom(usersMessage);
  23. readed.str(pom);
  24. std::string cn; //command name
  25. readed >> cn;
  26. int3 src, dst;
  27. int heronum;
  28. int3 dest;
  29. switch (*cn.c_str())
  30. {
  31. case 'P':
  32. std::cout<<"Policzyc sciezke."<<std::endl;
  33. readed>>src>>dst;
  34. LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
  35. break;
  36. case 'm': //number of heroes
  37. std::cout<<"Number of heroes: "<<CGI->heroh->heroInstances.size()<<std::endl;
  38. break;
  39. case 'H': //position of hero
  40. readed>>heronum;
  41. std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->pos<<std::endl;
  42. break;
  43. case 'M': //move hero
  44. readed>>heronum>>dest;
  45. cb->moveHero(heronum, dest);
  46. break;
  47. }
  48. //SDL_Delay(100);
  49. }
  50. return -1;
  51. }
  52. void CConsoleHandler::runConsole()
  53. {
  54. SDL_Thread * myth = SDL_CreateThread(&internalFunc, cb);
  55. }