private void OnGUI() { var fullRect = new Rect(0, 0, position.width - LeftSideWidth, position.height); Handles.DrawSolidRectangleWithOutline(fullRect, Color.white, Color.black); var lines = new Vector3[_arenaData.Size.x * 2 + _arenaData.Size.y * 2]; for (int i = 0; i < _arenaData.Size.x; i++) { lines[i * 2] = new Vector3(CellSize * i, 0, 0); lines[i * 2 + 1] = new Vector3(CellSize * i, fullRect.yMax, 0); } var offset = _arenaData.Size.x * 2; for (int i = 0; i < _arenaData.Size.y; i++) { lines[offset + i * 2] = new Vector3(0, CellSize * i, 0); lines[offset + i * 2 + 1] = new Vector3(fullRect.xMax, CellSize * i, 0); } Handles.color = Color.black; Handles.DrawLines(lines); for (int i = 0; i < _arenaData.Cells.Length; i++) { var index = TransformCellIndex(new Vector2Int(i % _arenaData.Size.x, i / _arenaData.Size.x)); var cell = _arenaData.Cells[i]; Color?color = null; switch (cell.Type) { case ArenaCellType.PlayerSpawn: color = Color.green; break; case ArenaCellType.Obstacle: color = Color.gray; break; case ArenaCellType.EnemySpawn: color = Color.red; break; } if (color != null) { Handles.color = color.Value; Handles.DrawSolidRectangleWithOutline( new Rect(index.x * CellSize, index.y * CellSize, CellSize, CellSize), color.Value, Color.black); } if (_currentCell != null) { GUILayout.BeginArea(new Rect(fullRect.xMax, 0, LeftSideWidth, fullRect.height)); DrawCellInfo(); GUILayout.EndArea(); } var evt = Event.current; if (evt.type == EventType.MouseUp && evt.button == 0) { var pos = evt.mousePosition; if (!fullRect.Contains(pos)) { return; } var cellIndex = TransformCellIndex(new Vector2Int((int)(pos.x / CellSize), (int)(pos.y / CellSize))); var newCell = _arenaData.Cells[cellIndex.x + cellIndex.y * _arenaData.Size.x]; if (evt.control) { newCell.Type = _currentCell.Type; } _currentCell = newCell; evt.Use(); } } }
public static void DrawArena(Gladiator spartacus, Gladiator opponent) { ArenaCell[,] arenaCells = new ArenaCell[size, size]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { char cGladiatorA = ' '; char cGladiatorB = ' '; char cGladiatorC = ' '; char cGladiatorD = ' '; if (spartacus.Position.X == x && spartacus.Position.Y == y) { switch (spartacus.Position.Facing) { case Direction.North: cGladiatorA = '|'; cGladiatorB = ' '; cGladiatorC = 'Ø'; cGladiatorD = ' '; break; case Direction.East: cGladiatorA = ' '; cGladiatorB = ' '; cGladiatorC = 'Ø'; cGladiatorD = '-'; break; case Direction.South: cGladiatorA = 'Ø'; cGladiatorB = ' '; cGladiatorC = '|'; cGladiatorD = ' '; break; case Direction.West: cGladiatorA = '-'; cGladiatorB = 'Ø'; cGladiatorC = ' '; cGladiatorD = ' '; break; case Direction.NorthEast: cGladiatorA = ' '; cGladiatorB = '/'; cGladiatorC = 'Ø'; cGladiatorD = ' '; break; case Direction.SouthEast: cGladiatorA = 'Ø'; cGladiatorB = ' '; cGladiatorC = ' '; cGladiatorD = '\\'; break; case Direction.SouthWest: cGladiatorA = ' '; cGladiatorB = 'Ø'; cGladiatorC = '/'; cGladiatorD = ' '; break; case Direction.NorthWest: cGladiatorA = '\\'; cGladiatorB = ' '; cGladiatorC = ' '; cGladiatorD = 'Ø'; break; } } if (opponent.Position.X == x && opponent.Position.Y == y) { switch (opponent.Position.Facing) { case Direction.North: cGladiatorA = '|'; cGladiatorB = ' '; cGladiatorC = 'O'; cGladiatorD = ' '; break; case Direction.East: cGladiatorA = ' '; cGladiatorB = ' '; cGladiatorC = 'O'; cGladiatorD = '-'; break; case Direction.South: cGladiatorA = 'O'; cGladiatorB = ' '; cGladiatorC = '|'; cGladiatorD = ' '; break; case Direction.West: cGladiatorA = '-'; cGladiatorB = 'O'; cGladiatorC = ' '; cGladiatorD = ' '; break; case Direction.NorthEast: cGladiatorA = '\\'; cGladiatorB = ' '; cGladiatorC = ' '; cGladiatorD = 'O'; break; case Direction.SouthEast: cGladiatorA = ' '; cGladiatorB = 'O'; cGladiatorC = '/'; cGladiatorD = ' '; break; case Direction.SouthWest: cGladiatorA = 'O'; cGladiatorB = ' '; cGladiatorC = ' '; cGladiatorD = '\\'; break; case Direction.NorthWest: cGladiatorA = ' '; cGladiatorB = '/'; cGladiatorC = 'O'; cGladiatorD = ' '; break; } } arenaCells[x, y] = CreateArenaCell(cGladiatorA, cGladiatorB, cGladiatorC, cGladiatorD); if (y == size - 1) { arenaCells[x, y].Bottom = "·····"; } if (x == size - 1) { arenaCells[x, y].Top = "......"; arenaCells[x, y].Middle1 = $": {cGladiatorA}{cGladiatorB} :"; arenaCells[x, y].Middle2 = $": {cGladiatorC}{cGladiatorD} :"; } if (y == size - 1 && x == size - 1) { arenaCells[x, y].Bottom = "······"; } } } StringBuilder ASCIIArena = new(); for (int y = 0; y < arenaCells.GetLength(1); y++) { ASCIIArena.Append(" "); for (int x = 0; x < arenaCells.GetLength(0); x++) { ASCIIArena.Append(arenaCells[x, y].Top); } ASCIIArena.Append("\n "); for (int x = 0; x < arenaCells.GetLength(0); x++) { ASCIIArena.Append(arenaCells[x, y].Middle1); } ASCIIArena.Append("\n "); for (int x = 0; x < arenaCells.GetLength(0); x++) { ASCIIArena.Append(arenaCells[x, y].Middle2); } ASCIIArena.Append("\n"); if (y == size - 1) { ASCIIArena.Append(" "); } for (int x = 0; x < arenaCells.GetLength(0); x++) { ASCIIArena.Append(arenaCells[x, y].Bottom); } } Console.Clear(); Console.WriteLine("KEY: W = North, A = West, S = South, D = East, F = Left, G = Right, Q = QUIT"); Console.WriteLine("\n\n\n"); Console.WriteLine(ASCIIArena); }