I dont know man

This commit is contained in:
Daniel Løvbrøtte Olsen 2018-10-09 22:40:12 +02:00
parent 51fe46cca0
commit 6d1d97ed9d
5 changed files with 149 additions and 16 deletions

1
Cargo.lock generated
View File

@ -7,6 +7,7 @@ dependencies = [
"rocket 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_codegen 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_contrib 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]

View File

@ -8,6 +8,7 @@ rocket = "0.3.17"
rocket_codegen = "0.3.17"
rand = "0.5.5"
base64 = "0.9.3"
serde_json = "1.0.32"
[dependencies.rocket_contrib]
version = "*"

6
Rocket.toml Normal file
View File

@ -0,0 +1,6 @@
[development]
address = "0.0.0.0"
port = 8000
workers = 8
log = "normal"
limits = { forms = 32768 }

40
main.rs
View File

@ -6,10 +6,13 @@ use std::str::FromStr;
extern crate rocket;
extern crate rocket_contrib;
#[macro_use] extern crate rocket_contrib;
use rocket::http::RawStr;
use rocket_contrib::Json;
//extern crate serde_json;
//use serde_json::{Value, Error};
extern crate rand;
use rand::Rng;
@ -17,7 +20,7 @@ extern crate base64;
fn main()
{
rocket::ignite().mount("/", routes![index,login]).launch();
rocket::ignite().mount("/", routes![index,login,]).launch();
}
#[get("/")]
@ -27,25 +30,30 @@ fn index() -> &'static str {
}
#[get("/login/<username>/<password>")]
fn login(username: &RawStr, password: &RawStr) -> String
fn login(username: &RawStr, password: &RawStr) -> Json
{
let mut rng = rand::thread_rng();
let session: u64 = rng.gen();
format!("{:x}", session)
let session = format!("{:x}", session);
Json(json!(session))
}
/*#[get("/<game_id>/<session_id>/get_stars")]
#[get("/game/<game_id>/<session_id>/get_stars")]
fn get_stars(game_id: &RawStr, session_id: &RawStr) -> Json
{
let data = r#"{[
{
id: 0,
"name": "StarGazer",
"resources": 43,
"coordinates {
x: 40,
y: 50
},
]}"#;
*/}
let player = Player {
name: "Daniel",
color: (0,255,255)
};
let star = Star {
id: 80085,
name: "Loli sanctuary",
coordinates: (50, 64),
resources: 50
};
Json(star)
}

117
types.rs Normal file
View File

@ -0,0 +1,117 @@
#[derive(Serialize)]
struct TechFunc {
on_cycle: Option<fn(Player)>,
on_tick: Option<fn(Player)>,
passive: Option<fn(Player)>
}
impl Default for TechFunc {
fn default() -> TechFunc {
TechFunc {
on_cycle: None,
on_tick: None,
passive: None
}
}
}
#[derive(Serialize)]
struct Player {
name: String,
color: (u8, u8, u8),
tech: HashMap<String, (u16, TechFunc)>,
research_queue: vec<String>,
money: u16
}
fn scanning(player: Player) -> u16 {
let scan_level = player.tech.get("Scanning").0/144;
scan_level + 2
}
fn hyperspace(player: Player) -> u16 {
let hyperspace_level = player.tech.get("Hyperspace Range").0/144;
hyperspace_level + 3
}
fn terraforming(player: Player) -> u16 {
let terraforming_level = player.tech.get("Terraforming").0/144;
terrafirming*5
}
fn experimentation(player: Player) {
let terraforming_level = player.tech.get("Experimentation").0/144;
let n = player.tech.len();
let mut rng = rand::thread_rng();
tech = rng.gen_range(0, n);
}
impl Default for Player {
fn default() -> Player {
let mut techs = HashMap::new();
techs.insert("Scanning", (144, TechFunc{passive: scanning});
techs.insert("Hyperspace Range", (144, TechFunc{passive: hyperspace}));
techs.insert("Terraforming", (144, TechFunc{passive: terraforming}));
techs.insert("Experimentation", (144, TechFunc));
techs.insert("Weapons", (144, TechFunc));
techs.insert("Banking", (144, TechFunc));
techs.insert("Manufactoring", (144, TechFunc));
Player {
tech: techs
}
}
}
impl process for Weapons {
fn passive() -> (u16, u16) {
(self.amount/144, self.effect2)
}
}
Player.techs.get("Weapons").passive()
impl Player {
fn payday() {
let banking_level = self.techs.get("Banking")/144;
self.money = banking_level*75;
let experimentation_level = self.techs.get("Experimentation")
}
}
#[derive(Serialize)]
struct Infrastructure {
name: String,
amount: u16
}
#[derive(Serialize)]
struct Star {
id: u16,
name: String,
coordinates: (u32, u32),
resources: u16,
owner: Option<u8>,
buildings: vec<Infrastructure>
}
impl Default for Star {
fn default() {
let infrastructures = [
Infrastructure {name: "Economy", amount: 0},
Infrastructure {name: "Industry", amount: 0},
Infrastructure {name: "Science", amount: 0}
];
Star {
owner: None,
buildings: infrastructures
}
}
}