File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Expand file tree Collapse file tree 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
6868- sysco; Basit bir terminal aracı. Lesson_01 dersinde kullanılan örneğin farklı bir sürümü.
6969- sysco2; sysco programının daha iyileştirilmiş bir sürümü.
7070- collector; sysinfo küfesini kullanarak cpu, memory metrikleri toplayan uygulama.
71+ - mocking; Birim testlerde mock nesne kullanımının ele alındığı örnek.
7172- drone-lab; Konu tekrarı, birim testler, lifetimes kullanımları.
7273- fops; Temel I/O işlemleri.
7374- 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+
17#[ allow( dead_code) ]
28pub trait Actor {
39 fn draw ( & self ) ;
410 fn update ( & mut self ) ;
511}
612
713#[ derive( Default ) ]
14+ #[ allow( dead_code) ]
815pub struct Game {
916 // width: f32,
1017 // height: f32,
1118 size : Size ,
1219 actors : Vec < Box < dyn Actor > > ,
20+ bots : Vec < Box < dyn Bot > > ,
1321}
1422
1523impl Game {
@@ -27,10 +35,16 @@ impl Game {
2735 actor. draw ( ) ;
2836 }
2937 }
38+ pub fn add_bot ( & mut self , bot : Box < dyn Bot > ) {
39+ self . bots . push ( bot) ;
40+ }
3041 pub fn update ( & mut self ) {
31- for actor in & mut self . actors {
42+ for actor in & mut self . actors {
3243 actor. update ( ) ;
3344 }
45+ for bot in & self . bots {
46+ bot. apply ( ) ;
47+ }
3448 }
3549}
3650
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+ } ;
25
36use framework:: * ;
47
@@ -11,6 +14,8 @@ fn main() {
1114 let mushroom = Mushroom :: new ( 2 , 10 ) ;
1215 game. add_actor ( Box :: new ( super_mario) ) ;
1316 game. add_actor ( Box :: new ( mushroom) ) ;
17+ let mega_mind = MindController :: default ( ) ;
18+ game. add_bot ( Box :: new ( mega_mind) ) ;
1419
1520 loop {
1621 sleep ( Duration :: from_secs ( 2 ) ) ;
@@ -20,6 +25,21 @@ fn main() {
2025 }
2126}
2227
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+
2343#[ allow( dead_code) ]
2444struct Player {
2545 id : u32 ,
You can’t perform that action at this time.
0 commit comments