<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AyahZahra</title>
    <description>The latest articles on DEV Community by AyahZahra (@ayahzahra).</description>
    <link>https://dev.to/ayahzahra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4174751%2F141c0056-aaab-4125-ae39-2c007533a039.png</url>
      <title>DEV Community: AyahZahra</title>
      <link>https://dev.to/ayahzahra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayahzahra"/>
    <language>en</language>
    <item>
      <title>What I Learned from Reading an 839-Line Pascal Game Built Without a Game Engine</title>
      <dc:creator>AyahZahra</dc:creator>
      <pubDate>Sat, 10 Oct 2026 06:57:46 +0000</pubDate>
      <link>https://dev.to/ayahzahra/what-i-learned-from-reading-an-839-line-pascal-game-built-without-a-game-engine-6kh</link>
      <guid>https://dev.to/ayahzahra/what-i-learned-from-reading-an-839-line-pascal-game-built-without-a-game-engine-6kh</guid>
      <description>&lt;p&gt;Whenever someone mentions writing a game from scratch, I often see recommendations to use a game engine. But for a small 2D grid game, skipping the engine can be the better choice.&lt;/p&gt;

&lt;p&gt;Not because game engines are bad, but because they can introduce solutions to problems you don't have while hiding decisions you might want to make yourself.&lt;/p&gt;

&lt;p&gt;To explore this idea, I read &lt;a href="https://github.com/ayahzahra/moss-circuit" rel="noopener noreferrer"&gt;Moss Circuit&lt;/a&gt;, an 839-line Pascal game that renders directly through the Windows API's GDI.&lt;/p&gt;

&lt;p&gt;No game engine. No asset pipeline. No game-loop abstraction.&lt;/p&gt;

&lt;p&gt;Just &lt;code&gt;Windows&lt;/code&gt;, &lt;code&gt;Messages&lt;/code&gt;, &lt;code&gt;SysUtils&lt;/code&gt;, &lt;code&gt;Math&lt;/code&gt;, and &lt;code&gt;Types&lt;/code&gt; in the &lt;code&gt;uses&lt;/code&gt; clause.&lt;/p&gt;

&lt;p&gt;Here's what I learned from reading all 839 lines.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Why Write a Game This Way?
&lt;/h2&gt;

&lt;p&gt;The entire program lives in a single unit containing 41 procedures and functions.&lt;/p&gt;

&lt;p&gt;Some of them handle palette colors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight pascal"&gt;&lt;code&gt;&lt;span class="n"&gt;RGBColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ThemeColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PageColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PanelColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;BorderColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;TextColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;MutedColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;AccentColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SnakeColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FoodColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CanvasColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GridColor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Others handle drawing primitives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight pascal"&gt;&lt;code&gt;&lt;span class="n"&gt;DrawTextRect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FillRounded&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FillCircle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DrawPetal&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The remaining code handles game logic and Win32 integration.&lt;/p&gt;

&lt;p&gt;This organization is worth learning from, even if you never write Pascal. Separating color helpers, drawing primitives, game logic, and platform-specific code makes a small project easier to navigate without introducing a complicated architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Board Geometry Is Recomputed on Resize
&lt;/h2&gt;

&lt;p&gt;This is one of my favorite parts of the implementation.&lt;/p&gt;

