Skip to content

[BE-1] Implement TryHit Handler with Hit Detection Logic #24

Description

@sarkarshuvojit

Parent Epic

#22

Description

Implement the TryHit WebSocket handler that allows players to attempt hitting cells on opponent boards.

Requirements

  • Handler receives: targetSessionID, x, y coordinates
  • Validate it's the player's turn
  • Validate target is a valid opponent
  • Validate coordinates are within bounds (0-9)
  • Validate cell hasn't been hit before
  • Detect hit or miss based on opponent's ship positions
  • Update opponent's board state (HIT or MISS)
  • Broadcast result to all players in room

Events

  • Inbound: TRY_HIT (already defined)
  • Outbound: HIT_ATTEMPTED / BOARD_UPDATED

Files to Modify

  • internal/api/handlers/ - New handler
  • internal/api/events/ - Payload types if needed
  • internal/game/ - Hit detection logic

Unit Tests

  • Hit detection on ship cell returns HIT
  • Hit detection on empty cell returns MISS
  • Already hit cell is rejected
  • Out of bounds coordinates rejected

Acceptance Criteria

  • TryHit handler implemented
  • Hit/Miss detection working
  • Board state updated correctly
  • Unit tests passing

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend related issues

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions