# 13895 - Football Game ###### tags: `class` --- ## Brief See the code below ## Solution 0 ```cpp= #include <iostream> #include "function.h" // [TODO] Implement this function // Test if any player is at this position. bool Field::SomeoneIsHere(int x, int y) { for (int i = 0; i < p; i++) { if (player[i]->IsHere(x, y)) return true; } return false; } // [TODO] Implement this function // Find the player who is holding the ball now. int Field::GetWho() { for (int i = 0; i < p; i++) { if (player[i]->IsHoldingBall()) return i; } return -1; } // [TODO] Implement this function void Field::handleBallKicked(int dx, int dy) { int curr_x = ball->GetX(), curr_y = ball->GetY(); while(1) { curr_x += dx, curr_y += dy; if (SomeoneIsHere(curr_x, curr_y)) { ball->SetX(curr_x); ball->SetY(curr_y); break; } else if (curr_x < 0 || curr_x >= n || curr_y < 0 || curr_y >= m) { ball->SetX(curr_x - dx); ball->SetY(curr_y - dy); break; } } } // Utin ``` ## Reference