&lt;p&gt;Whenever the window is resized, &lt;code&gt;CalculateBoard&lt;/code&gt; derives the board geometry from the client area's dimensions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight pascal"&gt;&lt;code&gt;&lt;span class="k"&gt;procedure&lt;/span&gt; &lt;span class="n"&gt;CalculateBoard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ClientWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ClientHeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Integer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt;
  &lt;span class="n"&gt;Padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Integer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;begin&lt;/span&gt;
  &lt;span class="n"&gt;Padding&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;48&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;BoardSize&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;Min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ClientWidth&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Padding&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ClientHeight&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="m"&gt;286&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;BoardSize&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;Max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;240&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;BoardSize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;BoardLeft&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ClientWidth&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="n"&gt;BoardSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;div&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;BoardTop&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;190&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;CellSize&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;BoardSize&lt;/span&gt; &lt;span class="k"&gt;div&lt;/span&gt; &lt;span class="n"&gt;BoardCells&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;BoardSize&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;CellSize&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;BoardCells&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;BoardLeft&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ClientWidth&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="n"&gt;BoardSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;div&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are four details here that are easy to miss.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;One constant defines the board dimensions.&lt;/strong&gt; &lt;code&gt;BoardCells = 24&lt;/code&gt; means the grid is always 24 × 24 cells.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integer division can leave unused pixels.&lt;/strong&gt; &lt;code&gt;CellSize := BoardSize div BoardCells&lt;/code&gt; truncates the result. The next assignment, &lt;code&gt;BoardSize := CellSize * BoardCells&lt;/code&gt;, snaps the board size to an exact multiple of the cell size.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The minimum size prevents the board from shrinking indefinitely.&lt;/strong&gt; &lt;code&gt;Max(240, ...)&lt;/code&gt; establishes a lower bound of 240 pixels.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The board is centered again after snapping.&lt;/strong&gt; Recalculating &lt;code&gt;BoardLeft&lt;/code&gt; ensures the final board remains centered rather than using the position calculated from the original dimensions.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That small sequence makes the board geometry predictable without needing a layout engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Difficulty Is Calculated from the Score
&lt;/h2&gt;

&lt;p&gt;Many Snake clones use a lookup table to define difficulty levels. Moss Circuit uses a formula instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight pascal"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;CurrentSpeed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;UINT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;begin&lt;/span&gt;
  &lt;span class="n"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;Max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MinimumSpeed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;StartSpeed&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Score&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;StartSpeed = 145&lt;/code&gt; and &lt;code&gt;MinimumSpeed = 66&lt;/code&gt;, the timer interval starts at 145 milliseconds and decreases by 3 milliseconds for every point, until it reaches the minimum.&lt;/p&gt;

&lt;p&gt;The interval reaches its 66 ms floor at a score of 27.&lt;/p&gt;

&lt;p&gt;Applying the calculated speed to the timer takes just one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight pascal"&gt;&lt;code&gt;&lt;span class="n"&gt;SetTimer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MainWindow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;TimerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;CurrentSpeed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;WM_TIMER&lt;/code&gt; message drives the game loop. There is no &lt;code&gt;while true&lt;/code&gt; loop anywhere.&lt;/p&gt;

&lt;p&gt;This is a good example of using the operating system's event mechanism instead of building a separate game-loop abstraction.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The Anti-Reverse Check Defines the Game Feel
&lt;/h2&gt;

&lt;p&gt;A surprisingly large part of making Snake feel right comes down to handling direction changes correctly.&lt;/p&gt;

&lt;p&gt;Here's the relevant procedure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight pascal"&gt;&lt;code&gt;&lt;span class="k"&gt;procedure&lt;/span&gt; &lt;span class="n"&gt;RequestDirection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NewX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;NewY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Integer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;begin&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;State&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gsReady&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="n"&gt;BeginGame&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;State&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;gsPlaying&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;TurnQueued&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="k"&gt;Exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NewX&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;DirectionX&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NewY&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;DirectionY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="k"&gt;Exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;NextDirectionX&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;NewX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;NextDirectionY&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;NewY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;TurnQueued&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;True&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things happen here.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reverse input is rejected.&lt;/strong&gt; If the snake is moving right, pressing left cannot immediately reverse its direction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only one turn is queued per tick.&lt;/strong&gt; Without &lt;code&gt;TurnQueued&lt;/code&gt;, a player could press right and then up within a few milliseconds, potentially causing an unintended turn before the next movement update.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The first direction input starts the game.&lt;/strong&gt; There's no need to press a separate start button.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The queue pattern is useful beyond Snake. Any grid-based game that updates movement in discrete ticks can encounter similar input-handling bugs.&lt;/p&gt;

