More functions in Ada version...
This commit is contained in:
parent
7a91d322cf
commit
87ff5a032b
104
xerbia.adb
104
xerbia.adb
@ -3,6 +3,8 @@ use ada.text_io;
|
|||||||
|
|
||||||
procedure xerbia is
|
procedure xerbia is
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
type resource_type is (
|
type resource_type is (
|
||||||
wheat, gold, wood, stone
|
wheat, gold, wood, stone
|
||||||
);
|
);
|
||||||
@ -16,15 +18,16 @@ procedure xerbia is
|
|||||||
turn
|
turn
|
||||||
);
|
);
|
||||||
|
|
||||||
grey : constant string := ascii.esc & "[1;30m";
|
------------------------------------------------------------------------------------------
|
||||||
red : constant string := ascii.esc & "[1;31m";
|
|
||||||
green : constant string := ascii.esc & "[1;32m";
|
function grey (text : in string) return string is begin return ascii.esc & "[1;30m" & text & ascii.esc & "[0m"; end grey;
|
||||||
yellow : constant string := ascii.esc & "[1;33m";
|
function red (text : in string) return string is begin return ascii.esc & "[1;31m" & text & ascii.esc & "[0m"; end red;
|
||||||
blue : constant string := ascii.esc & "[1;34m";
|
function green (text : in string) return string is begin return ascii.esc & "[1;32m" & text & ascii.esc & "[0m"; end green;
|
||||||
pink : constant string := ascii.esc & "[1;35m";
|
function yellow (text : in string) return string is begin return ascii.esc & "[1;33m" & text & ascii.esc & "[0m"; end yellow;
|
||||||
cyan : constant string := ascii.esc & "[1;36m";
|
function blue (text : in string) return string is begin return ascii.esc & "[1;34m" & text & ascii.esc & "[0m"; end blue;
|
||||||
white : constant string := ascii.esc & "[1;37m";
|
function pink (text : in string) return string is begin return ascii.esc & "[1;35m" & text & ascii.esc & "[0m"; end pink;
|
||||||
cancel : constant string := ascii.esc & "[0m";
|
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;
|
population : natural := 0;
|
||||||
reputation : integer := 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.")
|
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, 10, 60, 30),
|
||||||
(0, 120, 60, 10),
|
(0, 120, 60, 10),
|
||||||
(0, 30, 10, 60),
|
(0, 30, 10, 60),
|
||||||
(0, 60, 30, 10)
|
(0, 60, 30, 10)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
procedure separator is
|
procedure separator is
|
||||||
begin
|
begin
|
||||||
put_line (grey & "------------------------------------------------------------------------------------------" & cancel);
|
put_line (grey ("------------------------------------------------------------------------------------------"));
|
||||||
end separator;
|
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
|
begin
|
||||||
|
|
||||||
separator;
|
separator;
|
||||||
separator;
|
separator;
|
||||||
separator;
|
separator;
|
||||||
|
|
||||||
|
print_help;
|
||||||
|
print_resources;
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
end xerbia;
|
end xerbia;
|
||||||
|
2
xerbia.c
2
xerbia.c
@ -49,7 +49,7 @@ static void separate (void) {
|
|||||||
|
|
||||||
static int query (char * names [], int count) {
|
static int query (char * names [], int count) {
|
||||||
char input [1024] = "";
|
char input [1024] = "";
|
||||||
int index = reply_help;
|
int index = 0;
|
||||||
|
|
||||||
requery: for (index = 0; index < 1024; ++index) {
|
requery: for (index = 0; index < 1024; ++index) {
|
||||||
in (& input [index], 1);
|
in (& input [index], 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user