Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Printf
- open Unix
- open Board
- open State
- module A = ANSITerminal
- let rec blank_spacer spaces acc = begin
- if spaces = 0 then acc else blank_spacer (spaces - 1) (" "^acc)
- end
- (* let rec auto_center string =
- let x, y = A.size() in
- let difference = (let vale = (x - (String.length string)) in
- if vale mod 2 != 0 then (vale - 1) else (vale)) in
- (blank_spacer (difference/2) "")^string *)
- let rec auto_center string = begin
- let x, y = A.size() in
- let difference = (x - (String.length string)) in
- (blank_spacer (difference/2) "")^string
- end
- let rec newline number acc = begin
- if number = 0 then acc else newline (number - 1) ("\n")^acc
- end
- let rec color_check col = begin
- match col with
- | Red -> [A.Background A.Red; A.Foreground A.White;]
- | Blue -> [A.Background A.Blue; A.Foreground A.White;]
- end
- (* let check_state c s = begin
- if s = Hidden then A.print_string (color_check c) ("|███|"); 1 else A.print_s *)
- (** Goes through a list of list of strings (lst) for one side of the board
- and prints out the pieces. My plan will be to use something like this to
- print out the entire board including different colors depending on the
- piece type once we gain some progress into basic functionality*)
- let rec board_machine_9000 lst= begin
- printf (" ");
- match lst with
- | a::t -> begin
- let rec lst_reader item =
- match item with
- | [] -> printf "\n";
- | h::t -> begin
- let simplify drawing c s =
- if s = Hidden then A.print_string (color_check c) ("|███|") else A.print_string (color_check c) ("| "^drawing^" |"); lst_reader t;
- in
- match h with
- | One (c,s) -> simplify "1" c s;
- | Two (c,s) -> simplify "2" c s;
- | Three (c,s) -> simplify "3" c s;
- | Four (c,s) -> simplify "4" c s;
- | Five (c,s) -> simplify "5" c s;
- | Six (c,s) -> simplify "6" c s;
- | Seven (c,s) -> simplify "7" c s;
- | Eight (c,s) -> simplify "8" c s;
- | Nine (c,s) -> simplify "9" c s;
- | Ten (c,s) -> simplify "G" c s;
- | Bomb (c,s) -> simplify "B" c s;
- | Flag (c,s) -> simplify "F" c s;
- | River -> A.print_string [A.Background A.Cyan; A.Foreground A.Black;] ("| "^" "^" |"); lst_reader t;
- | Empty -> A.print_string [A.Background A.Black; A.Foreground A.Black;] ("| "^" "^" |"); lst_reader t;
- | LeftArrow -> A.print_string [A.Background A.Black; A.Foreground A.Green;] ("| "^"<"^" |"); lst_reader t;
- | RightArrow -> A.print_string [A.Background A.Black; A.Foreground A.Green;] ("| "^">"^" |"); lst_reader t;
- | UpArrow -> A.print_string [A.Background A.Black; A.Foreground A.Green;] ("| "^"^"^" |"); lst_reader t;
- | DownArrow -> A.print_string [A.Background A.Black; A.Foreground A.Green;] ("| "^"v"^" |"); lst_reader t;
- | Explosion -> A.print_string [A.Background A.Black; A.Foreground A.Red;] ("| "^"*"^" |"); lst_reader t;
- end in lst_reader a; A.print_string [A.Background A.Black; A.Foreground A.White] (auto_center "+------------------------------------------------+"); printf "\n"; board_machine_9000 t end
- | _ -> printf "" end
- let rec blueScreen state = begin
- A.erase A.Screen;
- A.print_string [A.Bold; A.Background A.Blue; A.Foreground A.White;] ((newline 14 "")^(auto_center "BLUE PLAYER TURN\n"));
- A.print_string [A.Background A.Blue; A.Foreground A.Black;] (auto_center "Please Pass Device to the Blue Player\n");
- A.print_string [A.Background A.Blue; A.Foreground A.Black;] ((auto_center "Press ENTER when Ready\n")^(newline 13 ""));
- ignore(read_line());
- A.erase A.Screen;
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.Red;] (auto_center " StrategOcaml \n");
- A.print_string [A.Background A.Black; A.Foreground A.White] (auto_center "+------------------------------------------------+");
- printf "\n";
- board_machine_9000 ((State.get_blue_state state) |> Board.expose);
- end
- let rec redScreen state = begin
- A.erase A.Screen;
- A.print_string [A.Bold; A.Background A.Red; A.Foreground A.White;] ((newline 14 "")^(auto_center "RED PLAYER TURN\n"));
- A.print_string [A.Background A.Red; A.Foreground A.Black;] (auto_center "Please Pass Device to the Blue Player\n");
- A.print_string [A.Background A.Red; A.Foreground A.Black;] ((auto_center "Press ENTER when Ready\n")^(newline 13 ""));
- ignore(read_line());
- A.erase A.Screen;
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.Red;] (auto_center " StrategOcaml \n");
- A.print_string [A.Background A.Black; A.Foreground A.White] (auto_center "+------------------------------------------------+");
- printf "\n";
- board_machine_9000 ((State.get_red_state state) |> Board.expose);
- end
- let rec parse_piece state =
- print_endline "\n \n Select the piece you would like to move: \n";
- print_string "> ";
- match read_line() with
- | user_response -> begin
- try Command.parse user_response with
- | Command.Invalid -> print_endline "Error in command."; parse_piece state
- end
- let rec parse_movement state =
- print_endline "\n \n Where would you like to move to: \n";
- print_string "> ";
- match read_line() with
- | user_response -> begin
- try Command.parse user_response with
- | Command.Invalid -> print_endline "Error in command."; parse_piece state;
- end
- let rec game_logic state = begin
- (if ((State.get_turns state) mod 2) = 0 then redScreen state else blueScreen state);
- let pieceSelect = (parse_piece state) in
- let movementSelect = (parse_movement state) in
- let newState =
- match pieceSelect with
- | Command.Select pos -> begin
- match movementSelect with
- | Command.Select pos2 -> begin try (State.move pos pos2 state) with
- | MoveDiagonal -> print_endline "Error - MoveDiagonal."; state;
- | MoveMTO -> print_endline "Error - MoveMTO."; state;
- | MoveRiver -> print_endline "Error - MoveRiver."; state;
- | MoveSelf -> print_endline "Error - MoveSelf."; state;
- | MovePast -> print_endline "Error - MovePast."; state;
- | _ -> print_endline "Error - Has no color"; state; end
- | Command.Surrender -> state;
- | _ -> state; end
- | Command.Surrender -> state;
- | _ -> state;
- in game_logic newState; end
- let initialization () = begin
- A.erase A.Screen;
- A.resize 104 30;
- A.erase A.Screen;
- A.print_string [A.Bold; A.Background A.White; A.Foreground A.Black;] ((newline 16 "")^(auto_center "Press ENTER to do a coin toss to see which side goes first!\n")^(newline 14 ""));
- ignore(read_line());
- Random.self_init ();
- let init = State.init_state (from_json_red (Yojson.Basic.from_file "b1.json") (Yojson.Basic.from_file "b2.json")) (from_json_blue (Yojson.Basic.from_file "b1.json") (Yojson.Basic.from_file "b2.json"))
- in
- (* if (Random.int 2) = 1 then blueScreen init else redScreen init; *)
- game_logic init;
- end
- let introduction () = begin
- A.erase A.Screen;
- A.resize 104 30;
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.Red;] ((newline 6 "")^" ███████╗████████╗██████╗ █████╗ ████████╗███████╗ ██████╗ ██████╗ ██████╗ █████╗ ███╗ ███╗██╗ \n");
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.Red;] " ██╔════╝╚══██╔══╝██╔══██╗██╔══██╗╚══██╔══╝██╔════╝██╔════╝ ██╔═══██╗██╔════╝██╔══██╗████╗ ████║██║ \n ";
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.Red;] "███████╗ ██║ ██████╔╝███████║ ██║ █████╗ ██║ ███╗██║ ██║██║ ███████║██╔████╔██║██║ \n ";
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.Red;] "╚════██║ ██║ ██╔══██╗██╔══██║ ██║ ██╔══╝ ██║ ██║██║ ██║██║ ██╔══██║██║╚██╔╝██║██║ \n ";
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.Red;] "███████║ ██║ ██║ ██║██║ ██║ ██║ ███████╗╚██████╔╝╚██████╔╝╚██████╗██║ ██║██║ ╚═╝ ██║███████╗\n ";
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.Red;] ("╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝"^newline 10 "");
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.White; A.Blink;] (auto_center "____ ___ _ _ _____ ___ ___ _ ___ _ \n");
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.White; A.Blink;] (auto_center "| _ \_ _ ___ ______ | __| \| |_ _| __| _ ) | |_ ___ | _ )___ __ _(_)_ _ \n");
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.White; A.Blink;] (auto_center "| _| '_/ -_(_-(_-< | _|| .` | | | | _|| / | _/ _ | _ / -_/ _` | | ' | \n");
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.White; A.Blink;] (auto_center "|_| |_| \___/__/__/ |___|_|\_| |_| |___|_|_) \__\___/ |___\___\__, |_|_||_| \n");
- A.print_string [A.Bold; A.Background A.Black; A.Foreground A.White; A.Blink;] ((auto_center " |___/ \n")^newline 5 "");
- ignore(read_line());
- initialization();
- end
- let () =
- introduction ();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement