Compare commits

...

3 Commits

8 changed files with 92 additions and 37 deletions

View File

@ -0,0 +1,24 @@
name: publish package
on:
push:
branches:
- main
jobs:
Explore-Gitea-Actions:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: run tests
run: |
cd ${{ gitea.workspace }}
cargo test --release
- name: build & release package
run: |
cd ${{ gitea.workspace }}
cargo build --release
cargo deb
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

View File

@ -10,4 +10,15 @@ ratatui = "0.28.1"
crossterm = "0.28.1" crossterm = "0.28.1"
rand = "0.8.5" rand = "0.8.5"
petgraph = "0.6.5" petgraph = "0.6.5"
whoami = "1.5.2" whoami = "1.5.2"
[package.metadata.deb]
maintainer = "Joachim Lusiardi <joachim@lusiardi.de>"
copyright = "2024, Joachim Lusiardi <joachim@lusiardi.de>"
extended-description = """Little roguelike game"""
depends = "$auto"
section = "game"
priority = "optional"
assets = [
["target/release/el_diabolo", "/usr/bin/", "755"],
]

View File

@ -1,3 +1,4 @@
use rand::Rng;
use ratatui::style::Color; use ratatui::style::Color;
use crate::player::Player; use crate::player::Player;
@ -22,11 +23,11 @@ pub struct Chest {
impl Chest { impl Chest {
pub fn new(position: Position) -> Self { pub fn new(position: Position) -> Self {
let level = position.get_level(); let min_gold = 10 * (position.get_level()+1);
let max_gold = min_gold + 10*position.get_level();
Self { Self {
position, position,
// TODO maybe randomize this? gold: rand::thread_rng().gen_range(min_gold..=max_gold),
gold: (level + 1) * 10,
} }
} }
} }
@ -61,9 +62,11 @@ pub struct Potion {
impl Potion { impl Potion {
pub fn new(position: Position) -> Self { pub fn new(position: Position) -> Self {
let min_health_gain = 5 + position.get_level();
let max_health_gain = min_health_gain + 3 * position.get_level();
Self { Self {
position, position,
health: 5, health: rand::thread_rng().gen_range(min_health_gain..=max_health_gain),
} }
} }
} }
@ -83,7 +86,7 @@ impl Artifact for Potion {
let new = player.get_life(); let new = player.get_life();
messages.insert( messages.insert(
0, 0,
format!("picked up potion and gained {} hp.", new - old).to_string(), format!("picked up potion and gained {} health.", new - old).to_string(),
); );
self.health = 0; self.health = 0;
} else { } else {

View File

@ -164,25 +164,32 @@ impl Game {
match m { match m {
None => {} None => {}
Some(m) => { Some(m) => {
// TODO fight the monster
let monster_dmg = m.damage() as i16;
let player_dmg = self.player.damage(); let player_dmg = self.player.damage();
self.player.change_life(-monster_dmg);
m.decrease_life(player_dmg); m.decrease_life(player_dmg);
// inform player
self.messages.insert(
0,
format!("{} hits you for {} damage.", m.get_name(), monster_dmg).to_string(),
);
self.messages.insert(
0,
format!("you hit {} for {} damage.", m.get_name(), player_dmg).to_string(),
);
// monster died, player gains experience
if m.is_dead() { if m.is_dead() {
self.player.gain_experience(m.get_experience_gain()); self.player.gain_experience(m.get_experience_gain());
self.messages.insert(
0,
format!(
"you hit {} for {} damage and kill it.",
m.get_name(),
player_dmg
)
.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);
self.messages.insert(
0,
format!("{} hits you for {} damage.", m.get_name(), monster_dmg)
.to_string(),
);
} }
return m.is_dead(); return m.is_dead();
} }

View File

@ -147,12 +147,8 @@ impl Level {
if player.get_immutable_position().get_x() == new_x if player.get_immutable_position().get_x() == new_x
&& player.get_immutable_position().get_y() == new_y && player.get_immutable_position().get_y() == new_y
{ {
// TODO handle fight between monster and player
let monster_dmg = self.monsters[index].damage() as i16; let monster_dmg = self.monsters[index].damage() as i16;
let player_dmg = player.damage();
self.monsters[index].decrease_life(player_dmg);
player.change_life(-monster_dmg); player.change_life(-monster_dmg);
messages.insert( messages.insert(
0, 0,
format!( format!(
@ -162,18 +158,32 @@ impl Level {
) )
.to_string(), .to_string(),
); );
messages.insert(
0, let player_dmg = player.damage();
format!( self.monsters[index].decrease_life(player_dmg);
"you hit {} for {} damage.",
self.monsters[index].get_name(),
player_dmg
)
.to_string(),
);
// if the attack did not kill the opponent, back down // if the attack did not kill the opponent, back down
if !player.is_dead() { if !player.is_dead() {
messages.insert(
0,
format!(
"you hit {} for {} damage and kill it.",
self.monsters[index].get_name(),
player_dmg
)
.to_string(),
);
self.monsters[index].get_position().change(-dx, -dy); self.monsters[index].get_position().change(-dx, -dy);
} else {
messages.insert(
0,
format!(
"you hit {} for {} damage.",
self.monsters[index].get_name(),
player_dmg
)
.to_string(),
);
} }
} }
break; break;

View File

@ -45,7 +45,7 @@ impl StatefulWidget for LevelWidget {
self.set_cell(buf, x, y, "Ω", Color::Black, Color::Gray); self.set_cell(buf, x, y, "Ω", Color::Black, Color::Gray);
} }
StructureElement::Wall => { StructureElement::Wall => {
// TODO add fancy walls // TODO add fancy walls with https://en.wikipedia.org/wiki/Box-drawing_characters
self.set_cell(buf, x, y, "#", FG_BROWN, Color::Gray); self.set_cell(buf, x, y, "#", FG_BROWN, Color::Gray);
} }
StructureElement::Floor => { StructureElement::Floor => {

View File

@ -108,7 +108,7 @@ fn main() -> Result<()> {
game.get_player().get_max_life(), game.get_player().get_max_life(),
game.get_player().get_experience(), game.get_player().get_experience(),
game.get_player().get_gold(), game.get_player().get_gold(),
game.get_player().get_immutable_position().get_level()+1 game.get_player().get_immutable_position().get_level() + 1
)) ))
.block(block) .block(block)
.wrap(Wrap { trim: true }), .wrap(Wrap { trim: true }),

View File

@ -8,7 +8,7 @@ pub trait HasPosition {
fn get_immutable_position(&self) -> &Position; fn get_immutable_position(&self) -> &Position;
} }
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug, Clone, Copy)]
pub struct Position { pub struct Position {
level: usize, level: usize,
x: usize, x: usize,