added enterprise to intro, entering quadrant names, and fixed bug in name indexing

This commit is contained in:
Christopher
2023-03-01 20:36:01 +13:00
parent a18112767d
commit 41ca9c3c70
4 changed files with 42 additions and 7 deletions

View File

@@ -8,10 +8,12 @@ pub fn move_enterprise(course: u8, warp_speed: f32, galaxy: &mut Galaxy) {
view::hit_edge(&end);
}
if galaxy.enterprise.quadrant != end.quadrant {
view::enter_quadrant(&end.quadrant);
}
galaxy.enterprise.quadrant = end.quadrant;
galaxy.enterprise.sector = end.sector;
// if new_quadrant isnt old quadrant print intro
view::short_range_scan(&galaxy)
}

View File

@@ -14,6 +14,7 @@ fn main() {
let mut galaxy = Galaxy::generate_new();
view::enterprise();
view::intro(&galaxy);
let _ = prompt("Press Enter when ready to accept command");

View File

@@ -106,7 +106,7 @@ impl Add<Pos> for Pos {
impl Display for Pos {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} , {}", self.0, self.1)
write!(f, "{} , {}", self.0 + 1, self.1 + 1)
}
}

View File

@@ -1,5 +1,33 @@
use crate::model::{Galaxy, Pos, EndPosition, SectorStatus};
pub fn enterprise() {
println!("
,------*------,
,------------- '--- ------'
'-------- --' / /
,---' '-------/ /--,
'----------------'
THE USS ENTERPRISE --- NCC-1701
")
}
pub fn intro(model: &Galaxy) {
let star_bases = model.remaining_starbases();
let mut star_base_message: String = "There is 1 starbase".into();
@@ -9,7 +37,7 @@ pub fn intro(model: &Galaxy) {
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.",
on stardate {}. This gives you {} days. {} in the galaxy for resupplying your ship.\n",
model.remaining_klingons(), model.final_stardate, model.final_stardate - model.stardate, star_base_message)
}
@@ -36,13 +64,17 @@ 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],
REGION_NAMES[((quadrant.0 << 1) + (quadrant.1 >> 2)) 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))
println!("\nYour mission begins with your starship located
in the galactic quadrant, '{}'.\n", quadrant_name(quadrant))
}
pub fn enter_quadrant(quadrant: &Pos) {
println!("\nNow entering {} quadrant . . .\n", quadrant_name(quadrant))
}
pub fn short_range_scan(model: &Galaxy) {