-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.rs
executable file
·77 lines (74 loc) · 2.7 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::rules::*;
use rules::BattlefieldSeed;
use weasel::creature::CreatureId;
use weasel::team::TeamId;
use weasel::{
AlterSpace, Battle, BattleController, CreateCreature, CreateTeam, EventTrigger, ResetSpace,
Server,
};
mod rules;
static TEAM_ID: TeamId<CustomRules> = 1;
static CREATURE_1: CreatureId<CustomRules> = 1;
static CREATURE_2: CreatureId<CustomRules> = 2;
static CREATURE_3: CreatureId<CustomRules> = 3;
fn main() {
// Create a server to manage the battle.
let battle = Battle::builder(CustomRules::new()).build();
let mut server = Server::builder(battle).build();
// Set the space model to be a 2D battlefield of squares.
ResetSpace::trigger(&mut server)
.seed(BattlefieldSeed::TwoDimensions)
.fire()
.unwrap();
// Display the space model.
println!("Battlefield:\n{}", server.battle().space().model());
// Spawn three creatures.
println!("Spawning three creatures...");
CreateTeam::trigger(&mut server, TEAM_ID).fire().unwrap();
// First creature goes in [1;0].
CreateCreature::trigger(&mut server, CREATURE_1, TEAM_ID, Square { x: 1, y: 0 })
.fire()
.unwrap();
// Second creature goes in [3;3].
CreateCreature::trigger(&mut server, CREATURE_2, TEAM_ID, Square { x: 3, y: 3 })
.fire()
.unwrap();
// Third creature goes in [4;3].
CreateCreature::trigger(&mut server, CREATURE_3, TEAM_ID, Square { x: 4, y: 3 })
.fire()
.unwrap();
println!();
// Display the space model and the creatures.
println!("Battlefield:\n{}", server.battle().space().model());
// Put traps on the squares across the diagonals.
println!("Placing traps on the diagonals!");
AlterSpace::trigger(
&mut server,
vec![
Square { x: 0, y: 0 },
Square { x: 1, y: 1 },
Square { x: 2, y: 2 },
Square { x: 3, y: 3 },
Square { x: 4, y: 4 },
Square { x: 0, y: 4 },
Square { x: 1, y: 3 },
Square { x: 3, y: 1 },
Square { x: 4, y: 0 },
],
)
.fire()
.unwrap();
assert_eq!(server.battle().entities().entities().count(), 2);
println!();
// Display the space model and the creatures. Some of them died!
println!("Battlefield:\n{}", server.battle().space().model());
// Now completely reset the space model, dropping one dimension.
println!("Removing the y-axis!");
ResetSpace::trigger(&mut server)
.seed(BattlefieldSeed::OneDimension)
.fire()
.unwrap();
println!();
// Display the space model and the creatures. Their positions have been adapted!
println!("Battlefield:\n{}", server.battle().space().model());
}