Files
Ajedrez_Purgatorio/Assets/Game/Scripts/Mono/Combat/BoardManagerCombat.cs
T
jimmyabv b539aa403e fix: resolve compilation errors, add tests, fix configs, update docs
- Fix 9 CS0101 duplicate classes between Mono/ and Mono/Classic/
  - BoardManager -> ClassicBoardManager, SquareClick -> ClassicSquareClick
  - Delete duplicate Piece/Pawn/King/Queen/Rook/Bishop/Knight from Classic/
  - Merge GetAttackSquares into Piece base class with overrides
- Fix King castling: reject castling through/while in check
- Assign URP pipeline to QualitySettings (6 levels) and GraphicsSettings
- Fix template identifiers (DefaultCompany -> EarthGenesisGames)
- Delete orphaned SampleScene.unity and duplicate URP assets
- Fix test assembly reference (Assembly-CSharp -> AjedrezPurgatorio.Runtime)
- Remove 11 unused packages (multiplayer, visualscripting, terrain, etc.)
- Update BoardInputSystemSpike for ClassicSquareClick
- Write unit tests: CheckDetector, DrawDetector, MoveValidator
- Fix BalanceConfig JSON structure to match C# class fields
- Update stale documentation (~30 files)
  - architecture.md, ADR-0001, roadmap, gate-check, EPIC.md
  - PROJECT_STATUS.md, BLOQUEADORES_JUGABILIDAD.md
  - tech-debt-register.md
- Add Unity Editor setup guide (production/UNITY_EDITOR_SETUP.md)
2026-08-17 20:40:02 -03:00

126 lines
4.0 KiB
C#

// ✅ BoardManagerCombat.cs
using UnityEngine;
public class BoardManagerCombat : MonoBehaviour
{
[Header("Prefabs de Piezas")]
public GameObject whitePawnPrefab, whiteRookPrefab, whiteKnightPrefab, whiteBishopPrefab, whiteQueenPrefab, whiteKingPrefab;
public GameObject blackPawnPrefab, blackRookPrefab, blackKnightPrefab, blackBishopPrefab, blackQueenPrefab, blackKingPrefab;
[Header("Prefabs de Casillas")]
public GameObject brownPrefab, grayPrefab;
[Header("Indicadores de Movimiento")]
public GameObject moveIndicatorPrefab;
public GameObject[,] indicators = new GameObject[8, 8];
public Transform boardParent;
public float tileSize = 10.24f;
public GameObject[,] squares = new GameObject[8, 8];
public static BoardManagerCombat Instance;
void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
void Start()
{
GenerateBoard();
GenerateIndicators();
PlacePieces();
}
void GenerateBoard()
{
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
GameObject prefabToUse = (x + y) % 2 == 0 ? brownPrefab : grayPrefab;
Vector3 pos = new(x * tileSize, y * tileSize, 0f);
GameObject square = Instantiate(prefabToUse, pos, Quaternion.identity, boardParent);
square.name = $"Square_{x}_{y}";
squares[x, y] = square;
var click = square.AddComponent<SquareClickCombat>();
click.position = new Vector2Int(x, y);
}
}
}
void PlacePiece(GameObject prefab, int x, int y, bool isWhite)
{
if (!prefab) { Debug.LogError($"Prefab faltante en ({x},{y})"); return; }
Vector3 pos = new(x * tileSize, y * tileSize, -1f);
GameObject pieceObj = Instantiate(prefab, pos, Quaternion.identity);
PieceCombat piece = pieceObj.GetComponent<PieceCombat>();
if (!piece) { Debug.LogError($"El prefab {prefab.name} no tiene el script PieceCombat"); return; }
piece.currentPos = new Vector2Int(x, y);
piece.isWhite = isWhite;
GameManagerCombat.Instance.board[x, y] = piece;
}
void PlacePieces()
{
for (int x = 0; x < 8; x++)
{
PlacePiece(whitePawnPrefab, x, 1, true);
PlacePiece(blackPawnPrefab, x, 6, false);
}
PlacePiece(whiteRookPrefab, 0, 0, true);
PlacePiece(whiteKnightPrefab, 1, 0, true);
PlacePiece(whiteBishopPrefab, 2, 0, true);
PlacePiece(whiteQueenPrefab, 3, 0, true);
PlacePiece(whiteKingPrefab, 4, 0, true);
PlacePiece(whiteBishopPrefab, 5, 0, true);
PlacePiece(whiteKnightPrefab, 6, 0, true);
PlacePiece(whiteRookPrefab, 7, 0, true);
PlacePiece(blackRookPrefab, 0, 7, false);
PlacePiece(blackKnightPrefab, 1, 7, false);
PlacePiece(blackBishopPrefab, 2, 7, false);
PlacePiece(blackQueenPrefab, 3, 7, false);
PlacePiece(blackKingPrefab, 4, 7, false);
PlacePiece(blackBishopPrefab, 5, 7, false);
PlacePiece(blackKnightPrefab, 6, 7, false);
PlacePiece(blackRookPrefab, 7, 7, false);
}
public void ShowIndicator(Vector2Int pos)
{
if (IsInsideBoard(pos)) indicators[pos.x, pos.y].SetActive(true);
}
public void HideAllIndicators()
{
foreach (var indicator in indicators)
if (indicator != null) indicator.SetActive(false);
}
bool IsInsideBoard(Vector2Int pos)
{
return pos.x >= 0 && pos.x < 8 && pos.y >= 0 && pos.y < 8;
}
void GenerateIndicators()
{
for (int x = 0; x < 8; x++)
for (int y = 0; y < 8; y++)
{
Vector3 pos = new(x * tileSize, y * tileSize, -0.5f);
GameObject indicator = Instantiate(moveIndicatorPrefab, pos, Quaternion.identity, boardParent);
indicator.SetActive(false);
indicators[x, y] = indicator;
}
}
}