File tree 3 files changed +38
-2
lines changed
3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,8 @@ Rust dilinde **isimlendirme standartları _(Naming Conventions)_** da kod okunur
68
68
- sysco; Basit bir terminal aracı. Lesson_01 dersinde kullanılan örneğin farklı bir sürümü.
69
69
- sysco2; sysco programının daha iyileştirilmiş bir sürümü.
70
70
- collector; sysinfo küfesini kullanarak cpu, memory metrikleri toplayan uygulama.
71
+ - mocking; Birim testlerde mock nesne kullanımının ele alındığı örnek.
71
72
- drone-lab; Konu tekrarı, birim testler, lifetimes kullanımları.
72
73
- fops; Temel I/O işlemleri.
73
74
- router; trait kullanımını örneklemek için eklenmiş olan uygulama.
75
+ - game-engine; trait, thread ve channel kullanımlarının ele alındığı örnektir.
Original file line number Diff line number Diff line change
1
+ pub trait Bot {
2
+ fn apply ( & self ) {
3
+ println ! ( "Default AI movements" ) ;
4
+ }
5
+ }
6
+
1
7
#[ allow( dead_code) ]
2
8
pub trait Actor {
3
9
fn draw ( & self ) ;
4
10
fn update ( & mut self ) ;
5
11
}
6
12
7
13
#[ derive( Default ) ]
14
+ #[ allow( dead_code) ]
8
15
pub struct Game {
9
16
// width: f32,
10
17
// height: f32,
11
18
size : Size ,
12
19
actors : Vec < Box < dyn Actor > > ,
20
+ bots : Vec < Box < dyn Bot > > ,
13
21
}
14
22
15
23
impl Game {
@@ -27,10 +35,16 @@ impl Game {
27
35
actor. draw ( ) ;
28
36
}
29
37
}
38
+ pub fn add_bot ( & mut self , bot : Box < dyn Bot > ) {
39
+ self . bots . push ( bot) ;
40
+ }
30
41
pub fn update ( & mut self ) {
31
- for actor in & mut self . actors {
42
+ for actor in & mut self . actors {
32
43
actor. update ( ) ;
33
44
}
45
+ for bot in & self . bots {
46
+ bot. apply ( ) ;
47
+ }
34
48
}
35
49
}
36
50
Original file line number Diff line number Diff line change 1
- use std:: { thread:: sleep, time:: Duration } ;
1
+ use std:: {
2
+ thread:: { self , sleep} ,
3
+ time:: Duration ,
4
+ } ;
2
5
3
6
use framework:: * ;
4
7
@@ -11,6 +14,8 @@ fn main() {
11
14
let mushroom = Mushroom :: new ( 2 , 10 ) ;
12
15
game. add_actor ( Box :: new ( super_mario) ) ;
13
16
game. add_actor ( Box :: new ( mushroom) ) ;
17
+ let mega_mind = MindController :: default ( ) ;
18
+ game. add_bot ( Box :: new ( mega_mind) ) ;
14
19
15
20
loop {
16
21
sleep ( Duration :: from_secs ( 2 ) ) ;
@@ -20,6 +25,21 @@ fn main() {
20
25
}
21
26
}
22
27
28
+ #[ derive( Default ) ]
29
+ pub struct MindController { }
30
+
31
+ impl Bot for MindController {
32
+ fn apply ( & self ) {
33
+ //todo@buraksenyurt Buradaki thread'in bir kere açılmasını garanti et
34
+ thread:: spawn ( || {
35
+ loop {
36
+ println ! ( "Applying simulation..." ) ;
37
+ sleep ( Duration :: from_secs ( 5 ) ) ;
38
+ }
39
+ } ) ;
40
+ }
41
+ }
42
+
23
43
#[ allow( dead_code) ]
24
44
struct Player {
25
45
id : u32 ,
You can’t perform that action at this time.
0 commit comments