mirror of
https://github.com/Earth-Genesis-Games/Ajedrez_Purgatorio.git
synced 2026-09-11 09:47:35 +00:00
- 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)
158 lines
4.7 KiB
C#
158 lines
4.7 KiB
C#
using UnityEngine;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
public class ClassicBoardManager : MonoBehaviour
|
|
{
|
|
[Header("Prefabs de Piezas")]
|
|
public GameObject whitePawnPrefab;
|
|
public GameObject whiteRookPrefab;
|
|
public GameObject whiteKnightPrefab;
|
|
public GameObject whiteBishopPrefab;
|
|
public GameObject whiteQueenPrefab;
|
|
public GameObject whiteKingPrefab;
|
|
|
|
public GameObject blackPawnPrefab;
|
|
public GameObject blackRookPrefab;
|
|
public GameObject blackKnightPrefab;
|
|
public GameObject blackBishopPrefab;
|
|
public GameObject blackQueenPrefab;
|
|
public GameObject blackKingPrefab;
|
|
|
|
[Header("Prefabs de Casillas")]
|
|
public GameObject brownPrefab;
|
|
public GameObject 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 ClassicBoardManager 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++)
|
|
{
|
|
bool isBrown = (x + y) % 2 == 0;
|
|
GameObject prefabToUse = isBrown ? brownPrefab : grayPrefab;
|
|
Vector3 position = new Vector3(x * tileSize, y * tileSize, 0f);
|
|
GameObject square = Instantiate(prefabToUse, position, Quaternion.identity, boardParent);
|
|
square.name = $"Square_{x}_{y}";
|
|
squares[x, y] = square;
|
|
|
|
var squareClick = square.AddComponent<ClassicSquareClick>();
|
|
squareClick.position = new Vector2Int(x, y);
|
|
}
|
|
}
|
|
}
|
|
|
|
void PlacePiece(GameObject prefab, int x, int y, bool isWhite)
|
|
{
|
|
if (prefab == null)
|
|
{
|
|
string message = $"ClassicBoardManager: falta asignar el prefab en ({x}, {y}).";
|
|
Debug.LogError(message);
|
|
#if UNITY_EDITOR
|
|
EditorApplication.isPlaying = false;
|
|
#endif
|
|
throw new System.InvalidOperationException(message);
|
|
}
|
|
|
|
Vector3 position = new Vector3(x * tileSize, y * tileSize, -1f);
|
|
GameObject pieceObj = Instantiate(prefab, position, Quaternion.identity);
|
|
|
|
Piece piece = pieceObj.GetComponent<Piece>();
|
|
if (piece == null)
|
|
{
|
|
Debug.LogError($"El prefab '{prefab.name}' no tiene el script 'Piece'");
|
|
return;
|
|
}
|
|
|
|
piece.currentPos = new Vector2Int(x, y);
|
|
piece.isWhite = isWhite;
|
|
|
|
GameManagerClassic.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);
|
|
}
|
|
}
|
|
|
|
private bool IsInsideBoard(Vector2Int pos)
|
|
{
|
|
return pos.x >= 0 && pos.x < 8 && pos.y >= 0 && pos.y < 8;
|
|
}
|
|
|
|
public void GenerateIndicators()
|
|
{
|
|
for (int x = 0; x < 8; x++)
|
|
{
|
|
for (int y = 0; y < 8; y++)
|
|
{
|
|
Vector3 position = new Vector3(x * tileSize, y * tileSize, -0.5f);
|
|
GameObject indicator = Instantiate(moveIndicatorPrefab, position, Quaternion.identity, boardParent);
|
|
indicator.SetActive(false);
|
|
indicators[x, y] = indicator;
|
|
}
|
|
}
|
|
}
|
|
}
|