summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 2100073a2312494eeb0b932ac3bd99339ad09ae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
mod game;
mod gui;
mod parser;

use crate::game::*;
use crate::gui::*;
use crate::parser::*;

fn main() {
    let screen = initscr();
    cbreak();
    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);

    if has_colours {
        start_color();
        use_default_colors();
        init_pair(black_colour as i16, -1, COLOR_RED);
        init_pair(white_colour as i16, -1, COLOR_BLUE);
        init_pair(red_colour as i16, COLOR_RED, -1);
    }

    screen.refresh();

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

    // 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);

    if let Err(e) = game.perform_action(action) {
        message_log.log_error(e);
    }

    board_gui.update(&game);
    game_log.update(&game);

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