11extern crate tcod;
2+ extern crate core;
23
34use std:: cell:: RefCell ;
45use std:: rc:: Rc ;
@@ -30,6 +31,8 @@ use combat::{
3031} ;
3132use actor:: Actor ;
3233
34+ use self :: core:: ops:: { Deref , DerefMut } ;
35+
3336pub struct MoveInfo {
3437 pub last_keypress : Option < KeyboardInput > ,
3538 pub char_location : Point ,
@@ -64,12 +67,12 @@ impl Game {
6467 let message_bounds = Bound :: new ( 0 , 52 , 99 , 61 ) ;
6568 let map_bounds = Bound :: new ( 0 , 0 , 78 , 49 ) ;
6669
67- let rc : Box < TcodRenderingComponent > = box RenderingComponent :: new ( total_bounds) ;
70+ let rc = Box :: new ( TcodRenderingComponent :: new ( total_bounds) ) ;
6871
69- let sw : Box < TcodStatsWindowComponent > = box WindowComponent :: new ( stats_bounds) ;
70- let iw : Box < TcodInputWindowComponent > = box WindowComponent :: new ( input_bounds) ;
71- let mw : Box < TcodMessagesWindowComponent > = box WindowComponent :: new ( message_bounds) ;
72- let maw : Box < TcodMapWindowComponent > = box WindowComponent :: new ( map_bounds) ;
72+ let sw = Box :: new ( TcodStatsWindowComponent :: new ( stats_bounds) ) ;
73+ let iw = Box :: new ( TcodInputWindowComponent :: new ( input_bounds) ) ;
74+ let mw = Box :: new ( TcodMessagesWindowComponent :: new ( message_bounds) ) ;
75+ let maw = Box :: new ( TcodMapWindowComponent :: new ( map_bounds) ) ;
7376
7477 let windows = Windows {
7578 input : iw,
@@ -78,19 +81,19 @@ impl Game {
7881 stats : sw
7982 } ;
8083
81- let gs : Box < MovementGameState > = box GameState :: new ( ) ;
84+ let gs = Box :: new ( MovementGameState :: new ( ) ) ;
8285
8386 let move_info = Rc :: new ( RefCell :: new ( MoveInfo :: new ( map_bounds) ) ) ;
8487 let mut maps = Maps :: new ( move_info. clone ( ) ) ;
8588
86- maps. friends . push_actor ( Point :: new ( 10 , 10 ) , box Actor :: dog ( 10 , 10 , move_info. clone ( ) ) ) ;
87- maps. friends . push_actor ( Point :: new ( 40 , 25 ) , box Actor :: cat ( 40 , 25 , move_info. clone ( ) ) ) ;
88- maps. enemies . push_actor ( Point :: new ( 20 , 20 ) , box Actor :: kobold ( 20 , 20 , move_info. clone ( ) ) ) ;
89+ maps. friends . push_actor ( Point :: new ( 10 , 10 ) , Box :: new ( Actor :: dog ( 10 , 10 , move_info. clone ( ) ) ) ) ;
90+ maps. friends . push_actor ( Point :: new ( 40 , 25 ) , Box :: new ( Actor :: cat ( 40 , 25 , move_info. clone ( ) ) ) ) ;
91+ maps. enemies . push_actor ( Point :: new ( 20 , 20 ) , Box :: new ( Actor :: kobold ( 20 , 20 , move_info. clone ( ) ) ) ) ;
8992
9093 let char_location = {
9194 move_info. borrow ( ) . deref ( ) . char_location
9295 } ;
93- maps. pcs . push_actor ( char_location, box Actor :: heroine ( move_info. clone ( ) ) ) ;
96+ maps. pcs . push_actor ( char_location, Box :: new ( Actor :: heroine ( move_info. clone ( ) ) ) ) ;
9497
9598 Game {
9699 exit : false ,
@@ -104,7 +107,8 @@ impl Game {
104107 }
105108
106109 pub fn render ( & mut self ) {
107- self . game_state . render ( & mut self . rendering_component , & mut self . maps , & mut self . windows ) ;
110+ let ref mut render_component = self . rendering_component ;
111+ self . game_state . render ( render_component, & mut self . maps , & mut self . windows ) ;
108112 }
109113
110114 pub fn update ( & mut self ) {
@@ -134,28 +138,28 @@ impl Game {
134138 Some ( ks) => {
135139 match ks. key {
136140 Printable ( '/' ) => {
137- let w : Box < Sword > = box Weapon :: new ( ) ;
138- let is : Box < AttackInputGameState > = box GameState :: new_with_weapon ( w) ;
139- self . game_state = is as Box < GameState > ;
141+ let w = Box :: new ( Sword :: new ( ) ) ;
142+ let is = Box :: new ( AttackInputGameState :: new_with_weapon ( w) ) ;
143+ self . game_state = is;
140144 } ,
141145 Printable ( '^' ) => {
142- let w : Box < Boomerang > = box Weapon :: new ( ) ;
143- let is : Box < AttackInputGameState > = box GameState :: new_with_weapon ( w) ;
144- self . game_state = is as Box < GameState > ;
146+ let w = Box :: new ( Boomerang :: new ( ) ) ;
147+ let is = Box :: new ( AttackInputGameState :: new_with_weapon ( w) ) ;
148+ self . game_state = is;
145149 } ,
146150 Printable ( '*' ) => {
147- let w : Box < Boomerang > = box Weapon :: new ( ) ;
148- let is : Box < AttackInputGameState > = box GameState :: new_with_weapon ( w) ;
149- self . game_state = is as Box < GameState > ;
151+ let w = Box :: new ( Boomerang :: new ( ) ) ;
152+ let is = Box :: new ( AttackInputGameState :: new_with_weapon ( w) ) ;
153+ self . game_state = is;
150154 } ,
151155 Printable ( '%' ) => {
152- let w : Box < Boomerang > = box Weapon :: new ( ) ;
153- let is : Box < AttackInputGameState > = box GameState :: new_with_weapon ( w) ;
154- self . game_state = is as Box < GameState > ;
156+ let w = Box :: new ( Boomerang :: new ( ) ) ;
157+ let is = Box :: new ( AttackInputGameState :: new_with_weapon ( w) ) ;
158+ self . game_state = is;
155159 } ,
156160 _ => {
157- let ms : Box < MovementGameState > = box GameState :: new ( ) ;
158- self . game_state = ms as Box < GameState > ;
161+ let ms = Box :: new ( MovementGameState :: new ( ) ) ;
162+ self . game_state = ms;
159163 }
160164 }
161165 } ,
0 commit comments