Skip to content

Conversation

Copy link

Copilot AI commented Oct 30, 2025

The codebase contained repetitive if-statement patterns for handling directional inputs (left/right/up/down) across key handlers and movement logic.

Changes

Form1.cs

  • Extracted HandleDirectionalKeyPress() - consolidates 4 if-statements into switch
  • Extracted HandleDirectionalKeyRelease() - consolidates 4 if-statements into switch
  • Extracted MoveZombieTowardPlayer() - encapsulates zombie AI movement

bullet.cs

  • Extracted MoveBullet() - consolidates 4 if-statements into switch

Before

if (e.KeyCode == Keys.Left) {
    goLeft = true;
    facing = "left";
    player.Image = Properties.Resources.left;
}
if (e.KeyCode == Keys.Right) {
    goRight = true;
    facing = "right";
    player.Image = Properties.Resources.right;
}
// ... repeated for Up and Down

After

HandleDirectionalKeyPress(e.KeyCode);

private void HandleDirectionalKeyPress(Keys key) {
    switch (key) {
        case Keys.Left:
            goLeft = true;
            facing = "left";
            player.Image = Properties.Resources.left;
            break;
        // ... other cases
    }
}

Reduces duplication by ~100 lines with no behavioral changes.

Original prompt

Find and refactor duplicated code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Refactor duplicated code for better maintainability Refactor duplicated directional logic into helper methods Oct 30, 2025
Copilot AI requested a review from abelberhane October 30, 2025 15:07
Copilot finished work on behalf of abelberhane October 30, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants