Crates.io | spelltest |
lib.rs | spelltest |
version | 0.2.0 |
source | src |
created_at | 2020-08-04 14:16:44.041967 |
updated_at | 2020-08-15 16:56:10.045791 |
description | SPELL TEST Mechanics |
homepage | |
repository | https://github.com/bidipeppercrap/spelltest.rs |
max_upload_size | |
id | 272906 |
size | 17,791 |
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();
}
See examples for more!
To run the official example, simply clone this repo and run it by using cargo run --example <folder-name>
(Replace <folder-name>
with the example folder name).
To run
basic
example in theexamples
folder, typecargo run --example basic