aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs62
1 files changed, 50 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index c7281cf..2100073 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,6 +12,9 @@ fn main() {
noecho();
curs_set(2);
+ let width = screen.get_max_x();
+ let height = screen.get_max_y();
+
let has_colours = has_colors();
let (black_colour, white_colour, red_colour): (u8, u8, u8) = (1, 2, 3);
@@ -25,31 +28,66 @@ fn main() {
screen.refresh();
- let mut board_gui = BoardGUI::new(0, 0, 5, 4, 8, 3, has_colours, white_colour, black_colour);
- let game_log = GameLog::new(0, 5 * 8 + 3 + 3, 100, 20);
- let message_log = MessageLog::new(26, 0, 3, 70, has_colours, red_colour);
- let action_entry = ActionEntry::new(25, 0, 10);
+ let size = 5;
+ let cell_height = 4;
+ let cell_width = 8;
+ let hoff = 3;
+
+ let board_bottom = (size * cell_height + 3) as i32;
+ let board_right = (size * cell_width + hoff + 3) as i32;
+
+ let mut board_gui = BoardGUI::new(
+ 0,
+ 0,
+ size,
+ cell_height,
+ cell_width,
+ hoff,
+ has_colours,
+ white_colour,
+ black_colour,
+ );
+
+ let game_log = GameLog::new(0, board_right, height, 20);
- let log = |s| message_log.log_error(s);
- let mut game = Game::new(5, "tslil", "taktician", log);
+ // Need room for '8___011111111', for example
+ let action_entry = ActionEntry::new(board_bottom, 0, 13);
+
+ let message_log = MessageLog::new(
+ board_bottom + 1,
+ 0,
+ height - board_bottom - 1,
+ width,
+ has_colours,
+ red_colour,
+ );
+
+ let (mut game, warning) = Game::new(5, "tslil", "taktician");
+ message_log.log_error(warning);
let pos = Position { x: 0, y: 0 };
let action = Action::Place(Player::White, pos, Stone::Flat);
- game.perform_action(action);
+ if let Err(e) = game.perform_action(action) {
+ message_log.log_error(e);
+ }
board_gui.update(&game);
game_log.update(&game);
- match parse_action(game.query_current_player(), &action_entry.read_action()) {
- Ok(act) => log(format!("{}", act)),
- Err(err) => log(err),
+ loop {
+ let inp = action_entry.read_action();
+ match parse_action(game.query_current_player(), &inp) {
+ Ok(act) => message_log.log_error(format!("{}", act)),
+ Err(err) => message_log.log_error(format!("Input \"{}\": {}", inp, err)),
+ }
+ action_entry.clear_entry_area();
}
// game_state.perform_action(&action);
// game_state.is_legal_action(&Action::Move(Player::White, pos, Direction::Up, vec![0, 1]));
// bg.draw_game_state(&game_state);
- board_gui.read_action();
- endwin();
+ // board_gui.read_action();
+ // endwin();
}