int Pacman::update(char gameboard[][28]) { int new_x = getNextX(); int new_y = getNextY(); boolean move = true; switch(gameboard[new_y][new_x]) { case 'd': case 'u': case '0': break; case '9': wrap(); break; case 'a': case 'c': case 'f': case 's': //die(); // :( default: move = false; break; } if(move) { incrementX(); incrementY(); } return gameboard[int(y)][int(x)]; }
int enemy::Getinput(character *Player) { int PlayerX = Player->getNextX(); int PlayerY = Player->getNextY(); int EnemyX = getNextX(); int EnemyY = getNextY(); int DistX = PlayerX - EnemyX; int DistY = PlayerY - EnemyY; int Distance = int(sqrt(DistX*DistX + DistY*DistY)); // Distance between enemy and player if (TurnCount == LastTurn) { return rand() % 4 + 1;// If a move toward the player cannot be found, move randomly } // Check that the Character has moved } else { LastMove = -1; } if (Distance < 6 ) { if (DistX < 0 && LastMove !=3) // Left { LastMove = 3; LastTurn = TurnCount; return 3; } else if (DistX > 0 && LastMove != 4) // right { LastMove = 4; LastTurn = TurnCount; return 4; } else if (DistY < 0 && LastMove != 1) // Up { LastMove = 1; LastTurn = TurnCount; return 1; } else if (DistY > 0 && LastMove != 2) // Down { LastMove = 2; LastTurn = TurnCount; return 2; } } return rand() % 4 + 1; // If a move toward the player cannot be found, move randomly }