Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File client.cc
- #include <vector>
- #include <iostream>
- #include <fstream>
- #include <unistd.h> // for sleep
- #include "GameEngineInterface.h"
- using namespace std;
- int
- main (int argc, char *argv[])
- {
- // Initialize the ORB
- CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
- // Connect to the Account
- ifstream f ("account.ior");
- string ior;
- f >> ior;
- CORBA::Object_var obj =
- orb->string_to_object (ior.c_str());
- GameEngineInterface_var engine = GameEngineInterface::_narrow (obj);
- GamePiece thisGhost = engine->createNewGamePiece(1);
- /*
- while(1){
- sleep(1);
- cout << "hello there\n";
- //GHOST AI GOES HERE.
- engine->moveGamePiece(thisGhost.id, 2, 0);
- }
- return 0;
- }
- */
- int i = 0;
- int pacmanPosX, pacmanPosY;
- int pacman = 0;
- int ghostPosX; //= thisGhost.x;
- int ghostPosY; //= thisGhost.y;
- int xDiff;
- int yDiff;
- cout << "hello";
- while(1){
- pacman = 0;
- GamePieceSequence *allPieces = engine->getAllGamePieces();
- int randomMove = rand() % 4;
- sleep(1);
- for(i = 0; i < allPieces->maximum(); i++){
- cout << allPieces->maximum() <<"\n";
- if(allPieces[i].operator[](i).type == 0){
- pacmanPosX = allPieces[i].operator[](i).x;
- cout << pacmanPosX << endl;
- pacmanPosY = allPieces[i].operator[](i).y;
- cout << pacmanPosY << endl;
- pacman = 1;
- }
- if(allPieces[i].operator[](i).id == thisGhost.id){
- ghostPosX = allPieces[i].operator[](i).x;
- cout << ghostPosX << " second if" << endl;
- ghostPosY = allPieces[i].operator[](i).y;
- cout << pacmanPosY << endl;
- }
- }
- xDiff = pacmanPosX - ghostPosX;
- yDiff = pacmanPosY - ghostPosY;
- //cout << "hello there\n";
- //GHOST AI GOES HERE.
- if(pacman == 1){
- if(xDiff > 0){
- //cout << "moving 1" << endl;
- engine->moveGamePiece(thisGhost.id, 1 ,0);
- if(yDiff > 0){
- engine->moveGamePiece(thisGhost.id, 0 ,1);
- }
- if(yDiff < 0){
- engine->moveGamePiece(thisGhost.id, 0, -1);
- }
- }
- if(xDiff < 0)
- {
- //cout << "moving 2" << endl;
- engine->moveGamePiece(thisGhost.id, -1, 0);
- if(yDiff > 0){
- engine->moveGamePiece(thisGhost.id, 0 ,1);
- }
- if(yDiff < 0){
- engine->moveGamePiece(thisGhost.id, 0, -1);
- }
- }
- if (xDiff == 0 && yDiff != 0) {
- //cout << "moving 3" << endl;
- if (yDiff > 0) {
- engine->moveGamePiece(thisGhost.id, 0, 1);
- }
- if (yDiff < 0) {
- engine->moveGamePiece(thisGhost.id, 0, -1);
- }
- }
- if (yDiff == 0 && xDiff != 0) {
- //cout << "moving 4" << endl;
- if (xDiff > 0) {
- engine->moveGamePiece(thisGhost.id, 1, 0);
- }
- if (xDiff < 0) {
- engine->moveGamePiece(thisGhost.id, -1, 0);
- }
- }
- }
- else {
- if(randomMove == 0)
- engine->moveGamePiece(thisGhost.id, 1, 0);
- if(randomMove == 1)
- engine->moveGamePiece(thisGhost.id, 0, 1);
- if(randomMove == 2)
- engine->moveGamePiece(thisGhost.id, -1, 0);
- if(randomMove == 3)
- engine->moveGamePiece(thisGhost.id, 0, -1);
- }
- //v.~vector<GamePiece>();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement