Compare commits

...

14 Commits

Author SHA1 Message Date
Joachim Lusiardi 51123ecd8e version bump and index generation 2024-11-07 09:57:32 +01:00
Joachim Lusiardi 4d77265b2f remove debug output 2024-11-07 09:47:49 +01:00
Joachim Lusiardi c91d57f049 next try 2024-11-07 09:46:15 +01:00
Joachim Lusiardi 8f151836bd next try 2024-11-07 09:41:40 +01:00
Joachim Lusiardi 9d862011a7 testing 2024-11-07 09:37:22 +01:00
Joachim Lusiardi d068620c3f more tuning 2024-11-07 09:35:30 +01:00
Joachim Lusiardi 6660c11306 more debug 2024-11-07 09:29:24 +01:00
Joachim Lusiardi 1d8896d1ad debugging 2024-11-07 09:27:31 +01:00
Joachim Lusiardi 252c1c244d make key secure in container 2024-11-07 09:24:19 +01:00
Joachim Lusiardi ef3a6026f5 minor fixes 2024-11-07 09:22:19 +01:00
Joachim Lusiardi 542616cb0b version bump 2024-11-07 09:15:44 +01:00
Joachim Lusiardi 9a6c8f5116 try to auto publish to website 2024-11-07 09:15:24 +01:00
Joachim Lusiardi d82e0d2d48 version updates 2024-11-06 14:33:11 +01:00
Joachim Lusiardi a542e4b1c0 add mechanism for level gain 2024-11-06 14:29:30 +01:00
9 changed files with 143 additions and 48 deletions

View File

