Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logic and types separation #4

Merged
merged 2 commits into from
Nov 30, 2024
Merged

logic and types separation #4

merged 2 commits into from
Nov 30, 2024

Conversation

IceCandle
Copy link
Owner

@IceCandle IceCandle commented Nov 30, 2024

The current codebase mixes game logic with React component code in GameContext.tsx. Additionally, type definitions are scattered across files, making it difficult to maintain consistent types across the application.

Solution
Move game logic to a dedicated folder
Create a centralized types file
Implement proper separation between game logic and UI components

Changes Made
New File Structure.
Moved core game functions from GameContext.tsx to game/board.ts:

  • createEmptyBoard
  • addRandomTile
  • moveBoard
  • isGameOver

Centralized Type Definitions:
Created types.ts with shared interfaces
Enhanced Type Safety:
Added type guards and runtime checks isValidRow

Benefit
Game logic can now be tested independently of React components

Copy link

vercel bot commented Nov 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
2024-clone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 30, 2024 1:36pm

@IceCandle IceCandle merged commit 07e85b2 into main Nov 30, 2024
3 checks passed
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.

1 participant