working towards something that starts

This commit is contained in:
Enrico Fasoli 2015-10-03 01:02:13 +02:00
parent 5005bc17cf
commit 60c19f7d14
4 changed files with 38 additions and 1 deletions

View File

@ -3,6 +3,8 @@ mod action;
mod block; mod block;
mod structure; mod structure;
mod world;
fn main() { fn main() {
println!("Hello, world!");
} }

View File

View File

35
src/world.rs Normal file
View File

@ -0,0 +1,35 @@
use structure::Structure;
use action::Action;
use util::Point;
use std::sync::mpsc::{Sender,Receiver,channel};
pub struct World {
size: i32, // width and height of the grid
grid: Vec<Option<Structure>>, // access a structure using coordinates
structures: Vec<Structure> // list of all structures
}
impl World {
pub fn new(size: i32) -> World {
World {
size: size,
grid: Vec::new() as Vec<Option<Structure>>,
structures: Vec::new() as Vec<Structure>,
}
}
pub fn compute(&mut self) {
}
pub fn fix_coords(&self, p: Point) -> Point {
fn fix_coord(c: i32, limit: i32) -> i32 {
match c < 0 {
true => (c * -1) % limit,
false => match c >= limit {
true => c % limit,
false => c
}
}
};
Point { x: fix_coord(p.x,self.size), y: fix_coord(p.y,self.size) }
}
}