# Build games and desktop programs

> Start a MonoGame project and explore Alice game samples and their testable logic.

Canonical: https://alice-lang.org/documentation/guides/games/

[Documentation index](https://alice-lang.org/documentation/llms.txt) · [Complete book](https://alice-lang.org/llms-full.txt)

## Create a game

```sh
alice new rabbit-game --game
cd rabbit-game
alice build
alice run
```

The game template sets the package kind to `game` and adds `MonoGame.Framework.DesktopGL` (`3.8.*`). A desktop graphics environment and appropriate platform graphics/audio libraries are required to run it. Package restore and compilation can work in environments that cannot open a window.

## Use the .NET game lifecycle

Alice can inherit MonoGame's `Game` type and override its virtual lifecycle methods. Use typed fields/properties for game state, load assets at the appropriate lifecycle stage, update logic with elapsed time, and render through the framework's graphics APIs.

.NET member names keep their case. Alice's inheritance and `super` forms call the framework's ordinary CLR members. Consult the framework's API contracts for disposal and graphics-thread restrictions.

## Explore complete samples

| Sample                                                                            | What to study                                         |
| --------------------------------------------------------------------------------- | ----------------------------------------------------- |
| [BounceGame](https://github.com/alicelanguage/alice/tree/main/samples/BounceGame) | A small MonoGame starting point                       |
| [Breakout](https://github.com/alicelanguage/alice/tree/main/samples/Breakout)     | Paddle/ball game, rendering, and headless logic tests |
| [Celeste](https://github.com/alicelanguage/alice/tree/main/samples/celeste)       | A larger Alice-only platformer sample using Raylib    |
| [Wonderland](https://github.com/alicelanguage/alice/tree/main/samples/wonderland) | A text adventure and Ruby-style DSL                   |

From the compiler checkout, build the sample workspace with `alice build samples` and run a member with `alice run samples Breakout`. Check each sample's README for its exact working directory, assets, and runtime requirements.

## Separate simulation from presentation

Keep movement, collision rules, scoring, and state transitions callable without a graphics window. Those methods can run in `alice test`. Initialize graphics devices, play audio, and create windows in the application lifecycle rather than in shared rule code.

Headless tests prove logic. A visible run is still needed to judge rendering, input, audio, and frame pacing.

## Asset paths and distribution

A program's working directory is not necessarily its source directory after publishing. Use a clear content root and portable path construction. Include required game content and licenses in the distribution. Native graphics or audio dependencies do not become browser-compatible merely because the game code is Alice.

For build modes and executable distribution, read [publishing](https://alice-lang.org/documentation/guides/publishing.md).

## Continue reading

- Previous: [Build a web API](https://alice-lang.org/documentation/guides/web.md)
- Next: [Test Alice programs](https://alice-lang.org/documentation/guides/testing.md)
