diff --git a/AGENTS.md b/AGENTS.md index 7c49a10..f712ead 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,6 +6,7 @@ - Use `docs/ai_stdlib_reference.md` for default runtime/module APIs and stdlib surface. - Treat `LYNG_AI_SPEC.md` and older docs as secondary if they conflict with the two files above. - Prefer the shortest clear loop: use `for` for straightforward iteration/ranges; use `while` only when loop state/condition is irregular or changes in ways `for` cannot express cleanly. +- In Lyng code, slice strings with range indexing (`text[a.. = [] @@ -324,6 +327,62 @@ fun render( frameLines } +fun fitLine(line: String, width: Int): String { + val maxLen = if (width > 0) width else 0 + if (maxLen <= 0) return "" + if (line.size >= maxLen) return line[.. = [] + lines.add("PAUSED") + lines.add("") + lines.add("Any key: continue game") + lines.add("Esc: exit game") + lines.add("") + lines.add("Move: A/D or arrows") + lines.add("Rotate: W or Up") + lines.add("Drop: S/Down, Space hard drop") + + var innerWidth = 0 + for (line in lines) { + if (line.size > innerWidth) innerWidth = line.size + } + innerWidth += 4 + val maxInner = max(12, contentWidth - 2) + if (innerWidth > maxInner) innerWidth = maxInner + if (innerWidth % 2 != 0) innerWidth-- + + val boxWidth = innerWidth + 2 + val boxHeight = lines.size + 2 + + val left = originCol + max(0, (contentWidth - boxWidth) / 2) + val top = originRow + max(0, (contentHeight - boxHeight) / 2) + + val topBorder = UNICODE_TOP_LEFT + repeatText(UNICODE_HORIZONTAL, innerWidth / 2) + UNICODE_TOP_RIGHT + val bottomBorder = UNICODE_BOTTOM_LEFT + repeatText(UNICODE_HORIZONTAL, innerWidth / 2) + UNICODE_BOTTOM_RIGHT + + Console.moveTo(top, left) + Console.write(topBorder) + + for (i in 0..