Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | ------------------------------------------------------------------------------ |
| 2 | -- -- |
| 3 | -- GNAT ncurses Binding Samples -- |
| 4 | -- -- |
| 5 | -- Rain -- |
| 6 | -- -- |
| 7 | -- B O D Y -- |
| 8 | -- -- |
| 9 | ------------------------------------------------------------------------------ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 10 | -- Copyright 2020 Thomas E. Dickey -- |
| 11 | -- Copyright 1998-2007,2008 Free Software Foundation, Inc. -- |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 12 | -- -- |
| 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: -- |
| 20 | -- -- |
| 21 | -- The above copyright notice and this permission notice shall be included -- |
| 22 | -- in all copies or substantial portions of the Software. -- |
| 23 | -- -- |
| 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. -- |
| 31 | -- -- |
| 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 -- |
| 35 | -- authorization. -- |
| 36 | ------------------------------------------------------------------------------ |
| 37 | -- Author: Laurent Pautet <pautet@gnat.com> |
| 38 | -- Modified by: Juergen Pfeifer, 1997 |
| 39 | -- Version Control |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 40 | -- $Revision: 1.9 $ |
| 41 | -- $Date: 2020/02/02 23:34:34 $ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 42 | -- Binding Version 01.00 |
| 43 | ------------------------------------------------------------------------------ |
| 44 | -- -- |
| 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; |
| 49 | |
| 50 | procedure Rain is |
| 51 | |
| 52 | Visibility : Cursor_Visibility; |
| 53 | |
| 54 | subtype X_Position is Line_Position; |
| 55 | subtype Y_Position is Column_Position; |
| 56 | |
| 57 | Xpos : array (1 .. 5) of X_Position; |
| 58 | Ypos : array (1 .. 5) of Y_Position; |
| 59 | |
| 60 | done : Boolean; |
| 61 | |
| 62 | c : Key_Code; |
| 63 | |
| 64 | N : Integer; |
| 65 | |
| 66 | G : Generator; |
| 67 | |
| 68 | Max_X, X : X_Position; |
| 69 | Max_Y, Y : Y_Position; |
| 70 | |
| 71 | procedure Next (J : in out Integer); |
| 72 | procedure Cursor (X : X_Position; Y : Y_Position); |
| 73 | |
| 74 | procedure Next (J : in out Integer) is |
| 75 | begin |
| 76 | if J = 5 then |
| 77 | J := 1; |
| 78 | else |
| 79 | J := J + 1; |
| 80 | end if; |
| 81 | end Next; |
| 82 | |
| 83 | procedure Cursor (X : X_Position; Y : Y_Position) is |
| 84 | begin |
| 85 | Move_Cursor (Line => X, Column => Y); |
| 86 | end Cursor; |
| 87 | pragma Inline (Cursor); |
| 88 | |
| 89 | begin |
| 90 | |
| 91 | Init_Screen; |
| 92 | Set_NL_Mode; |
| 93 | Set_Echo_Mode (False); |
| 94 | |
| 95 | Visibility := Invisible; |
| 96 | Set_Cursor_Visibility (Visibility); |
| 97 | Set_Timeout_Mode (Standard_Window, Non_Blocking, 0); |
| 98 | |
| 99 | Max_X := Lines - 5; |
| 100 | Max_Y := Columns - 5; |
| 101 | |
| 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; |
| 105 | end loop; |
| 106 | |
| 107 | N := 1; |
| 108 | done := False; |
| 109 | while not done and Process.Continue loop |
| 110 | |
| 111 | X := X_Position (Float (Max_X) * Random (G)) + 2; |
| 112 | Y := Y_Position (Float (Max_Y) * Random (G)) + 2; |
| 113 | |
| 114 | Cursor (X, Y); |
| 115 | Add (Ch => '.'); |
| 116 | |
| 117 | Cursor (Xpos (N), Ypos (N)); |
| 118 | Add (Ch => 'o'); |
| 119 | |
| 120 | -- |
| 121 | Next (N); |
| 122 | Cursor (Xpos (N), Ypos (N)); |
| 123 | Add (Ch => 'O'); |
| 124 | |
| 125 | -- |
| 126 | Next (N); |
| 127 | Cursor (Xpos (N) - 1, Ypos (N)); |
| 128 | Add (Ch => '-'); |
| 129 | Cursor (Xpos (N), Ypos (N) - 1); |
| 130 | Add (Str => "|.|"); |
| 131 | Cursor (Xpos (N) + 1, Ypos (N)); |
| 132 | Add (Ch => '-'); |
| 133 | |
| 134 | -- |
| 135 | Next (N); |
| 136 | Cursor (Xpos (N) - 2, Ypos (N)); |
| 137 | Add (Ch => '-'); |
| 138 | Cursor (Xpos (N) - 1, Ypos (N) - 1); |
| 139 | Add (Str => "/\\"); |
| 140 | Cursor (Xpos (N), Ypos (N) - 2); |
| 141 | Add (Str => "| O |"); |
| 142 | Cursor (Xpos (N) + 1, Ypos (N) - 1); |
| 143 | Add (Str => "\\/"); |
| 144 | Cursor (Xpos (N) + 2, Ypos (N)); |
| 145 | Add (Ch => '-'); |
| 146 | |
| 147 | -- |
| 148 | Next (N); |
| 149 | Cursor (Xpos (N) - 2, Ypos (N)); |
| 150 | Add (Ch => ' '); |
| 151 | Cursor (Xpos (N) - 1, Ypos (N) - 1); |
| 152 | Add (Str => " "); |
| 153 | Cursor (Xpos (N), Ypos (N) - 2); |
| 154 | Add (Str => " "); |
| 155 | Cursor (Xpos (N) + 1, Ypos (N) - 1); |
| 156 | Add (Str => " "); |
| 157 | Cursor (Xpos (N) + 2, Ypos (N)); |
| 158 | Add (Ch => ' '); |
| 159 | |
| 160 | Xpos (N) := X; |
| 161 | Ypos (N) := Y; |
| 162 | |
| 163 | c := Getchar; |
| 164 | case c is |
| 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); |
| 169 | when others => null; |
| 170 | end case; |
| 171 | |
| 172 | Nap_Milli_Seconds (50); |
| 173 | end loop; |
| 174 | |
| 175 | Visibility := Normal; |
| 176 | Set_Cursor_Visibility (Visibility); |
| 177 | End_Windows; |
| 178 | Curses_Free_All; |
| 179 | |
| 180 | end Rain; |