Skip to content

Commit

Permalink
rough rough cli for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
evanofslack committed Dec 27, 2024
1 parent d3f02bf commit 5893427
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[workspace]

members = ["core", "pylatro"]
members = ["core", "pylatro", "cli"]

307 changes: 307 additions & 0 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "balatro-cli"
version = "0.0.1"
edition = "2021"
description = "Balatro on the command line (basic)"
license = "MIT"
repository ="https://github.com/evanofslack/balatro-rs"

[dependencies]
text_io = "0.1.9"
balatro-rs = {path = "../core/", version = "0.0.1"}
43 changes: 43 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use balatro_rs::action::Action;
use balatro_rs::game::Game;
use text_io::read;

fn input_loop(max: usize) -> usize {
loop {
let i: usize = read!();
if i <= max {
return i;
} else {
println!("Input must be between 0 and {}", max)
}
}
}

fn game_loop(game: &mut Game) {
loop {
if game.is_over() {
return;
}
let actions: Vec<Action> = game.gen_actions().collect();
println!("Select action:");
println!("[0] Show game state");
for (i, action) in actions.clone().iter().enumerate() {
println!("[{}] {:}", i + 1, action);
}
let index = input_loop(actions.len());
if index == 0 {
println!("\n{}", game);
continue;
}
let action = actions[index - 1].clone();
game.handle_action(action).expect("handle action");
}
}

fn main() {
let mut game = Game::default();
game.start();
println!("Starting game...");
game_loop(&mut game);
println!("Game over!");
}

0 comments on commit 5893427

Please sign in to comment.