4个版本
| 0.2.0 | 2020年8月15日 | 
|---|---|
| 0.1.3 | 2020年8月4日 | 
| 0.1.2 | 2020年8月4日 | 
| 0.1.0 | 2020年8月4日 | 
#5 in #mechanics
7KB
58 行
用Rust编写的SPELL TEST机制!
快速示例
use spelltest::*;
fn main() {
    // --- Create a player character ---
    // Creature::new(name, health, energy, damage, defense)
    // Set mutable variable because we expect a change to health and energy
    let mut player = Creature::new("Pel Nervil", 100, 20, 5, 0);
    // --- Create a dummy enemy ---
    let mut dummy_enemy = Creature::new("Player killer", 200, 50, 10, 5);
    // Let's print their attributes
    player.print();
    dummy_enemy.print();
    // Let's do a turn-based combat
    // First, the player attack the enemy
    player.attack(&mut dummy_enemy); // Borrow and use as mutable to apply a change to enemy health
    // Let's print enemy attributes again, we expect the enemy health is reduced by the attack from the player
    dummy_enemy.print();
    // It's the enemy turn to attack
    dummy_enemy.attack(&mut player); // Like before, borrow and use as mutable
    // Expecting reduced player health
    player.print();
}
查看更多示例:示例
要运行官方示例,只需克隆此仓库,然后使用cargo run --example <folder-name>运行它(将<folder-name>替换为示例文件夹名称)。
要在
examples文件夹中运行basic示例,请输入cargo run --example basic