Compare commits
18 Commits
new_level_
...
main
Author | SHA1 | Date |
---|---|---|
Joachim Lusiardi | 94c787d8c7 | |
Joachim Lusiardi | 9776482922 | |
Joachim Lusiardi | fb69c932a8 | |
Joachim Lusiardi | 62e13ace4c | |
Joachim Lusiardi | 51123ecd8e | |
Joachim Lusiardi | 4d77265b2f | |
Joachim Lusiardi | c91d57f049 | |
Joachim Lusiardi | 8f151836bd | |
Joachim Lusiardi | 9d862011a7 | |
Joachim Lusiardi | d068620c3f | |
Joachim Lusiardi | 6660c11306 | |
Joachim Lusiardi | 1d8896d1ad | |
Joachim Lusiardi | 252c1c244d | |
Joachim Lusiardi | ef3a6026f5 | |
Joachim Lusiardi | 542616cb0b | |
Joachim Lusiardi | 9a6c8f5116 | |
Joachim Lusiardi | d82e0d2d48 | |
Joachim Lusiardi | a542e4b1c0 |
|
@ -22,3 +22,7 @@ jobs:
|
|||
ls -al target/debian
|
||||
UPLOAD_FILE=$(ls target/debian/*.deb)
|
||||
curl --user jlusiardi:${{ secrets.UPLOAD_TOKEN }} --upload-file ${UPLOAD_FILE} https://gitea.intern.haus-in-hirschaid.de/api/packages/jlusiardi/debian/pool/bionic/main/upload
|
||||
echo -e "${{ secrets.DEPLOY_PRIVATE_KEY }}" > /tmp/ssh_key
|
||||
chmod 0600 /tmp/ssh_key
|
||||
scp -o StrictHostKeyChecking=no -i /tmp/ssh_key ${UPLOAD_FILE} jlusiardi@april2023.lusiardi.de:/var/www/p17.lusiardi.de/el_diabolo
|
||||
ssh -o StrictHostKeyChecking=no -i /tmp/ssh_key jlusiardi@april2023.lusiardi.de /var/www/p17.lusiardi.de/el_diabolo/generate_index.sh
|
|
@ -147,7 +147,7 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
|||
|
||||
[[package]]
|
||||
name = "el_diabolo"
|
||||
version = "0.1.0"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"crossterm",
|
||||
"macros",
|
||||
|
@ -234,6 +234,12 @@ dependencies = [
|
|||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indoc"
|
||||
version = "2.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
|
||||
|
||||
[[package]]
|
||||
name = "instability"
|
||||
version = "0.3.2"
|
||||
|
@ -429,23 +435,23 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ratatui"
|
||||
version = "0.28.1"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fdef7f9be5c0122f890d58bdf4d964349ba6a6161f705907526d891efabba57d"
|
||||
checksum = "eabd94c2f37801c20583fc49dd5cd6b0ba68c716787c2dd6ed18571e1e63117b"
|
||||
dependencies = [
|
||||
"bitflags 2.4.1",
|
||||
"cassowary",
|
||||
"compact_str",
|
||||
"crossterm",
|
||||
"indoc",
|
||||
"instability",
|
||||
"itertools",
|
||||
"lru",
|
||||
"paste",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"unicode-segmentation",
|
||||
"unicode-truncate",
|
||||
"unicode-width",
|
||||
"unicode-width 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -598,7 +604,7 @@ checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf"
|
|||
dependencies = [
|
||||
"itertools",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
"unicode-width 0.1.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -607,6 +613,12 @@ version = "0.1.14"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
|
|
|
@ -3,13 +3,13 @@ members = ["macros"]
|
|||
|
||||
[package]
|
||||
name = "el_diabolo"
|
||||
version = "0.1.0"
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
ratatui = "0.28.1"
|
||||
ratatui = "0.29.0"
|
||||
crossterm = "0.28.1"
|
||||
rand = "0.8.5"
|
||||
petgraph = "0.6.5"
|
||||
|
|
|
@ -24,6 +24,7 @@ pub fn create_monsters(input: TokenStream) -> TokenStream {
|
|||
experience_gain: usize,
|
||||
ticks_between_steps: u128,
|
||||
damage_range: RangeInclusive<usize>,
|
||||
defense: usize,
|
||||
}
|
||||
impl Monster for #variant_name {
|
||||
fn get_name(&self) -> &str { &self.name }
|
||||
|
@ -35,7 +36,7 @@ pub fn create_monsters(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
fn get_ticks_between_steps(&self) -> u128 { self.ticks_between_steps }
|
||||
fn damage(&self) -> usize { rand::thread_rng().gen_range(self.damage_range.clone()) }
|
||||
|
||||
fn defense(&self) -> usize { self.defense }
|
||||
#[cfg(test)]
|
||||
fn get_life(&self) -> usize { self.life }
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{collections::HashMap, ops::RangeInclusive};
|
||||
|
||||
use crate::{monster::MonsterTypes, room::RoomType};
|
||||
use crate::{monsters::MonsterTypes, room::RoomType};
|
||||
|
||||
/// the number of rooms in vertical direction
|
||||
pub const ROOMS_HORIZONTAL: usize = 8;
|
||||
|
|
18
src/game.rs
18
src/game.rs
|
@ -164,10 +164,10 @@ impl Game {
|
|||
match m {
|
||||
None => {}
|
||||
Some(m) => {
|
||||
let player_dmg = self.player.damage();
|
||||
let player_dmg = self.player.damage().saturating_sub(m.defense());
|
||||
m.decrease_life(player_dmg);
|
||||
if m.is_dead() {
|
||||
self.player.gain_experience(m.get_experience_gain());
|
||||
let level_up: bool = self.player.gain_experience(m.get_experience_gain());
|
||||
self.messages.insert(
|
||||
0,
|
||||
format!(
|
||||
|
@ -177,13 +177,23 @@ impl Game {
|
|||
)
|
||||
.to_string(),
|
||||
);
|
||||
if level_up {
|
||||
self.messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you reach a new experience level, it's now {}",
|
||||
self.player.get_experience_level(),
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
self.messages.insert(
|
||||
0,
|
||||
format!("you hit {} for {} damage.", m.get_name(), player_dmg).to_string(),
|
||||
);
|
||||
let monster_dmg = m.damage() as i16;
|
||||
self.player.change_life(-monster_dmg);
|
||||
let monster_dmg =m.damage().saturating_sub(self.player.defense());
|
||||
self.player.change_life(-(monster_dmg as i16));
|
||||
|
||||
self.messages.insert(
|
||||
0,
|
||||
|
|
71
src/level.rs
71
src/level.rs
|
@ -8,9 +8,9 @@ use crate::artifacts::Artifact;
|
|||
use crate::artifacts::{Chest, Potion};
|
||||
use crate::constants::LEVEL_HEIGHT;
|
||||
use crate::constants::LEVEL_WIDTH;
|
||||
use crate::monster::Monster;
|
||||
use crate::monsters::Monster;
|
||||
#[cfg(test)]
|
||||
use crate::monster::{Orc, Rat};
|
||||
use crate::monsters::{Orc, Rat};
|
||||
use crate::player::Player;
|
||||
use crate::position::HasPosition;
|
||||
use crate::position::Position;
|
||||
|
@ -147,43 +147,66 @@ impl Level {
|
|||
if player.get_immutable_position().get_x() == new_x
|
||||
&& player.get_immutable_position().get_y() == new_y
|
||||
{
|
||||
let monster_dmg = self.monsters[index].damage() as i16;
|
||||
player.change_life(-monster_dmg);
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"{} hits you for {} damage.",
|
||||
self.monsters[index].get_name(),
|
||||
monster_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
let player_dmg = player.damage();
|
||||
self.monsters[index].decrease_life(player_dmg);
|
||||
|
||||
// if the attack did not kill the opponent, back down
|
||||
if !player.is_dead() {
|
||||
let monster_dmg =self.monsters[index].damage().saturating_sub(player.defense());
|
||||
player.change_life(-(monster_dmg as i16));
|
||||
if player.is_dead() {
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you hit {} for {} damage and kill it.",
|
||||
"{} hits you for {} damage and kills you.",
|
||||
self.monsters[index].get_name(),
|
||||
player_dmg
|
||||
monster_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
self.monsters[index].get_position().change(-dx, -dy);
|
||||
} else {
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you hit {} for {} damage.",
|
||||
"{} hits you for {} damage.",
|
||||
self.monsters[index].get_name(),
|
||||
player_dmg
|
||||
monster_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
// player not dead => monster can occupy new position
|
||||
self.monsters[index].get_position().change(-dx, -dy);
|
||||
// player fights back
|
||||
let player_dmg = player.damage().saturating_sub(self.monsters[index].defense());
|
||||
self.monsters[index].decrease_life(player_dmg);
|
||||
if self.monsters[index].is_dead() {
|
||||
let level_up: bool = player
|
||||
.gain_experience(self.monsters[index].get_experience_gain());
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you hit {} for {} damage and kill it.",
|
||||
self.monsters[index].get_name(),
|
||||
player_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
if level_up {
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you reach a new experience level, it's now {}",
|
||||
player.get_experience_level(),
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you hit {} for {} damage.",
|
||||
self.monsters[index].get_name(),
|
||||
player_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -13,8 +13,8 @@ use crate::artifacts::Potion;
|
|||
use crate::constants::get_monsters_per_level;
|
||||
use crate::constants::ROOM_HEIGHT;
|
||||
use crate::constants::ROOM_WIDTH;
|
||||
use crate::monster::create_monster_by_type;
|
||||
use crate::monster::Monster;
|
||||
use crate::monsters::create_monster_by_type;
|
||||
use crate::monsters::Monster;
|
||||
use crate::position::Position;
|
||||
use crate::room::Connection;
|
||||
use crate::{
|
||||
|
@ -540,12 +540,12 @@ fn test_create_mst() {
|
|||
rooms[3][3].kind = RoomType::BasicRoom;
|
||||
let res = LevelGenerator::create_mst(&rooms);
|
||||
assert_eq!(res.node_count(), 4);
|
||||
assert_eq!(res.edge_count(), 3);
|
||||
assert_eq!(res.edge_count(), 4);
|
||||
|
||||
rooms[3][5].kind = RoomType::BasicRoom;
|
||||
let res = LevelGenerator::create_mst(&rooms);
|
||||
assert_eq!(res.node_count(), 5);
|
||||
assert_eq!(res.edge_count(), 4);
|
||||
assert_eq!(res.edge_count(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
pub struct LevelLadder {
|
||||
curr: usize,
|
||||
next: usize,
|
||||
}
|
||||
|
||||
impl Iterator for LevelLadder {
|
||||
type Item = usize;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let current = self.curr;
|
||||
|
||||
self.curr = self.next;
|
||||
self.next += current;
|
||||
|
||||
// Since there's no endpoint to a Fibonacci sequence, the `Iterator`
|
||||
// will never return `None`, and `Some` is always returned.
|
||||
Some(current * 30)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a Fibonacci sequence generator
|
||||
pub fn get_level_ladder() -> LevelLadder {
|
||||
LevelLadder { curr: 1, next: 2 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_ladder() {
|
||||
let mut iter = get_level_ladder();
|
||||
assert_eq!(iter.next(), Some(30));
|
||||
}
|
36
src/main.rs
36
src/main.rs
|
@ -14,7 +14,6 @@ use crossterm::{
|
|||
ExecutableCommand,
|
||||
};
|
||||
use ratatui::prelude::*;
|
||||
use ratatui::widgets::block::{Position, Title};
|
||||
use ratatui::widgets::{Block, BorderType, Borders, Wrap};
|
||||
use ratatui::{
|
||||
prelude::{CrosstermBackend, Terminal},
|
||||
|
@ -32,12 +31,16 @@ mod constants;
|
|||
mod game;
|
||||
mod level;
|
||||
mod level_generator;
|
||||
mod level_ladder;
|
||||
mod level_widget;
|
||||
mod monster;
|
||||
mod monsters;
|
||||
mod player;
|
||||
mod position;
|
||||
mod room;
|
||||
|
||||
const BACKGROUND_COLOR: Color = Color::DarkGray;
|
||||
const PANEL_BACKGROUND_COLOR: Color = Color::Black;
|
||||
|
||||
//
|
||||
fn main() -> Result<()> {
|
||||
let mut game = Game::new(Player::new(realname().as_str(), 30));
|
||||
|
@ -53,7 +56,7 @@ fn main() -> Result<()> {
|
|||
terminal.draw(|frame| {
|
||||
let mut area = frame.area();
|
||||
frame.render_widget(
|
||||
Block::default().style(Style::default().bg(Color::Green)),
|
||||
Block::default().style(Style::default().bg(BACKGROUND_COLOR)),
|
||||
area,
|
||||
);
|
||||
|
||||
|
@ -100,20 +103,19 @@ fn main() -> Result<()> {
|
|||
height: map_area.height / 2 + 1,
|
||||
};
|
||||
let block = Block::default()
|
||||
.title(
|
||||
Title::from(format!(" {} ", game.get_player().get_name()))
|
||||
.alignment(Alignment::Center)
|
||||
.position(Position::Top),
|
||||
.title_top(
|
||||
Line::from(format!(" {} ", game.get_player().get_name())).centered()
|
||||
)
|
||||
.borders(Borders::TOP)
|
||||
.border_style(Style::default().fg(Color::White))
|
||||
.border_type(BorderType::Rounded)
|
||||
.style(Style::default().bg(Color::Blue));
|
||||
.style(Style::default().bg(PANEL_BACKGROUND_COLOR));
|
||||
frame.render_widget(
|
||||
Paragraph::new(format!(
|
||||
"Health: {} of {}\nExp: {}\nGold: {}\nLevel: {} of {}\nInventory used: {} of {}",
|
||||
"Health: {} of {}\nDefense: {}\nExp: {}\nGold: {}\nLevel: {} of {}\nInventory used: {} of {}",
|
||||
game.get_player().get_life(),
|
||||
game.get_player().get_max_life(),
|
||||
game.get_player().defense(),
|
||||
game.get_player().get_experience(),
|
||||
game.get_player().get_gold(),
|
||||
game.get_player().get_immutable_position().get_level() + 1,
|
||||
|
@ -133,15 +135,13 @@ fn main() -> Result<()> {
|
|||
};
|
||||
// Display the latest messages from the game to the user
|
||||
let block = Block::default()
|
||||
.title(
|
||||
Title::from(" messages ")
|
||||
.alignment(Alignment::Center)
|
||||
.position(Position::Top),
|
||||
.title_top(
|
||||
Line::from(" messages ").centered()
|
||||
)
|
||||
.borders(Borders::TOP)
|
||||
.border_style(Style::default().fg(Color::White))
|
||||
.border_type(BorderType::Rounded)
|
||||
.style(Style::default().bg(Color::Blue));
|
||||
.style(Style::default().bg(PANEL_BACKGROUND_COLOR));
|
||||
|
||||
let paragraph1 = if game.messages.is_empty() {
|
||||
"".to_string()
|
||||
|
@ -218,12 +218,8 @@ fn main() -> Result<()> {
|
|||
area.width = 40;
|
||||
area.height = 20;
|
||||
let block = Block::default()
|
||||
.title(
|
||||
Title::from(" Game ended ")
|
||||
.alignment(Alignment::Center)
|
||||
.position(Position::Top),
|
||||
)
|
||||
.title(Title::from("Press `q` to quit!").position(Position::Bottom))
|
||||
.title_top(Line::from(" Game ended ").centered())
|
||||
.title_bottom(Line::from("Press `q` to quit!"))
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::White))
|
||||
.border_type(BorderType::Rounded)
|
||||
|
|
|
@ -16,6 +16,7 @@ pub trait Monster: HasPosition {
|
|||
#[cfg(test)]
|
||||
fn get_life(&self) -> usize;
|
||||
fn damage(&self) -> usize;
|
||||
fn defense(&self) -> usize;
|
||||
}
|
||||
|
||||
#[derive(CreateMonsters, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
|
@ -49,6 +50,7 @@ create_monster!(
|
|||
experience_gain: 5,
|
||||
ticks_between_steps: 5,
|
||||
damage_range: 1..=2,
|
||||
defense: 0,
|
||||
);
|
||||
|
||||
create_monster!(
|
||||
|
@ -60,6 +62,7 @@ create_monster!(
|
|||
experience_gain: 7,
|
||||
ticks_between_steps: 7,
|
||||
damage_range: 2..=3,
|
||||
defense: 0,
|
||||
);
|
||||
|
||||
create_monster!(
|
||||
|
@ -71,6 +74,7 @@ create_monster!(
|
|||
experience_gain: 10,
|
||||
ticks_between_steps: 10,
|
||||
damage_range: 2..=3,
|
||||
defense: 0,
|
||||
);
|
||||
|
||||
create_monster!(
|
||||
|
@ -82,6 +86,7 @@ create_monster!(
|
|||
experience_gain: 10,
|
||||
ticks_between_steps: 20,
|
||||
damage_range: 1..=4,
|
||||
defense: 0,
|
||||
);
|
||||
|
||||
create_monster!(
|
||||
|
@ -93,6 +98,7 @@ create_monster!(
|
|||
experience_gain: 20,
|
||||
ticks_between_steps: 10,
|
||||
damage_range: 1..=5,
|
||||
defense: 0,
|
||||
);
|
||||
|
||||
pub fn create_monster_by_type(monster_type: &MonsterTypes, position: Position) -> Box<dyn Monster> {
|
|
@ -2,6 +2,7 @@ use rand::Rng;
|
|||
use std::cmp::{max, min};
|
||||
|
||||
use crate::artifacts::Potion;
|
||||
use crate::level_ladder::get_level_ladder;
|
||||
use crate::position::{HasPosition, Position};
|
||||
|
||||
pub struct Player {
|
||||
|
@ -13,6 +14,8 @@ pub struct Player {
|
|||
experience: usize,
|
||||
inventory: Vec<Potion>,
|
||||
inventory_slots: usize,
|
||||
level: usize,
|
||||
defense: usize,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
|
@ -26,6 +29,8 @@ impl Player {
|
|||
experience: 0,
|
||||
inventory: vec![],
|
||||
inventory_slots: 2,
|
||||
level: 1,
|
||||
defense: 0,
|
||||
}
|
||||
}
|
||||
pub fn get_name(&self) -> String {
|
||||
|
@ -59,8 +64,28 @@ impl Player {
|
|||
self.gold
|
||||
}
|
||||
|
||||
pub fn gain_experience(&mut self, amount: usize) {
|
||||
self.experience += amount
|
||||
pub fn gain_experience(&mut self, amount: usize) -> bool {
|
||||
let mut result = false;
|
||||
for (i, level_step) in get_level_ladder().enumerate() {
|
||||
if self.experience <= level_step && self.experience + amount > level_step {
|
||||
self.level += 1;
|
||||
// make life gain depend on level?
|
||||
self.max_life += 5;
|
||||
self.defense += 1;
|
||||
self.life = self.max_life;
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
if i > self.level {
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.experience += amount;
|
||||
result
|
||||
}
|
||||
|
||||
pub fn get_experience_level(&self) -> usize {
|
||||
self.level
|
||||
}
|
||||
|
||||
pub fn get_experience(&self) -> usize {
|
||||
|
@ -71,6 +96,10 @@ impl Player {
|
|||
rand::thread_rng().gen_range(1..4)
|
||||
}
|
||||
|
||||
pub fn defense(&self) -> usize {
|
||||
self.defense
|
||||
}
|
||||
|
||||
pub fn add_to_inventory(&mut self, potion: &Potion) -> bool {
|
||||
if self.inventory.len() < self.inventory_slots {
|
||||
self.inventory.push(*potion);
|
||||
|
@ -116,6 +145,8 @@ fn test_get_name() {
|
|||
experience: 0,
|
||||
inventory: vec![],
|
||||
inventory_slots: 1,
|
||||
level: 0,
|
||||
defense: 0,
|
||||
};
|
||||
assert_eq!(p.get_name(), "Teddy Tester");
|
||||
}
|
||||
|
@ -141,6 +172,8 @@ fn test_change_life() {
|
|||
experience: 0,
|
||||
inventory: vec![],
|
||||
inventory_slots: 1,
|
||||
level: 0,
|
||||
defense: 0,
|
||||
};
|
||||
assert_eq!(p.get_life(), 5);
|
||||
p.change_life(-2);
|
||||
|
@ -176,6 +209,8 @@ fn test_max_life() {
|
|||
experience: 0,
|
||||
inventory: vec![],
|
||||
inventory_slots: 1,
|
||||
level: 0,
|
||||
defense: 0,
|
||||
};
|
||||
assert_eq!(p.get_max_life(), 10);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue