Kaktusen

Untitled

Nov 3rd, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. //main.cpp
  2. #include <nds.h>
  3. #include <stdio.h>
  4. #include <iostream>
  5. #include <string>
  6.  
  7. #include "fight.h"
  8.  
  9. using namespace std;
  10.  
  11. void OnKeyPressed(int key) {
  12. if(key > 0)
  13. iprintf("%c", key);
  14. }
  15.  
  16. int main(void) {
  17. //init
  18. consoleDemoInit();
  19.  
  20. Keyboard *kbd = keyboardDemoInit();
  21.  
  22. kbd->OnKeyPressed = OnKeyPressed;
  23.  
  24. while(true) {
  25. int key = keyboardUpdate();
  26. cout << "Whats your name?\n";
  27.  
  28. if(key > 0) {
  29. cout << key;
  30. }
  31.  
  32. swiWaitForVBlank();
  33. consoleClear();
  34.  
  35. while(true) {
  36. int choose;
  37.  
  38. cout << "1) Find battle" << endl
  39. << "9) Exit game" << endl;
  40.  
  41. cin >> choose;
  42.  
  43. if(key > 0) {
  44. cout << key;
  45. }
  46.  
  47. if(choose == 1) {
  48. cHandleEvents.fight();
  49. }
  50.  
  51. if(choose == 9) {
  52. break;
  53. }
  54.  
  55. swiWaitForVBlank();
  56. consoleClear();
  57. }
  58. break;
  59. }
  60. return 0;
  61. }
  62.  
  63. //fight
  64. #include <nds.h>
  65. #include <stdio.h>
  66. #include <iostream>
  67. #include <ctime>
  68. #include <string>
  69.  
  70. #include "fight.h"
  71. #include "player.h"
  72.  
  73. using namespace std;
  74.  
  75. int monster;
  76.  
  77. void handleEvents::findMonster() {
  78. srand(time(NULL));
  79.  
  80. int random = rand() % 3 + 1;
  81.  
  82. if(random == 1) {
  83. monster = 1;
  84. }
  85.  
  86. if(random == 2) {
  87. monster = 2;
  88. }
  89.  
  90. if(random == 3) {
  91. monster = 3;
  92. }
  93. }
  94.  
  95. void handleEvents::fightMonster1() {
  96. int choose;
  97. cMonster1.hp = 1;
  98. char enemy[256] = "Stone";
  99.  
  100. while(true) {
  101. cout << enemy << "\n" << "Hp: " << cMonster1.hp << "\n\n";
  102. cout << cPlayer.name << "\n" << "Lives: " << cPlayer.lives << "Health: " << cPlayer.health << "Mana: " << cPlayer.mana << "\n\n";
  103.  
  104. cout << "1: Fight\n"
  105. << "9 Run away!\n";
  106.  
  107. cout << "Choose: ";
  108.  
  109. cin >> choose;
  110.  
  111. if(choose == 1) {
  112. cMonster1.hp-=1;
  113. }
  114.  
  115. if(cMonster1.hp <= 0) {
  116. break;
  117. }
  118.  
  119. swiWaitForVBlank();
  120. consoleClear();
  121. }
  122. }
  123.  
  124. void handleEvents::fightMonster2() {
  125. int choose;
  126. char enemy[256] = "Stone";
  127.  
  128. while(true) {
  129. cout << enemy << "\n" << "Hp: " << cMonster2.hp << "\n\n";
  130. cout << cPlayer.name << "\n" << "Lives: " << cPlayer.lives << "Health: " << cPlayer.health << "Mana: " << cPlayer.mana << "\n\n";
  131.  
  132. cout << "1: Fight\n"
  133. << "9 Run away!\n";
  134.  
  135. cout << "Choose: ";
  136.  
  137. if(choose == 1) {
  138. cMonster2.hp-=1;
  139. }
  140.  
  141. if(cMonster2.hp <= 0) {
  142. break;
  143. }
  144.  
  145. swiWaitForVBlank();
  146. consoleClear();
  147. }
  148. }
  149.  
  150. void handleEvents::fightMonster3() {
  151. int choose;
  152. char enemy[256] = "Stone";
  153.  
  154. while(true) {
  155. cout << enemy << "\n" << "Hp: " << cMonster3.hp << "\n\n";
  156. cout << cPlayer.name << "\n" << "Lives: " << cPlayer.lives << "Health: " << cPlayer.health << "Mana: " << cPlayer.mana << "\n\n";
  157.  
  158. cout << "1: Fight\n"
  159. << "9 Run away!\n";
  160.  
  161. cout << "Choose: ";
  162.  
  163. if(choose == 1) {
  164. cMonster3.hp -= 1;
  165. }
  166.  
  167. if(cMonster2.hp <= 0) {
  168. break;
  169. }
  170.  
  171. swiWaitForVBlank();
  172. consoleClear();
  173. }
  174. }
  175.  
  176. void handleEvents::fight() {
  177. while(true) {
  178. findMonster();
  179.  
  180. if(monster == 1) {
  181. fightMonster1();
  182. }
  183.  
  184. if(monster == 2) {
  185. fightMonster2();
  186. }
  187.  
  188. if(monster == 3) {
  189. fightMonster3();
  190. }
  191. }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment