+
Skip to content

andrewtc/posturn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Docs Status REUSE status

🏰 posturn 🎮

Build turn-based games with async Rust

This crate offers a simple way to model turn-based games. Instead of writing a monolithic state machine, why not a Coroutine instead?

posturn allows you to write your turn-based game logic as an async function that emits events back to calling code. When an event is emitted, the game enters a wait-for-input state using await, pausing and returning control to the UI layer. The UI can handle the event and re-render itself however it wishes. When ready to continue, the UI resumes the game. This calls back into the coroutine, providing all player input necessary to take the next turn.

This approach has the advantage of maintaining a clean separation between turn-based game logic and the UI layer. A game written in this manner can be used with any frontend capable of processing events emitted by the game. This makes it possible to write, for instance, two game clients in entirely different game engines with no changes to the underlying game logic.

For a very simple example, see RoShamBo in the tests module.

For a complete game built with posturn, see examples/tui.

📃 Usage

To use posturn, simply add this to your Cargo.toml:

[dependencies]
posturn = "0.3.0"

Alternatively, run the following from your crate root:

cargo add posturn@0.3.0

⚠️ Compatibility

This crate currently depends on genawaiter to provide a stable implementation of Rust coroutines. Once the Coroutine trait has been stabilized (RFC 2033), future versions of posturn may move in the direction of using the std implementation, gated by a feature flag.

For now, the dependency on genawaiter is required. If you need std support for a nightly project, please see this issue or open a PR on GitHub.

⚖️ License

All Rust code is licensed under the MIT license.

Various other files (e.g. this README) are licensed under one of the following:

posturn aims to be REUSE compliant. The SPDX-License-Identifier at the top of each file shows which license is associated with it.

About

Build turn-based games with `async` Rust

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载