fork download
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <string>
  4.  
  5.  
  6. #define MAX_EXITS_NUM 5
  7. #define MAX_EXITS_NPC 10
  8.  
  9.  
  10. template<int N>
  11. std::string operator+(const std::string &first, const std::string (&second)[N]) {
  12. std::string result = first;
  13. for (auto iter = std::begin(second); iter != std::end(second); ++iter) {
  14. result += *iter;
  15. }
  16.  
  17. return result;
  18. }
  19.  
  20.  
  21. class location {
  22. public:
  23. std::string name;
  24.  
  25. std::string desc;
  26.  
  27. int num_of_exits;
  28.  
  29. std::string exits[MAX_EXITS_NUM];
  30.  
  31. int num_of_NPC;
  32.  
  33. std::string NPCs[MAX_EXITS_NPC];
  34.  
  35.  
  36. location () {};
  37.  
  38. ~location () {};
  39.  
  40. location load_location(std::string) ;
  41.  
  42. std::string format_text_to_output();
  43. };
  44.  
  45.  
  46. int main () {
  47. std::cout <<"Hello world\n";
  48.  
  49. //make new location
  50. location asd;
  51. asd = asd.load_location("main");
  52. std:: cout << asd.format_text_to_output();
  53.  
  54. return 0;
  55. }
  56.  
  57. location location::load_location(std::string new_loc_name) {
  58.  
  59. //asking SDL to load file with location description
  60. //?
  61. //searching in file for new_loc_name string
  62. //?
  63. //parcing part of file from new_loc_name
  64. //somehow getting data from file
  65. int num_of_exits = 3;
  66. std::string exits [num_of_exits] = {"first exit\n", "second exit\n", "third exit\n"};
  67. int num_of_NPC = 1;
  68. std::string NPCs [num_of_NPC] = {"Gay_nigger\n"};
  69. location new_loc;
  70. new_loc.name = "Имя локацции " + new_loc_name;
  71. for (int i = 0; i < num_of_exits; i++) {
  72. new_loc.exits[i] = exits [i];
  73. }
  74.  
  75. new_loc.num_of_exits = num_of_exits;
  76. new_loc.num_of_NPC = num_of_NPC;
  77. for (int i = 0; i < num_of_NPC; i++) {
  78. new_loc.NPCs[i] = NPCs[i];
  79. }
  80.  
  81. new_loc.desc = "Большое и длинное описание локации\n";
  82.  
  83. return new_loc;
  84. }
  85.  
  86. std::string location::format_text_to_output() {
  87. std::string output;
  88. output = name +"\n\n" + desc + "possible exits\n\n" + exits + "\nNPC\n\n" + this->NPCs;
  89. return output;
  90. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Hello world
Имя локацции main

Большое и длинное описание локации
possible exits

first exit
second exit
third exit

NPC

Gay_nigger