BAT Coding Challenge Snippet #3

PHOTO EMBED

Tue Sep 03 2024 20:18:41 GMT+0000 (Coordinated Universal Time)

Saved by @TechBox #c++

 
// Challenge Solution - Part #3 ------------------------------------------------------
// Create cheatingOpponent() Function
void cheatingOpponent(){
  // For each position on Player 1's grid, if it is green, that position has not been hit yet.
  // So target it with the next (cheating) hit.
  for (int k = 0; k < MATRIX_H * MATRIX_W; k++) {
    if (grid1S[k] == 4) { // If position is green, then ship is present
      target2[k] = 1; // Red Color == Hit
      grid1S[k] = 1;  // Red Color == Hit

      // Mark the attack as complete
      attackComplete = 1;
      break;
    }
  }

  // Delay briefly for smoother gameplay
  delay(500);
}
// End Challenge Solution ------------------------------------------------------------
 
  
content_copyCOPY