Skip to content

Commit 56a52b4

Browse files
committed
Initiated a new sample
1 parent 155a70d commit 56a52b4

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[workspace]
2-
members = ["Lesson_00", "Lesson_01", "Lesson_02", "Lesson_03", "Lesson_04", "Lesson_05", "Lesson_06", "Lesson_07", "Lesson_08", "Lesson_09", "Lesson_10", "Lesson_11", "Lesson_12", "collector", "drone-lab", "fops", "mocking", "router", "sysco", "sysco2"]
2+
members = ["Lesson_00", "Lesson_01", "Lesson_02", "Lesson_03", "Lesson_04", "Lesson_05", "Lesson_06", "Lesson_07", "Lesson_08", "Lesson_09", "Lesson_10", "Lesson_11", "Lesson_12", "collector", "drone-lab", "fops", "game-engine", "mocking", "router", "sysco", "sysco2"]
33

44
resolver = "2"

game-engine/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "game-engine"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]

game-engine/src/main.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
fn main() {
2+
let mut game = Game::new();
3+
let super_mario = Player::new(1, "Super Mario".to_string());
4+
let mushroom = Mushroom::new(2, 10);
5+
game.add_actor(Box::new(super_mario));
6+
game.add_actor(Box::new(mushroom));
7+
}
8+
9+
struct Player {
10+
id: u32,
11+
name: String,
12+
}
13+
impl Player {
14+
pub fn new(id: u32, name: String) -> Self {
15+
Player { id, name }
16+
}
17+
}
18+
19+
impl Actor for Player {
20+
fn draw(&self) {
21+
println!("Player draw");
22+
}
23+
fn update(&mut self) {
24+
println!("Update location of player");
25+
}
26+
}
27+
28+
struct Mushroom {
29+
id: u32,
30+
strength: u8,
31+
}
32+
33+
impl Mushroom {
34+
pub fn new(id: u32, strength: u8) -> Self {
35+
Mushroom { id, strength }
36+
}
37+
}
38+
39+
impl Actor for Mushroom {
40+
fn draw(&self) {
41+
println!("Mushroom drawing");
42+
}
43+
fn update(&mut self) {
44+
println!("Calculation strength");
45+
}
46+
}
47+
48+
trait Actor {
49+
fn draw(&self);
50+
fn update(&mut self);
51+
}
52+
53+
struct Game {
54+
actors: Vec<Box<dyn Actor>>,
55+
}
56+
57+
impl Game {
58+
pub fn new() -> Self {
59+
Game { actors: Vec::new() }
60+
}
61+
pub fn add_actor(&mut self, actor: Box<dyn Actor>) {
62+
self.actors.push(actor);
63+
}
64+
}

0 commit comments

Comments
 (0)