// 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 ------------------------------------------------------------
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter