1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
9 ------------------------------------------------------------------------------
10 -- Copyright 2020 Thomas E. Dickey --
11 -- Copyright 1998-2007,2008 Free Software Foundation, Inc. --
13 -- Permission is hereby granted, free of charge, to any person obtaining a --
14 -- copy of this software and associated documentation files (the --
15 -- "Software"), to deal in the Software without restriction, including --
16 -- without limitation the rights to use, copy, modify, merge, publish, --
17 -- distribute, distribute with modifications, sublicense, and/or sell --
18 -- copies of the Software, and to permit persons to whom the Software is --
19 -- furnished to do so, subject to the following conditions: --
21 -- The above copyright notice and this permission notice shall be included --
22 -- in all copies or substantial portions of the Software. --
24 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
25 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
26 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
27 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
28 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
29 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
30 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
32 -- Except as contained in this notice, the name(s) of the above copyright --
33 -- holders shall not be used in advertising or otherwise to promote the --
34 -- sale, use or other dealings in this Software without prior written --
36 ------------------------------------------------------------------------------
37 -- Author: Laurent Pautet <pautet@gnat.com>
38 -- Modified by: Juergen Pfeifer, 1997
41 -- $Date: 2020/02/02 23:34:34 $
42 -- Binding Version 01.00
43 ------------------------------------------------------------------------------
45 with ncurses2.util; use ncurses2.util;
46 with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
47 with Status; use Status;
48 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
52 Visibility : Cursor_Visibility;
54 subtype X_Position is Line_Position;
55 subtype Y_Position is Column_Position;
57 Xpos : array (1 .. 5) of X_Position;
58 Ypos : array (1 .. 5) of Y_Position;
68 Max_X, X : X_Position;
69 Max_Y, Y : Y_Position;
71 procedure Next (J : in out Integer);
72 procedure Cursor (X : X_Position; Y : Y_Position);
74 procedure Next (J : in out Integer) is
83 procedure Cursor (X : X_Position; Y : Y_Position) is
85 Move_Cursor (Line => X, Column => Y);
87 pragma Inline (Cursor);
93 Set_Echo_Mode (False);
95 Visibility := Invisible;
96 Set_Cursor_Visibility (Visibility);
97 Set_Timeout_Mode (Standard_Window, Non_Blocking, 0);
100 Max_Y := Columns - 5;
102 for I in Xpos'Range loop
103 Xpos (I) := X_Position (Float (Max_X) * Random (G)) + 2;
104 Ypos (I) := Y_Position (Float (Max_Y) * Random (G)) + 2;
109 while not done and Process.Continue loop
111 X := X_Position (Float (Max_X) * Random (G)) + 2;
112 Y := Y_Position (Float (Max_Y) * Random (G)) + 2;
117 Cursor (Xpos (N), Ypos (N));
122 Cursor (Xpos (N), Ypos (N));
127 Cursor (Xpos (N) - 1, Ypos (N));
129 Cursor (Xpos (N), Ypos (N) - 1);
131 Cursor (Xpos (N) + 1, Ypos (N));
136 Cursor (Xpos (N) - 2, Ypos (N));
138 Cursor (Xpos (N) - 1, Ypos (N) - 1);
140 Cursor (Xpos (N), Ypos (N) - 2);
141 Add (Str => "| O |");
142 Cursor (Xpos (N) + 1, Ypos (N) - 1);
144 Cursor (Xpos (N) + 2, Ypos (N));
149 Cursor (Xpos (N) - 2, Ypos (N));
151 Cursor (Xpos (N) - 1, Ypos (N) - 1);
153 Cursor (Xpos (N), Ypos (N) - 2);
155 Cursor (Xpos (N) + 1, Ypos (N) - 1);
157 Cursor (Xpos (N) + 2, Ypos (N));
165 when Character'Pos ('q') => done := True;
166 when Character'Pos ('Q') => done := True;
167 when Character'Pos ('s') => Set_NoDelay_Mode (Standard_Window, False);
168 when Character'Pos (' ') => Set_NoDelay_Mode (Standard_Window, True);
172 Nap_Milli_Seconds (50);
175 Visibility := Normal;
176 Set_Cursor_Visibility (Visibility);