Basic Game object testing
This commit is contained in:
parent
aa56a22f1b
commit
d2cbb431a7
|
@ -1,3 +1,4 @@
|
|||
#[derive(Debug)]
|
||||
enum Order {
|
||||
NOTHING,
|
||||
GARRISON(u16),
|
||||
|
@ -9,12 +10,20 @@ enum Order {
|
|||
COLLECT_ALL_BUT(u16),
|
||||
LOOP
|
||||
}
|
||||
impl Default for Order {
|
||||
fn default() -> Self {
|
||||
Order::NOTHING
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default,Debug)]
|
||||
pub struct Carrier {
|
||||
owner: &Player,
|
||||
ownerID: u8,
|
||||
name: String,
|
||||
ships: u16,
|
||||
location: (u16, u16),
|
||||
orders: Vec<(&Star, Order)>,
|
||||
order_pointer: u8
|
||||
orders: Vec<(u8, Order)>,
|
||||
completedOrders: Vec<(u8, Order)>,
|
||||
order_pointer: u8,
|
||||
repeat: bool
|
||||
}
|
17
game/mod.rs
17
game/mod.rs
|
@ -2,12 +2,21 @@ mod player;
|
|||
mod star;
|
||||
mod carrier;
|
||||
|
||||
use game::player::Player;
|
||||
use game::star::Star;
|
||||
use game::carrier::Carrier;
|
||||
use self::player::Player;
|
||||
use self::star::Star;
|
||||
use self::carrier::Carrier;
|
||||
|
||||
struct Game {
|
||||
#[derive(Default,Debug)]
|
||||
pub struct Game {
|
||||
players: Vec<Player>,
|
||||
stars: Vec<Star>,
|
||||
carriers: Vec<Carrier>
|
||||
}
|
||||
|
||||
impl Game {
|
||||
pub fn addPlayer(&mut self, name: String) {
|
||||
let mut player: Player = Player::default();
|
||||
player.name = name;
|
||||
self.players.push(player);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
#[derive(Debug)]
|
||||
enum Race {
|
||||
Griffin,
|
||||
Catte
|
||||
|
@ -8,6 +9,7 @@ impl Default for Race {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ResearchItem {
|
||||
levels: u8,
|
||||
points: u16
|
||||
|
@ -21,7 +23,7 @@ impl Default for ResearchItem {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Default,Debug)]
|
||||
struct Research {
|
||||
weapons: ResearchItem,
|
||||
banking: ResearchItem,
|
||||
|
@ -32,9 +34,9 @@ struct Research {
|
|||
scanning: ResearchItem
|
||||
}
|
||||
|
||||
//#[derive(Default)]
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
name: String,
|
||||
pub name: String,
|
||||
color: (u8, u8, u8),
|
||||
race: Race,
|
||||
research: Research
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#[derive(Default,Debug)]
|
||||
struct Infrastructre {
|
||||
factory: u16,
|
||||
lab: u16,
|
||||
bank: u16
|
||||
}
|
||||
|
||||
#[derive(Default,Debug)]
|
||||
pub struct Star {
|
||||
owner: Option<&player>,
|
||||
ownerID: Option<u8>,
|
||||
location: (u16, u16),
|
||||
name: String,
|
||||
natural_resources: u16,
|
||||
|
|
12
main.rs
12
main.rs
|
@ -4,12 +4,13 @@
|
|||
#[macro_use] extern crate rocket_contrib;
|
||||
|
||||
mod game;
|
||||
use game::Game;
|
||||
|
||||
use rocket_contrib::serve::StaticFiles;
|
||||
|
||||
fn main() {
|
||||
let myrocket = rocket::ignite().mount("/", StaticFiles::from("static"));
|
||||
let myrocket = myrocket.mount("/api", routes![world]);
|
||||
let myrocket = myrocket.mount("/api", routes![world,test]);
|
||||
myrocket.launch();
|
||||
}
|
||||
|
||||
|
@ -17,4 +18,13 @@ fn main() {
|
|||
#[get("/")]
|
||||
fn world() -> &'static str {
|
||||
"Hello, world!"
|
||||
}
|
||||
|
||||
#[get("/test")]
|
||||
fn test() -> String {
|
||||
let mut game: Game = Game::default();
|
||||
|
||||
game.addPlayer("Daniel".to_string());
|
||||
|
||||
format!("{:?}", game)
|
||||
}
|
Loading…
Reference in New Issue