use std::cell::RefCell; use std::rc::Rc; use crate::canvas::Canvas; use crate::state::State; pub struct Game { canvas: Canvas, state: Rc>, } 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); } }