More functions in Ada version...

This commit is contained in:
Ognjen Milan Robovic 2024-06-17 07:41:05 -04:00
parent 7a91d322cf
commit 87ff5a032b
2 changed files with 94 additions and 12 deletions

View File

@ -3,6 +3,8 @@ use ada.text_io;
procedure xerbia is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type resource_type is (
wheat, gold, wood, stone
);
@ -16,15 +18,16 @@ procedure xerbia is
turn
);
grey : constant string := ascii.esc & "[1;30m";
red : constant string := ascii.esc & "[1;31m";
green : constant string := ascii.esc & "[1;32m";
yellow : constant string := ascii.esc & "[1;33m";
blue : constant string := ascii.esc & "[1;34m";
pink : constant string := ascii.esc & "[1;35m";
cyan : constant string := ascii.esc & "[1;36m";
white : constant string := ascii.esc & "[1;37m";
cancel : constant string := ascii.esc & "[0m";
------------------------------------------------------------------------------------------
function grey (text : in string) return string is begin return ascii.esc & "[1;30m" & text & ascii.esc & "[0m"; end grey;
function red (text : in string) return string is begin return ascii.esc & "[1;31m" & text & ascii.esc & "[0m"; end red;
function green (text : in string) return string is begin return ascii.esc & "[1;32m" & text & ascii.esc & "[0m"; end green;
function yellow (text : in string) return string is begin return ascii.esc & "[1;33m" & text & ascii.esc & "[0m"; end yellow;
function blue (text : in string) return string is begin return ascii.esc & "[1;34m" & text & ascii.esc & "[0m"; end blue;
function pink (text : in string) return string is begin return ascii.esc & "[1;35m" & text & ascii.esc & "[0m"; end pink;
function cyan (text : in string) return string is begin return ascii.esc & "[1;36m" & text & ascii.esc & "[0m"; end cyan;
function white (text : in string) return string is begin return ascii.esc & "[1;37m" & text & ascii.esc & "[0m"; end white;
population : natural := 0;
reputation : integer := 0;
@ -45,22 +48,101 @@ procedure xerbia is
new string'("Submit your monthly strategy to the council and wait until next month.")
);
construction_price : array (construction_type, resource_type) of natural := (
construction_price : constant array (construction_type, resource_type) of natural := (
(0, 10, 60, 30),
(0, 120, 60, 10),
(0, 30, 10, 60),
(0, 60, 30, 10)
);
------------------------------------------------------------------------------------------
procedure separator is
begin
put_line (grey & "------------------------------------------------------------------------------------------" & cancel);
put_line (grey ("------------------------------------------------------------------------------------------"));
end separator;
------------------------------------------------------------------------------------------
function query_reply return reply_type is
input : string (1 .. 1024);
begin
loop input := get_line;
--
for index in reply_type loop
if input <= reply_type'image (index) then
return (index);
end if;
end loop;
--
put_line ("Incorrect " & red ("reply") & ", type '" & blue ("help") & "' to list replies or look at message above.");
--
end loop;
end query_reply;
------------------------------------------------------------------------------------------
function query_construction return construction_type is
input : string (1 .. 1024);
begin
loop input := get_line;
--
for index in construction_type loop
if input = construction_type'image (index) then
return (index);
end if;
end loop;
--
put_line ("Incorrect " & red ("construction") & ", type '" & blue ("help") & "' to list replies or look at message above.");
--
end loop;
end query_construction;
------------------------------------------------------------------------------------------
procedure print_help is
begin
for index in reply_type loop
put_line (blue (reply_type'image (index)) & grey (" <> ") & reply_text (index).all);
end loop;
--
separator;
end print_help;
------------------------------------------------------------------------------------------
procedure print_resources is
begin
for index in resource_type loop
case resource (index) is
when 0 => put_line ("You don't have any " & red (resource_type'image (index)) & ".");
when 1 => put_line ("You have " & blue ("1") & " unit of " & blue (resource_type'image (index)) & ".");
when others => put_line ("You have" & blue (resource (index)'image) & " unit of " & blue (resource_type'image (index)) & ".");
end case;
end loop;
--
separator;
end print_resources;
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin
separator;
separator;
separator;
print_help;
print_resources;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end xerbia;

View File

@ -49,7 +49,7 @@ static void separate (void) {
static int query (char * names [], int count) {
char input [1024] = "";
int index = reply_help;
int index = 0;
requery: for (index = 0; index < 1024; ++index) {
in (& input [index], 1);