Skip to content

Commit e4baa8f

Browse files
author
Jared McFarland
committed
Initial Commit
0 parents  commit e4baa8f

File tree

9 files changed

+422
-0
lines changed

9 files changed

+422
-0
lines changed

.build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cp ~/src/libtcod/*.dylib $OUT_DIR/
2+
cp ~/src/libtcod/terminal.png $OUT_DIR/

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target/
2+
3+
*.dylib
4+
*.rlib
5+
6+
terminal.png

Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
3+
name = "dwemthys"
4+
version = "0.0.1"
5+
authors = ["jmcfarland"]
6+
build = "sh .build.sh"
7+
8+
[dependencies.color]
9+
10+
git = "https://github.com/bjz/color-rs.git"
11+
12+
[dependencies.tcod]
13+
14+
git = "https://github.com/tomassedovic/tcod-rs.git"
15+

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod monster;
2+
pub mod player;
3+
pub mod vm;

src/main.rs

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
extern crate dwemthys;
2+
extern crate tcod;
3+
4+
use std::io;
5+
use std::rand::Rng;
6+
7+
use dwemthys::monster::Monster;
8+
use dwemthys::player::Player;
9+
use dwemthys::vm::VM;
10+
use tcod::{Console, background_flag, key_code, Special};
11+
12+
struct Game {
13+
monsters: Vec<Monster>,
14+
player: Player,
15+
monster: Option<Monster>,
16+
player_weapon: int,
17+
over: bool
18+
}
19+
20+
impl Game {
21+
fn new() -> Game {
22+
let monsters: Vec<Monster> = vec![
23+
Monster::dragon(),
24+
Monster::cyclist(),
25+
Monster::deer(),
26+
Monster::ombudsman(),
27+
Monster::angel(),
28+
Monster::monkey()
29+
];
30+
let player = Player::rabbit();
31+
32+
Game { monsters: monsters, player: player, monster: None, player_weapon: -1, over: false }
33+
}
34+
35+
fn introduce_foe(&mut self) {
36+
let should_get_new = match self.monster {
37+
Some(ref m) => m.life < 1,
38+
None => true
39+
};
40+
if should_get_new {
41+
let opt : Option<Monster> = self.monsters.pop();
42+
self.monster = opt.clone();
43+
let name = match opt {
44+
Some(monster) => monster.name,
45+
None => { self.over = true; return }
46+
};
47+
48+
println!("[Get ready. {:s} has emerged.]", name)
49+
}
50+
}
51+
52+
fn process_input(&mut self) {
53+
self.player_weapon = -1;
54+
println!("How would you like to attack? Boomerang, Hero's Sword, Lettuce or Bombs?");
55+
println!("^ for Boomerang, / for Sword, % for Lettuce, * for Bombs or h for an
56+
explanation.");
57+
58+
let mut reader = io::stdin();
59+
let input = reader.read_line().ok().expect("Failed to read line.");
60+
let input_char: Option<String> = from_str(input.as_slice().trim());
61+
62+
let command = match input_char {
63+
Some(string) => string,
64+
None => fail!("fuck")
65+
};
66+
let sword_dmg = match self.monster.clone() {
67+
Some(monster) => (4 + ((monster.life % 10) ^ 2)),
68+
None => fail!("Game over!")
69+
};
70+
71+
if command == "*".to_string() {
72+
if self.player.bombs > 0 {
73+
self.player_weapon = 86;
74+
self.player.bombs -= 1;
75+
} else {
76+
println!("You're out of bombs!");
77+
}
78+
} else if command == "/".to_string() {
79+
self.player_weapon = sword_dmg;
80+
} else if command == "%".to_string() {
81+
self.player.lettuce();
82+
self.player_weapon = 0;
83+
} else if command == "^".to_string() {
84+
self.player_weapon = 13;
85+
} else if command == "h".to_string() {
86+
println!("Your weapons:
87+
^ (Boomerang) has strength 13
88+
/ (Hero's Sword) has variable strength based on your opponent ({:d})
89+
% (Lettuce) Lettuce will build your strength and extra ruffage will fly in the face of your opponent!!
90+
* (Bomb) You only have {:d} left!", 1i, self.player.bombs);
91+
} else {
92+
println!("That didn't make any sense!");
93+
}
94+
}
95+
96+
fn display_intro(&self) {
97+
println!("A scalding SEETHING LAVA infiltrates the cacauphonous ENGORGED MINESHAFTS deep
98+
within the ageless canopy of the DWEMTHY FOREST... chalky and nocturnal screams from the
99+
belly of the RAVENOUS WILD STORKUPINE... who eats wet goslings RIGHT AFTER they've had a
100+
few graham crackers and a midday nap... amidst starved hippos TECHNICALLY ORPHANED but
101+
truthfully sheltered by umbrellas owned jointly by car dealership conglomerates... beneath
102+
uncapped vials of mildly pulpy BLUE ELIXIR... which shall remain... heretofore...
103+
UNDISTURBED... DWEMTHY!!!");
104+
105+
println!("You have six foes.");
106+
107+
println!("These are the living, breathing monstrosities of Dwemthy's Array. I don't know
108+
how they got there. No one knows. Actually, I'm guessing the IntrepidDecomposedCyclist rode
109+
his ten-speed. But the others: NO ONE knows.
110+
111+
If it's really important for you to know, let's just say the others were born there. Can we
112+
move on??
113+
114+
As Dwemthy's Array gets deeper, the challenge becomes more difficult.");
115+
116+
println!("Fight the Array and the monsters will appear as you go. Godspeed and may you
117+
return with harrowing tales and nary an angel talon piercing through your shoulder.
118+
119+
Oh, and none of this \"I'm too young to die\" business. I'm sick of that crap. I'm not going
120+
to have you insulting our undead young people. They are our future. After our future is
121+
over, that is.");
122+
123+
println!("\nPrepare for battle!\n\n=================\n\n")
124+
}
125+
126+
fn update_game(&mut self) {
127+
let weapon = self.player_weapon;
128+
{
129+
let monster = match self.monster {
130+
Some(ref mut monster) => monster,
131+
None => { self.over = true; return }
132+
};
133+
self.player.fight(monster, weapon);
134+
}
135+
if self.player.life < 1i {
136+
self.revive_rabbit();
137+
}
138+
}
139+
140+
fn revive_rabbit(&mut self) {
141+
println!("You have fallen in battle, but another foolish young rabbit rushes to take your
142+
place!");
143+
self.player = Player::rabbit();
144+
}
145+
146+
fn render(&self) {
147+
println!("You have {:d} health!!", self.player.life);
148+
}
149+
}
150+
151+
fn main() {
152+
let mut con = Console::init_root(80, 50, "libtcod Rust tutorial", false);
153+
let mut exit = false;
154+
while !(Console::window_closed() || exit) {
155+
con.clear();
156+
con.put_char(40, 25, '@', background_flag::Set);
157+
con.flush();
158+
let keypress = con.wait_for_keypress(true);
159+
match keypress.key {
160+
Special(key_code::Escape) => exit = true,
161+
_ => {}
162+
}
163+
}
164+
//let n : Option<u8> = from_str("05");
165+
//let num : u8 = match n {
166+
//Some(nu) => nu,
167+
//None => fail!("couldn't parse")
168+
//};
169+
//let array = [0x05, 0x10, 0x00, 0x05, 10u8, 0x01, num, 25u8];
170+
//let mut vm = VM::new();
171+
//vm.interpret(array);
172+
//let mut game = Game::new();
173+
//game.display_intro();
174+
//game.introduce_foe();
175+
176+
//loop {
177+
//&mut game.process_input();
178+
//if game.player_weapon != -1 {
179+
//&mut game.update_game();
180+
//&mut game.introduce_foe();
181+
//game.render();
182+
//}
183+
//if game.over { break; }
184+
//}
185+
}

src/monster/mod.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use std;
2+
use std::rand::Rng;
3+
4+
pub struct Monster {
5+
pub strength: int,
6+
pub life: int,
7+
pub charisma: int,
8+
pub weapon: int,
9+
pub name: String
10+
}
11+
12+
impl Monster {
13+
pub fn new(s: int, l: int, c: int, w: int, n: String) -> Monster {
14+
Monster { life: l, strength: s, charisma: c, weapon: w, name: n }
15+
}
16+
17+
pub fn monkey() -> Monster {
18+
Monster::new(35, 46, 91, 2, "Industrial Raver Monkey".to_string())
19+
}
20+
21+
pub fn angel() -> Monster {
22+
Monster::new(6, 540, 144, 50, "Dwarven Angel".to_string())
23+
}
24+
25+
pub fn ombudsman() -> Monster {
26+
Monster::new(6, 320, 144, 50, "Assistant Vice Tentacle And Ombudsman".to_string())
27+
}
28+
29+
pub fn deer() -> Monster {
30+
Monster::new(192, 655, 19, 109, "Teeth Deer".to_string())
31+
}
32+
33+
pub fn cyclist() -> Monster {
34+
Monster::new(560, 901, 422, 105, "Intrepid Decomposed Cyclist".to_string())
35+
}
36+
37+
pub fn dragon() -> Monster {
38+
Monster::new(451, 1340, 1020, 939, "Dragon".to_string())
39+
}
40+
41+
pub fn hit(&mut self, dmg: int) {
42+
let p_up = std::rand::task_rng().gen_range(0i, self.charisma);
43+
let mut life = self.life;
44+
if p_up % 9 == 7 {
45+
life += p_up / 4;
46+
println!("[{:s} magick powers up {:d}!]", self.name, p_up);
47+
}
48+
life -= dmg;
49+
if life < 0 {
50+
println!("[{:s} has died.]", self.name);
51+
}
52+
self.life = life;
53+
}
54+
55+
}
56+
57+
impl Clone for Monster {
58+
fn clone(&self) -> Monster {
59+
Monster { life: self.life, strength: self.strength, charisma: self.charisma, weapon:
60+
self.weapon, name: self.name.clone() }
61+
}
62+
}

src/player/mod.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use std;
2+
use std::rand::Rng;
3+
4+
use monster::Monster;
5+
6+
pub struct Player {
7+
pub strength: int,
8+
pub life: int,
9+
pub charisma: int,
10+
pub bombs: int
11+
}
12+
13+
impl Player {
14+
pub fn new(s: int, l: int, c: int, b: int) -> Player {
15+
Player { life: l, strength: s, charisma: c, bombs: b }
16+
}
17+
18+
pub fn rabbit() -> Player {
19+
Player::new(2, 10, 44, 3)
20+
}
21+
22+
pub fn fight(&mut self, mon: &mut Monster, weapon: int) {
23+
if self.life <= 0 {
24+
println!("[You're too dead to fight!]");
25+
return;
26+
}
27+
28+
let hit = std::rand::task_rng().gen_range(0i, self.strength + weapon);
29+
println!("[You hit {:s} with {:d} with points of damage!]", mon.name, hit);
30+
mon.hit(hit);
31+
32+
if mon.life > 0 {
33+
let hit = std::rand::task_rng().gen_range(0i, mon.strength + mon.weapon);
34+
println!("[{:s} hit you with {:d} points of damage!]", mon.name, hit);
35+
self.hit(hit);
36+
}
37+
}
38+
39+
pub fn lettuce(&mut self) {
40+
let lettuce = std::rand::task_rng().gen_range(0i, self.charisma);
41+
println!("[Healthy lettuce gives you {:d} life points!!]", lettuce);
42+
self.life += lettuce
43+
}
44+
45+
pub fn hit(&mut self, dmg: int) {
46+
let p_up = std::rand::task_rng().gen_range(0i, self.charisma);
47+
let mut life = self.life;
48+
if p_up % 9 == 7 {
49+
life += p_up / 4;
50+
println!("[Your magick powers up {:d}!]", p_up);
51+
}
52+
life -= dmg;
53+
if life < 0 {
54+
println!("[You have died.]");
55+
}
56+
self.life = life;
57+
}
58+
}

0 commit comments

Comments
 (0)