added intro section with quadrant name

This commit is contained in:
Christopher
2023-03-01 19:51:50 +13:00
parent efba942396
commit a18112767d
4 changed files with 62 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
use std::{io::{stdin, stdout, Write}, process::exit, str::FromStr};
use std::{io::{stdin, stdout, Write, Read}, process::exit, str::FromStr};
use model::Galaxy;
@@ -13,7 +13,11 @@ fn main() {
.expect("Error setting Ctrl-C handler");
let mut galaxy = Galaxy::generate_new();
// todo: init options, starting state and notes
view::intro(&galaxy);
let _ = prompt("Press Enter when ready to accept command");
view::starting_quadrant(&galaxy.enterprise.quadrant);
view::short_range_scan(&galaxy);
loop {

View File

@@ -6,6 +6,7 @@ use crate::view;
pub struct Galaxy {
pub stardate: f32,
pub final_stardate: f32,
pub quadrants: Vec<Quadrant>,
pub enterprise: Enterprise
}
@@ -131,15 +132,22 @@ impl Galaxy {
quadrants.into_iter().map(|q| { q.klingons.len() as u8 }).sum::<u8>()
}
pub fn remaining_starbases(&self) -> u8 {
let quadrants = &self.quadrants;
quadrants.into_iter().filter(|q| q.star_base.is_some()).count() as u8
}
pub fn generate_new() -> Self {
let quadrants = Self::generate_quadrants();
let mut rng = rand::thread_rng();
let enterprise_quadrant = Pos(rng.gen_range(0..8), rng.gen_range(0..8));
let enterprise_sector = quadrants[enterprise_quadrant.as_index()].find_empty_sector();
let stardate = rng.gen_range(20..=40) as f32 * 100.0;
Galaxy {
stardate: 3800.0,
stardate,
final_stardate: stardate + rng.gen_range(25..=35) as f32,
quadrants: quadrants,
enterprise: Enterprise {
condition: Condition::Green,

View File

@@ -1,5 +1,50 @@
use crate::model::{Galaxy, Pos, EndPosition, SectorStatus};
pub fn intro(model: &Galaxy) {
let star_bases = model.remaining_starbases();
let mut star_base_message: String = "There is 1 starbase".into();
if star_bases > 1 {
star_base_message = format!("There are {} starbases", star_bases);
}
println!("Your orders are as follows:
Destroy the {} Klingon warships which have invaded
the galaxy before they can attack federation headquarters
on stardate {}. This gives you {} days. {} in the galaxy for resupplying your ship.",
model.remaining_klingons(), model.final_stardate, model.final_stardate - model.stardate, star_base_message)
}
const REGION_NAMES: [&str; 16] = [
"Antares",
"Sirius",
"Rigel",
"Deneb",
"Procyon",
"Capella",
"Vega",
"Betelgeuse",
"Canopus",
"Aldebaran",
"Altair",
"Regulus",
"Sagittarius",
"Arcturus",
"Pollux",
"Spica"
];
const SUB_REGION_NAMES: [&str; 4] = ["I", "II", "III", "IV"];
fn quadrant_name(quadrant: &Pos) -> String {
format!("{} {}",
REGION_NAMES[(quadrant.0 << 1 + quadrant.1 >> 1) as usize],
SUB_REGION_NAMES[(quadrant.1 % 4) as usize])
}
pub fn starting_quadrant(quadrant: &Pos) {
println!("Your mission begins with your starship located
in the galactic quadrant, '{}'.", quadrant_name(quadrant))
}
pub fn short_range_scan(model: &Galaxy) {
let quadrant = &model.quadrants[model.enterprise.quadrant.as_index()];

View File

@@ -4,6 +4,8 @@ Started after movement and display of stats was finished (no energy management o
- [x] klingon movement
- [x] klingon firing, game over etc
- [ ] add intro
- [ ] add entering (and starting in) sector headers
- [ ] remove energy on move
- [ ] shields
- [ ] stranded...