diff options
Diffstat (limited to 'src/game.rs')
-rw-r--r-- | src/game.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/game.rs b/src/game.rs new file mode 100644 index 0000000..4b527d2 --- /dev/null +++ b/src/game.rs @@ -0,0 +1,31 @@ +use std::cell::RefCell; +use std::rc::Rc; + +use crate::canvas::Canvas; +use crate::state::State; + +pub struct Game { + canvas: Canvas, + state: Rc<RefCell<State>>, +} + +impl Game { + pub fn new(canvas_id: &str, width: u32, height: u32) -> Game { + let canvas = Canvas::new(canvas_id, width, height); + let state = Rc::new(RefCell::new(State::new(width, height))); + + Game { + canvas, + state, + } + } + + pub fn update(&self) { + let next_state = self.state.borrow().next(); + *self.state.borrow_mut() = next_state; + } + + pub fn render(&self) { + self.state.borrow().draw(&self.canvas); + } +} |