CConsoleHandler.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <sstream>
  11. int internalFunc(void * nothingUsed)
  12. {
  13. char * usersMessage = new char[500];
  14. std::string readed;
  15. while(true)
  16. {
  17. std::cin.getline(usersMessage, 500);
  18. std::istringstream readed;
  19. std::string pom(usersMessage);
  20. readed.str(pom);
  21. std::string cn; //command name
  22. readed >> cn;
  23. int3 src, dst;
  24. int heronum;
  25. int3 dest;
  26. switch (*cn.c_str())
  27. {
  28. case 'P':
  29. std::cout<<"Policzyc sciezke."<<std::endl;
  30. readed>>src>>dst;
  31. LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
  32. break;
  33. case 'm': //number of heroes
  34. std::cout<<"Number of heroes: "<<CGI->heroh->heroInstances.size()<<std::endl;
  35. break;
  36. case 'H': //position of hero
  37. readed>>heronum;
  38. std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->pos<<std::endl;
  39. break;
  40. case 'M': //move hero
  41. readed>>heronum>>dest;
  42. CGI->state->cb->moveHero(heronum, dest);
  43. break;
  44. }
  45. //SDL_Delay(100);
  46. }
  47. return -1;
  48. }
  49. void CConsoleHandler::runConsole()
  50. {
  51. SDL_Thread * myth = SDL_CreateThread(&internalFunc, NULL);
  52. }