Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. // File client.cc
  2.  
  3.  
  4. #include <vector>
  5.  
  6. #include <iostream>
  7.  
  8. #include <fstream>
  9.  
  10. #include <unistd.h> // for sleep
  11.  
  12. #include "GameEngineInterface.h"
  13.  
  14.  
  15.  
  16. using namespace std;
  17.  
  18.  
  19.  
  20. int
  21.  
  22. main (int argc, char *argv[])
  23.  
  24. {
  25.  
  26. // Initialize the ORB
  27.  
  28. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
  29.  
  30.  
  31.  
  32. // Connect to the Account
  33.  
  34. ifstream f ("account.ior");
  35.  
  36. string ior;
  37.  
  38. f >> ior;
  39.  
  40. CORBA::Object_var obj =
  41.  
  42. orb->string_to_object (ior.c_str());
  43.  
  44. GameEngineInterface_var engine = GameEngineInterface::_narrow (obj);
  45.  
  46. GamePiece thisGhost = engine->createNewGamePiece(1);
  47.  
  48. /*
  49.  
  50. while(1){
  51.  
  52. sleep(1);
  53.  
  54. cout << "hello there\n";
  55.  
  56. //GHOST AI GOES HERE.
  57.  
  58. engine->moveGamePiece(thisGhost.id, 2, 0);
  59.  
  60. }
  61.  
  62. return 0;
  63.  
  64. }
  65. */
  66.  
  67. int i = 0;
  68. int pacmanPosX, pacmanPosY;
  69. int pacman = 0;
  70. int ghostPosX; //= thisGhost.x;
  71. int ghostPosY; //= thisGhost.y;
  72. int xDiff;
  73. int yDiff;
  74.  
  75.  
  76. cout << "hello";
  77.  
  78. while(1){
  79. pacman = 0;
  80. GamePieceSequence *allPieces = engine->getAllGamePieces();
  81. int randomMove = rand() % 4;
  82.  
  83. sleep(1);
  84. for(i = 0; i < allPieces->maximum(); i++){
  85. cout << allPieces->maximum() <<"\n";
  86. if(allPieces[i].operator[](i).type == 0){
  87. pacmanPosX = allPieces[i].operator[](i).x;
  88. cout << pacmanPosX << endl;
  89. pacmanPosY = allPieces[i].operator[](i).y;
  90. cout << pacmanPosY << endl;
  91. pacman = 1;
  92. }
  93. if(allPieces[i].operator[](i).id == thisGhost.id){
  94. ghostPosX = allPieces[i].operator[](i).x;
  95. cout << ghostPosX << " second if" << endl;
  96. ghostPosY = allPieces[i].operator[](i).y;
  97. cout << pacmanPosY << endl;
  98. }
  99. }
  100. xDiff = pacmanPosX - ghostPosX;
  101.  
  102. yDiff = pacmanPosY - ghostPosY;
  103. //cout << "hello there\n";
  104.  
  105. //GHOST AI GOES HERE.
  106. if(pacman == 1){
  107. if(xDiff > 0){
  108. //cout << "moving 1" << endl;
  109. engine->moveGamePiece(thisGhost.id, 1 ,0);
  110. if(yDiff > 0){
  111. engine->moveGamePiece(thisGhost.id, 0 ,1);
  112. }
  113. if(yDiff < 0){
  114. engine->moveGamePiece(thisGhost.id, 0, -1);
  115. }
  116. }
  117. if(xDiff < 0)
  118. {
  119. //cout << "moving 2" << endl;
  120. engine->moveGamePiece(thisGhost.id, -1, 0);
  121. if(yDiff > 0){
  122. engine->moveGamePiece(thisGhost.id, 0 ,1);
  123. }
  124. if(yDiff < 0){
  125. engine->moveGamePiece(thisGhost.id, 0, -1);
  126. }
  127. }
  128. if (xDiff == 0 && yDiff != 0) {
  129. //cout << "moving 3" << endl;
  130. if (yDiff > 0) {
  131. engine->moveGamePiece(thisGhost.id, 0, 1);
  132. }
  133. if (yDiff < 0) {
  134. engine->moveGamePiece(thisGhost.id, 0, -1);
  135. }
  136. }
  137. if (yDiff == 0 && xDiff != 0) {
  138. //cout << "moving 4" << endl;
  139. if (xDiff > 0) {
  140. engine->moveGamePiece(thisGhost.id, 1, 0);
  141. }
  142. if (xDiff < 0) {
  143. engine->moveGamePiece(thisGhost.id, -1, 0);
  144. }
  145. }
  146.  
  147. }
  148. else {
  149. if(randomMove == 0)
  150.  
  151. engine->moveGamePiece(thisGhost.id, 1, 0);
  152. if(randomMove == 1)
  153. engine->moveGamePiece(thisGhost.id, 0, 1);
  154. if(randomMove == 2)
  155. engine->moveGamePiece(thisGhost.id, -1, 0);
  156. if(randomMove == 3)
  157. engine->moveGamePiece(thisGhost.id, 0, -1);
  158. }
  159. //v.~vector<GamePiece>();
  160.  
  161. }
  162.  
  163. return 0;
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement