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