&lt;p&gt;The important idea is to separate the direction requested by the player from the direction currently being applied by the game simulation.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Preferences Persist to &lt;code&gt;%APPDATA%&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Moss Circuit stores its settings in a directory under the user's application data folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight pascal"&gt;&lt;code&gt;&lt;span class="n"&gt;DataDirectory&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;GetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'APPDATA'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;DataDirectory&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;''&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="n"&gt;DataDirectory&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ExtractFilePath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ParamStr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="n"&gt;DataDirectory&lt;/span&gt; &lt;span class="p"&gt;:=&lt;/span&gt;
  &lt;span class="n"&gt;IncludeTrailingPathDelimiter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DataDirectory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="s"&gt;'MossCircuit'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;ForceDirectories&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DataDirectory&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The theme preference and high score are stored under &lt;code&gt;%APPDATA%\MossCircuit\&lt;/code&gt; on a typical Windows installation.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;APPDATA&lt;/code&gt; is unavailable, the program falls back to the executable's directory.&lt;/p&gt;

&lt;p&gt;The file-writing code also handles I/O errors without immediately terminating the game:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight pascal"&gt;&lt;code&gt;&lt;span class="k"&gt;procedure&lt;/span&gt; &lt;span class="n"&gt;SaveSetting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;string&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;begin&lt;/span&gt;
  &lt;span class="n"&gt;AssignFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FileHandle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DataFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="cm"&gt;{$I-}&lt;/span&gt;
  &lt;span class="n"&gt;Rewrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FileHandle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;IOResult&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="k"&gt;begin&lt;/span&gt;
    &lt;span class="k"&gt;WriteLn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FileHandle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;CloseFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FileHandle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="cm"&gt;{$I+}&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;{$I-}&lt;/code&gt; directive disables automatic I/O error checking, allowing the program to inspect the result through &lt;code&gt;IOResult&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If opening the file fails, the game avoids a crash caused by that operation. The trade-off is that the setting may not be saved.&lt;/p&gt;

&lt;p&gt;There is one important nuance: this fallback does not make the game fully cross-platform. The code still depends on Windows-specific APIs, and the executable directory may not be writable.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. A Simple but Effective Theming System
&lt;/h2&gt;

&lt;p&gt;The game supports two color themes, and palette values are routed through &lt;code&gt;ThemeColor&lt;/code&gt; rather than being hardcoded throughout the drawing code.&lt;/p&gt;

&lt;p&gt;Changing the theme flag updates the colors used by the palette helpers.&lt;/p&gt;

&lt;p&gt;This is a lightweight theming system: one flag and a set of color functions.&lt;/p&gt;

&lt;p&gt;There's no need for a CSS-like system, separate theme files, or a complex inheritance hierarchy for a game this small.&lt;/p&gt;

&lt;p&gt;The broader lesson is that architecture should match the scale of the project. A small game can benefit from clear separation of concerns without needing a full framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. What the Game Doesn't Have
&lt;/h2&gt;

&lt;p&gt;Moss Circuit has no audio, particle effects, save slots, multiplayer, or level editor.&lt;/p&gt;

&lt;p&gt;For an 839-line game, those omissions make sense. Every additional feature adds implementation and maintenance costs.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;gsComplete&lt;/code&gt; state and &lt;code&gt;CompleteGarden&lt;/code&gt; procedure also suggest that the game has a defined completion state, with a flower that grows as the board fills.&lt;/p&gt;

&lt;p&gt;Rather than adding features just because other games have them, the implementation focuses on the core experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who Should Read This Code?
&lt;/h2&gt;

&lt;p&gt;If you want to understand what a complete small game can look like without the overhead of a game engine, Moss Circuit is worth exploring.&lt;/p&gt;

&lt;p&gt;The WinAPI-specific parts have a learning curve, but the game logic is relatively straightforward. If you're already familiar with GDI, you'll recognize many of the patterns quickly.&lt;/p&gt;

&lt;p&gt;Even if you normally use a game engine, reading a project like this can help you understand what the engine is doing behind the scenes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Source code:&lt;/strong&gt; &lt;a href="https://github.com/ayahzahra/moss-circuit" rel="noopener noreferrer"&gt;Moss Circuit on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the Indonesian version, including the code map and screenshots, see my blog:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://brandmu.my.id/posts/moss-circuit-mini-game-pascal/" rel="noopener noreferrer"&gt;Read the full article on brandmu.my.id&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>opensource</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
