started work on a rust implementation of super star trek

This commit is contained in:
Christopher
2023-02-28 11:37:54 +13:00
parent ead3213fd8
commit c4b8da053b
3 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@@ -0,0 +1,34 @@
use model::{Galaxy, GameStatus, Pos, Quadrant};
mod model;
fn main() {
let mut galaxy = Galaxy::generate_new();
// create the model
// start the loop
loop {
view(&galaxy);
galaxy = wait_for_command(&galaxy);
}
// rather than using a loop, recursion and passing the ownership might be better
}
fn view(model: &Galaxy) {
match model.game_status {
GameStatus::ShortRangeScan => {
let quadrant = &model.quadrants[model.enterprise.sector.as_index()];
render_quadrant(&model.enterprise.sector, quadrant)
}
}
}
fn render_quadrant(enterprise_sector: &Pos, quadrant: &Quadrant) {
}
fn wait_for_command(galaxy: &Galaxy) -> Galaxy {
// listen for command from readline
// handle bad commands
// update model
Galaxy::generate_new()
}

View File

@@ -0,0 +1,43 @@
pub struct Galaxy {
pub quadrants: Vec<Quadrant>,
pub enterprise: Enterprise,
pub game_status: GameStatus
}
pub struct Pos(u8, u8);
impl Pos {
pub fn as_index(&self) -> usize {
(self.0 * 8 + self.1).into()
}
}
pub struct Quadrant {
pub stars: Vec<Pos>,
pub star_bases: Vec<Pos>,
pub klingons: Vec<Klingon>
}
pub struct Klingon {
pub sector: Pos
}
pub struct Enterprise {
pub quadrant: Pos,
pub sector: Pos,
}
pub enum GameStatus {
ShortRangeScan
}
impl Galaxy {
pub fn generate_new() -> Self {
Galaxy {
quadrants: Vec::new(),
enterprise: Enterprise { quadrant: Pos(0,0), sector: Pos(0,0) },
game_status: GameStatus::ShortRangeScan
}
}
}