@ -22,3 +22,7 @@ jobs:
ls -al target/debian ls -al target/debian
UPLOAD_FILE=$(ls target/debian/*.deb) 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 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

24
Cargo.lock generated
View File

@ -147,7 +147,7 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]] [[package]]
name = "el_diabolo" name = "el_diabolo"
version = "0.1.0" version = "0.2.2"
dependencies = [ dependencies = [
"crossterm", "crossterm",
"macros", "macros",
@ -234,6 +234,12 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "indoc"
version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
[[package]] [[package]]
name = "instability" name = "instability"
version = "0.3.2" version = "0.3.2"
@ -429,23 +435,23 @@ dependencies = [
[[package]] [[package]]
name = "ratatui" name = "ratatui"
version = "0.28.1" version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdef7f9be5c0122f890d58bdf4d964349ba6a6161f705907526d891efabba57d" checksum = "eabd94c2f37801c20583fc49dd5cd6b0ba68c716787c2dd6ed18571e1e63117b"
dependencies = [ dependencies = [
"bitflags 2.4.1", "bitflags 2.4.1",
"cassowary", "cassowary",
"compact_str", "compact_str",
"crossterm", "crossterm",
"indoc",
"instability", "instability",
"itertools", "itertools",
"lru", "lru",
"paste", "paste",
"strum", "strum",
"strum_macros",
"unicode-segmentation", "unicode-segmentation",
"unicode-truncate", "unicode-truncate",
"unicode-width", "unicode-width 0.2.0",
] ]
[[package]] [[package]]
@ -598,7 +604,7 @@ checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf"
dependencies = [ dependencies = [
"itertools", "itertools",
"unicode-segmentation", "unicode-segmentation",
"unicode-width", "unicode-width 0.1.14",
] ]
[[package]] [[package]]
@ -607,6 +613,12 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"

View File

@ -3,13 +3,13 @@ members = ["macros"]
[package] [package]
name = "el_diabolo" name = "el_diabolo"
version = "0.1.0" version = "0.2.2"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
ratatui = "0.28.1" ratatui = "0.29.0"
crossterm = "0.28.1" crossterm = "0.28.1"
rand = "0.8.5" rand = "0.8.5"
petgraph = "0.6.5" petgraph = "0.6.5"

View File

@ -167,7 +167,7 @@ impl Game {
let player_dmg = self.player.damage(); let player_dmg = self.player.damage();
m.decrease_life(player_dmg); m.decrease_life(player_dmg);
if m.is_dead() { 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( self.messages.insert(
0, 0,
format!( format!(
@ -177,6 +177,16 @@ impl Game {
) )
.to_string(), .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 { } else {
self.messages.insert( self.messages.insert(
0, 0,

View File

@ -149,6 +149,17 @@ impl Level {
{ {
let monster_dmg = self.monsters[index].damage() as i16; let monster_dmg = self.monsters[index].damage() as i16;
player.change_life(-monster_dmg); player.change_life(-monster_dmg);
if player.is_dead() {
messages.insert(
0,
format!(
"{} hits you for {} damage and kills you.",
self.monsters[index].get_name(),
monster_dmg
)
.to_string(),
);
} else {
messages.insert( messages.insert(
0, 0,
format!( format!(
@ -158,12 +169,14 @@ impl Level {
) )
.to_string(), .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(); let player_dmg = player.damage();
self.monsters[index].decrease_life(player_dmg); self.monsters[index].decrease_life(player_dmg);
if self.monsters[index].is_dead() {
// if the attack did not kill the opponent, back down let level_up: bool = player
if !player.is_dead() { .gain_experience(self.monsters[index].get_experience_gain());
messages.insert( messages.insert(
0, 0,
format!( format!(
@ -173,7 +186,16 @@ impl Level {
) )
.to_string(), .to_string(),
); );
self.monsters[index].get_position().change(-dx, -dy); if level_up {
messages.insert(
0,
format!(
"you reach a new experience level, it's now {}",
player.get_experience_level(),
)
.to_string(),
);
}
} else { } else {
messages.insert( messages.insert(
0, 0,
@ -186,6 +208,7 @@ impl Level {
); );
} }
} }
}
break; break;
} }
} }

View File

@ -540,12 +540,12 @@ fn test_create_mst() {
rooms[3][3].kind = RoomType::BasicRoom; rooms[3][3].kind = RoomType::BasicRoom;
let res = LevelGenerator::create_mst(&rooms); let res = LevelGenerator::create_mst(&rooms);
assert_eq!(res.node_count(), 4); assert_eq!(res.node_count(), 4);
assert_eq!(res.edge_count(), 3); assert_eq!(res.edge_count(), 4);
rooms[3][5].kind = RoomType::BasicRoom; rooms[3][5].kind = RoomType::BasicRoom;
let res = LevelGenerator::create_mst(&rooms); let res = LevelGenerator::create_mst(&rooms);
assert_eq!(res.node_count(), 5); assert_eq!(res.node_count(), 5);
assert_eq!(res.edge_count(), 4); assert_eq!(res.edge_count(), 5);
} }
#[test] #[test]

30
src/level_ladder.rs Normal file
View File

@ -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));
}

View File

@ -14,7 +14,6 @@ use crossterm::{
ExecutableCommand, ExecutableCommand,
}; };
use ratatui::prelude::*; use ratatui::prelude::*;
use ratatui::widgets::block::{Position, Title};
use ratatui::widgets::{Block, BorderType, Borders, Wrap}; use ratatui::widgets::{Block, BorderType, Borders, Wrap};
use ratatui::{ use ratatui::{
prelude::{CrosstermBackend, Terminal}, prelude::{CrosstermBackend, Terminal},
@ -32,6 +31,7 @@ mod constants;
mod game; mod game;
mod level; mod level;
mod level_generator; mod level_generator;
mod level_ladder;
mod level_widget; mod level_widget;
mod monster; mod monster;
mod player; mod player;
@ -100,10 +100,8 @@ fn main() -> Result<()> {
height: map_area.height / 2 + 1, height: map_area.height / 2 + 1,
}; };
let block = Block::default() let block = Block::default()
.title( .title_top(
Title::from(format!(" {} ", game.get_player().get_name())) Line::from(format!(" {} ", game.get_player().get_name())).centered()
.alignment(Alignment::Center)
.position(Position::Top),
) )
.borders(Borders::TOP) .borders(Borders::TOP)
.border_style(Style::default().fg(Color::White)) .border_style(Style::default().fg(Color::White))
@ -133,10 +131,8 @@ fn main() -> Result<()> {
}; };
// Display the latest messages from the game to the user // Display the latest messages from the game to the user
let block = Block::default() let block = Block::default()
.title( .title_top(
Title::from(" messages ") Line::from(" messages ").centered()
.alignment(Alignment::Center)
.position(Position::Top),
) )
.borders(Borders::TOP) .borders(Borders::TOP)
.border_style(Style::default().fg(Color::White)) .border_style(Style::default().fg(Color::White))
@ -218,12 +214,8 @@ fn main() -> Result<()> {
area.width = 40; area.width = 40;
area.height = 20; area.height = 20;
let block = Block::default() let block = Block::default()
.title( .title_top(Line::from(" Game ended ").centered())
Title::from(" Game ended ") .title_bottom(Line::from("Press `q` to quit!"))
.alignment(Alignment::Center)
.position(Position::Top),
)
.title(Title::from("Press `q` to quit!").position(Position::Bottom))
.borders(Borders::ALL) .borders(Borders::ALL)
.border_style(Style::default().fg(Color::White)) .border_style(Style::default().fg(Color::White))
.border_type(BorderType::Rounded) .border_type(BorderType::Rounded)

View File

@ -2,6 +2,7 @@ use rand::Rng;
use std::cmp::{max, min}; use std::cmp::{max, min};
use crate::artifacts::Potion; use crate::artifacts::Potion;
use crate::level_ladder::get_level_ladder;
use crate::position::{HasPosition, Position}; use crate::position::{HasPosition, Position};
pub struct Player { pub struct Player {
@ -13,6 +14,7 @@ pub struct Player {
experience: usize, experience: usize,
inventory: Vec<Potion>, inventory: Vec<Potion>,
inventory_slots: usize, inventory_slots: usize,
level: usize,
} }
impl Player { impl Player {
@ -26,6 +28,7 @@ impl Player {
experience: 0, experience: 0,
inventory: vec![], inventory: vec![],
inventory_slots: 2, inventory_slots: 2,
level: 1,
} }
} }
pub fn get_name(&self) -> String { pub fn get_name(&self) -> String {
@ -59,8 +62,26 @@ impl Player {
self.gold self.gold
} }
pub fn gain_experience(&mut self, amount: usize) { pub fn gain_experience(&mut self, amount: usize) -> bool {
self.experience += amount 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;
self.max_life += 5;
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 { pub fn get_experience(&self) -> usize {
@ -116,6 +137,7 @@ fn test_get_name() {
experience: 0, experience: 0,
inventory: vec![], inventory: vec![],
inventory_slots: 1, inventory_slots: 1,
level: 0,
}; };
assert_eq!(p.get_name(), "Teddy Tester"); assert_eq!(p.get_name(), "Teddy Tester");
} }
@ -141,6 +163,7 @@ fn test_change_life() {
experience: 0, experience: 0,
inventory: vec![], inventory: vec![],
inventory_slots: 1, inventory_slots: 1,
level: 0,
}; };
assert_eq!(p.get_life(), 5); assert_eq!(p.get_life(), 5);
p.change_life(-2); p.change_life(-2);
@ -176,6 +199,7 @@ fn test_max_life() {
experience: 0, experience: 0,
inventory: vec![], inventory: vec![],
inventory_slots: 1, inventory_slots: 1,
level: 0,
}; };
assert_eq!(p.get_max_life(), 10); assert_eq!(p.get_max_life(), 10);
} }