Advertisement
Guest User

Untitled

a guest
Apr 27th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <vector>
  5. #include <string>
  6. #include <ctime>
  7. #include <conio.h>
  8. //#include "Entity.h"
  9.  
  10. using namespace std;
  11.  
  12. class World {};
  13. class Human;
  14. class Vampire;
  15. class Werewolf;
  16.  
  17. //Press N to start, while console is open
  18.  
  19. bool debug = true;
  20. int turn = 0;
  21. int people = 2000;
  22. int people_was = people;
  23. int sity = 1;//see sity_state()
  24. bool threat_awareness = false;
  25.  
  26.  
  27. class Obj : public World
  28. {};
  29.  
  30. class Build : public Obj{};
  31.  
  32. class House : public Build
  33. {};
  34.  
  35. class Entity : public World
  36. {
  37. private:
  38. public:
  39. //string type;
  40. //virtual void suck() = 0;
  41. //virtual void convert() = 0;
  42. };
  43.  
  44. vector<Vampire> vamps(0);
  45. vector<Human> humans(0);
  46. vector<Werewolf> wolfs(0);
  47.  
  48.  
  49. class Car : public Obj
  50. {};
  51.  
  52. bool attack(double attacker, double defender)
  53. {
  54. double allforce;
  55. allforce = attacker + defender;
  56.  
  57. int chance;
  58. int percent = allforce / 100;
  59. chance = allforce - defender;
  60. bool TrueFalse = (rand() % 100) < chance;
  61. return TrueFalse;
  62. }
  63.  
  64. class Human : public Entity
  65. {
  66. private:
  67. double force;
  68. string type = "civil";
  69. bool alive = true;
  70. bool hystorical_figure = false;
  71. public:
  72. Human(){}
  73. Human(string in_type)
  74. {
  75. force = 1;
  76. if (in_type == "civil")
  77. {
  78. type = "civil";
  79. }
  80. if (in_type == "soldier")
  81. {
  82. force *= 3;
  83. type = "soldier";
  84. }
  85. if (in_type == "police")
  86. {
  87. force *= 2;
  88. type = "police";
  89. }
  90. humans.push_back(*this);
  91. }
  92.  
  93.  
  94. void set_aware(){ force *= 1.5; }
  95.  
  96. string get_type()
  97. {
  98. return type;
  99. }
  100.  
  101. double get_force()
  102. {
  103. return force;
  104. }
  105.  
  106. bool is_alive()
  107. {
  108. return alive;
  109. }
  110. bool is_hystorical_figure()
  111. {
  112. return hystorical_figure;
  113. }
  114. void make_hystorical_figure()
  115. {
  116. hystorical_figure = true;
  117. }
  118.  
  119. void kill()
  120. {
  121. alive = false;
  122. }
  123. void attack_vampire(Vampire &v)
  124. {
  125. bool succes = attack(get_force(), v.get_force());
  126. if(succes == true)
  127. {
  128. v.kill();
  129. }
  130. else kill();
  131. }
  132. void attack_werewolf(Werewolf &w)
  133. {
  134. bool succes = attack(get_force(), w.get_force());
  135. if (succes == true)
  136. {
  137. w.kill();
  138. }
  139. else kill();
  140. }
  141. };
  142.  
  143. template <class Pick>
  144. int pick(vector<Pick> vec)
  145. {
  146. int out = 0 + rand() % vec.size();
  147. return out;
  148. }
  149.  
  150. int vampire_coolness = 10;
  151. class Vampire : public Entity
  152. {
  153. private:
  154. int hunger; int generate = 1; double force;
  155. bool alive = true;
  156. //Vampire parent;
  157. public:
  158. Vampire(){ }
  159. Vampire(int gen)
  160. {
  161. //generate = v.generate;
  162. generate = gen + 1;
  163. force = 1 * (vampire_coolness/generate);//not 1 - it must have a human type force
  164. vamps.push_back(*this);
  165. //vamps.push_back(*this);
  166. //inc_generation();
  167. }
  168. void suck(Human &h)
  169. {
  170. //people--;
  171. if (h.is_alive() == true)
  172. {
  173. h.kill();
  174. }
  175. }
  176.  
  177. double get_force()
  178. {
  179. return force;
  180. }
  181.  
  182. void inc_generation(int gen)
  183. {
  184. generate = gen++;
  185. }
  186.  
  187. int generation()
  188. {
  189. return generate;
  190. }
  191.  
  192. bool is_alive()
  193. {
  194. return alive;
  195. }
  196. void kill()
  197. {
  198. alive = false;
  199. }
  200.  
  201. void convert(Human &h)
  202. {
  203. //people--;
  204. if (h.is_alive() == true)
  205. {
  206. h.kill();
  207. Vampire *vamp = new Vampire(generate);
  208. }//vamp->inc_generation(generate); //vamp->generation() = v.generation(); }
  209. //vamp->inc_generation(); //vamp->inc_generation();
  210. //vamp->generation += 1;
  211. }
  212.  
  213. void attack_human(Human &h)
  214. {
  215. bool succes = attack(get_force(), h.get_force());
  216. if (succes == true)
  217. {
  218. h.kill();
  219. }
  220. else kill();
  221. }
  222. void attack_werewolf(Werewolf &w)
  223. {
  224. bool succes = attack(get_force(), w.get_force());
  225. if (succes == true)
  226. {
  227. w.kill();
  228. }
  229. else kill();
  230. }
  231.  
  232. };
  233.  
  234. class Werewolf : public Entity
  235. {
  236. private:
  237. double force;
  238. bool alive = true;
  239. public:
  240. Werewolf()
  241. {
  242. force = 5;
  243. wolfs.push_back(*this);
  244. }
  245.  
  246. double get_force()
  247. {
  248. return force;
  249. }
  250.  
  251. bool is_alive()
  252. {
  253. return alive;
  254. }
  255. void kill()
  256. {
  257. alive = false;
  258. }
  259.  
  260. void attack_human(Human &h)
  261. {
  262. bool succes = attack(get_force(), h.get_force());
  263. if (succes == true)
  264. {
  265. h.kill();
  266. }
  267. else kill();
  268. }
  269. void attack_vampire(Vampire &v)
  270. {
  271. bool succes = attack(get_force(), v.get_force());
  272. if (succes == true)
  273. {
  274. v.kill();
  275. }
  276. else kill();
  277. }
  278. };
  279.  
  280. int hystorical_figures(char in_char)
  281. {
  282. int count = 0;
  283. for (int i = 0; i < humans.size(); i++)
  284. {
  285. if (in_char == 'a')
  286. {
  287. count++;
  288. }
  289. if (in_char == 'd')
  290. {
  291. count++;
  292. }
  293. }
  294. return count;
  295. }
  296.  
  297. int humans_count(string in_string)
  298. {
  299. int count = 0;
  300. for (int i = 0; i < humans.size(); i++)
  301. {
  302. if (in_string == "all")
  303. {
  304. count++;
  305. }
  306. if (in_string == "alive")
  307. {
  308. if(humans[i].is_alive() == true)
  309. count++;
  310. }
  311. if (in_string == "dead")
  312. {
  313. if (humans[i].is_alive() == false)
  314. count++;
  315. }
  316. if (in_string == "civil")
  317. {
  318. if(humans[i].get_type() == "civil" && humans[i].is_alive() == true)
  319. count++;
  320. }
  321. if (in_string == "police")
  322. {
  323. if (humans[i].get_type() == "police" && humans[i].is_alive() == true)
  324. count++;
  325. }
  326. if (in_string == "soldier")
  327. {
  328. if (humans[i].get_type() == "soldier" && humans[i].is_alive() == true)
  329. count++;
  330. }
  331. }
  332. return count;
  333. }
  334.  
  335. int vampire_count()
  336. {
  337. int count=0;
  338. for (int i = 0; i < vamps.size(); i++)
  339. {
  340. if(vamps[i].is_alive() == true)
  341. count++;
  342. }
  343. return count;
  344.  
  345. }
  346.  
  347. int werewolf_count()
  348. {
  349. int count = 0;
  350. for (int i = 0; i < wolfs.size(); i++)
  351. {
  352. if (wolfs[i].is_alive() == true)
  353. count++;
  354. }
  355. return count;
  356. }
  357.  
  358. void game_turn()
  359. {
  360. int vamps_cpy = vamps.size();
  361. int wolfs_cpy = wolfs.size();
  362. srand(time(0));
  363. int act;// , pick;
  364. for (int i = 0; i < vamps_cpy; i++)
  365. {
  366. if (vamps[i].is_alive() == true)
  367. {
  368. if (threat_awareness == true)
  369. act = 1 + rand() % 2;
  370. else act = 1;
  371. if (act == 1)
  372. {
  373. act = 1 + rand() % 2;
  374. //pick = 0 + rand() % humans.size();
  375. if (act == 1 && vamps[i].generation() < 10)
  376. vamps[i].convert(humans[pick(humans)]);
  377. if (act == 2)
  378. vamps[i].suck(humans[pick(humans)]);
  379. }
  380. if (act == 2)
  381. {
  382. act = 1 + rand() % 2;
  383. if (act == 1)
  384. {
  385. vamps[i].attack_human(humans[pick(humans)]);
  386. }
  387. if (act == 2)
  388. {
  389. vamps[i].attack_werewolf(wolfs[pick(wolfs)]);
  390. }
  391. }
  392. }
  393. }
  394. for (int i = 0; i < wolfs_cpy; i++)
  395. {
  396. act = 1 + rand() % 2;
  397. if (wolfs[i].is_alive() == true)
  398. {
  399. if (act == 1)
  400. {
  401. wolfs[i].attack_human(humans[pick(humans)]);
  402. }
  403. if (act == 2)
  404. {
  405. wolfs[i].attack_vampire(vamps[pick(vamps)]);
  406. }
  407. }
  408. }
  409. if (threat_awareness == true)
  410. {
  411. for (int i = 0; i < humans.size(); i++)
  412. {
  413. if ((humans[i].get_type() == "police" || humans[i].get_type() == "soldier") && humans[i].is_alive() == true)
  414. {
  415. act = 1 + rand() % 2;
  416. if (act == 1)
  417. {
  418. humans[i].attack_vampire(vamps[pick(vamps)]);
  419. }
  420. if (act == 2)
  421. {
  422. humans[i].attack_werewolf(wolfs[pick(wolfs)]);
  423. }
  424. }
  425. }
  426. }
  427. turn++;
  428. }
  429. void sity_state()
  430. {
  431. int percents;
  432. int percent = people_was / 100;
  433. percents = humans_count("alive") / percent;
  434. cout << percents << "% people alive - ";
  435. if(percents > 90)
  436. {
  437. sity = 1;
  438. cout << "all still" << endl;
  439. }
  440. if (percents < 90 && percents > 61)
  441. {
  442. sity = 2;
  443. cout << "police panic" << endl;
  444. }
  445. if (percents < 60 && percents > 31)
  446. {
  447. sity = 3;
  448. if(threat_awareness == false)
  449. {
  450. for (int i = 0; i < people / 10; i++)
  451. {
  452. Human *civil = new Human("soldier");
  453. }
  454. }
  455. threat_awareness = true;
  456. cout << "massive army forses invade into sity" << endl;
  457. }
  458. if (percents < 31 )
  459. {
  460. sity = 4;
  461. cout << "Apocalypse come" << endl;
  462. }
  463.  
  464.  
  465. }
  466.  
  467. void results()
  468. {}
  469.  
  470. void game_process()
  471. {
  472. while (humans_count("alive") > 0)
  473. {
  474. system("cls");
  475. cout << "Turn: " << turn << endl;
  476. cout << "Humans: " << humans_count("alive") << "(" << " Civils: " << humans_count("civil") << " Police: " << humans_count("police") << "cars: " << " Army: " << humans_count("soldier")<< " armored vechines: " << " aviation: " << ")" << " Humans dead: " << humans_count("dead") << endl;
  477. cout << "Vamps: " << vampire_count()<<endl;
  478. cout << "Werewolfs:" << werewolf_count() << endl;
  479. sity_state();
  480. if (debug == true)
  481. {
  482. //events()
  483. //hystorical figures()
  484. for (int i = 1; i < 11; i++)
  485. {
  486. int k = 0;
  487. cout << "Vamps of " << i << "'st generation count: ";
  488. for (int j = 0; j < vamps.size(); j++)
  489. {
  490. if (vamps[j].generation() == i)
  491. k++;
  492. }
  493. cout << k << endl;
  494. }
  495. }
  496. Sleep(1000);
  497. game_turn();
  498. }
  499. cout << endl << "game over" << endl;
  500. results();
  501.  
  502. }
  503.  
  504.  
  505.  
  506. void game_init()
  507. {
  508. for (int i = 0; i < people; i++)
  509. {
  510. Human *civil = new Human("civil");
  511. //civil->set_type("civil");
  512. }
  513. for (int i = 0; i < people/100; i++)
  514. {
  515. Human *civil = new Human("police");
  516. //civil->set_type("police");
  517. }
  518. for (int i = 0; i < people/150; i++)
  519. {
  520. Human *civil = new Human("soldier");
  521. //civil->set_type("soldier");
  522. }
  523. Vampire *cain = new Vampire(0);
  524. Werewolf *wolfy = new Werewolf;
  525. game_process();
  526. }
  527.  
  528. int menu()
  529. {
  530. cout << "n - new game" << endl;
  531. cout << "l - load" << endl;
  532. cout << "a - about" << endl;
  533. cout << "x - exit" << endl;
  534. char input = _getch();
  535. if (input == 'n')
  536. {
  537. return 1;
  538. }
  539. if (input == 'l')
  540. {
  541. return 2;
  542. }
  543. if (input == 'a')
  544. {
  545. return 3;
  546. }
  547. if (input == 'x')
  548. {
  549. return 0;
  550. }
  551. }
  552.  
  553. void game()
  554. {
  555. switch (menu())
  556. {
  557. case 0:
  558. break;
  559. case 1:
  560. game_init();
  561. break;
  562. case 2:
  563. cout << "This feature for future";
  564. break;
  565. case 3:
  566. cout << "This feature for future";
  567. break;
  568. default:
  569. cout << "error, please try again; you input must be in english languagagagage" << endl;
  570. game();
  571. break;
  572. }
  573. }
  574.  
  575. int main()
  576. {
  577. srand(time(0));
  578. game();
  579. system("pause");
  580. return 0;
  581. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement