rain.adb 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- Rain --
  6. -- --
  7. -- B O D Y --
  8. -- --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. --
  11. -- --
  12. -- Permission is hereby granted, free of charge, to any person obtaining a --
  13. -- copy of this software and associated documentation files (the --
  14. -- "Software"), to deal in the Software without restriction, including --
  15. -- without limitation the rights to use, copy, modify, merge, publish, --
  16. -- distribute, distribute with modifications, sublicense, and/or sell --
  17. -- copies of the Software, and to permit persons to whom the Software is --
  18. -- furnished to do so, subject to the following conditions: --
  19. -- --
  20. -- The above copyright notice and this permission notice shall be included --
  21. -- in all copies or substantial portions of the Software. --
  22. -- --
  23. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
  24. -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
  25. -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
  26. -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
  27. -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
  28. -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
  29. -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
  30. -- --
  31. -- Except as contained in this notice, the name(s) of the above copyright --
  32. -- holders shall not be used in advertising or otherwise to promote the --
  33. -- sale, use or other dealings in this Software without prior written --
  34. -- authorization. --
  35. ------------------------------------------------------------------------------
  36. -- Author: Laurent Pautet <pautet@gnat.com>
  37. -- Modified by: Juergen Pfeifer, 1997
  38. -- Version Control
  39. -- $Revision: 1.8 $
  40. -- $Date: 2008/08/30 21:38:07 $
  41. -- Binding Version 01.00
  42. ------------------------------------------------------------------------------
  43. -- --
  44. with ncurses2.util; use ncurses2.util;
  45. with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
  46. with Status; use Status;
  47. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  48. procedure Rain is
  49. Visibility : Cursor_Visibility;
  50. subtype X_Position is Line_Position;
  51. subtype Y_Position is Column_Position;
  52. Xpos : array (1 .. 5) of X_Position;
  53. Ypos : array (1 .. 5) of Y_Position;
  54. done : Boolean;
  55. c : Key_Code;
  56. N : Integer;
  57. G : Generator;
  58. Max_X, X : X_Position;
  59. Max_Y, Y : Y_Position;
  60. procedure Next (J : in out Integer);
  61. procedure Cursor (X : X_Position; Y : Y_Position);
  62. procedure Next (J : in out Integer) is
  63. begin
  64. if J = 5 then
  65. J := 1;
  66. else
  67. J := J + 1;
  68. end if;
  69. end Next;
  70. procedure Cursor (X : X_Position; Y : Y_Position) is
  71. begin
  72. Move_Cursor (Line => X, Column => Y);
  73. end Cursor;
  74. pragma Inline (Cursor);
  75. begin
  76. Init_Screen;
  77. Set_NL_Mode;
  78. Set_Echo_Mode (False);
  79. Visibility := Invisible;
  80. Set_Cursor_Visibility (Visibility);
  81. Set_Timeout_Mode (Standard_Window, Non_Blocking, 0);
  82. Max_X := Lines - 5;
  83. Max_Y := Columns - 5;
  84. for I in Xpos'Range loop
  85. Xpos (I) := X_Position (Float (Max_X) * Random (G)) + 2;
  86. Ypos (I) := Y_Position (Float (Max_Y) * Random (G)) + 2;
  87. end loop;
  88. N := 1;
  89. done := False;
  90. while not done and Process.Continue loop
  91. X := X_Position (Float (Max_X) * Random (G)) + 2;
  92. Y := Y_Position (Float (Max_Y) * Random (G)) + 2;
  93. Cursor (X, Y);
  94. Add (Ch => '.');
  95. Cursor (Xpos (N), Ypos (N));
  96. Add (Ch => 'o');
  97. --
  98. Next (N);
  99. Cursor (Xpos (N), Ypos (N));
  100. Add (Ch => 'O');
  101. --
  102. Next (N);
  103. Cursor (Xpos (N) - 1, Ypos (N));
  104. Add (Ch => '-');
  105. Cursor (Xpos (N), Ypos (N) - 1);
  106. Add (Str => "|.|");
  107. Cursor (Xpos (N) + 1, Ypos (N));
  108. Add (Ch => '-');
  109. --
  110. Next (N);
  111. Cursor (Xpos (N) - 2, Ypos (N));
  112. Add (Ch => '-');
  113. Cursor (Xpos (N) - 1, Ypos (N) - 1);
  114. Add (Str => "/\\");
  115. Cursor (Xpos (N), Ypos (N) - 2);
  116. Add (Str => "| O |");
  117. Cursor (Xpos (N) + 1, Ypos (N) - 1);
  118. Add (Str => "\\/");
  119. Cursor (Xpos (N) + 2, Ypos (N));
  120. Add (Ch => '-');
  121. --
  122. Next (N);
  123. Cursor (Xpos (N) - 2, Ypos (N));
  124. Add (Ch => ' ');
  125. Cursor (Xpos (N) - 1, Ypos (N) - 1);
  126. Add (Str => " ");
  127. Cursor (Xpos (N), Ypos (N) - 2);
  128. Add (Str => " ");
  129. Cursor (Xpos (N) + 1, Ypos (N) - 1);
  130. Add (Str => " ");
  131. Cursor (Xpos (N) + 2, Ypos (N));
  132. Add (Ch => ' ');
  133. Xpos (N) := X;
  134. Ypos (N) := Y;
  135. c := Getchar;
  136. case c is
  137. when Character'Pos ('q') => done := True;
  138. when Character'Pos ('Q') => done := True;
  139. when Character'Pos ('s') => Set_NoDelay_Mode (Standard_Window, False);
  140. when Character'Pos (' ') => Set_NoDelay_Mode (Standard_Window, True);
  141. when others => null;
  142. end case;
  143. Nap_Milli_Seconds (50);
  144. end loop;
  145. Visibility := Normal;
  146. Set_Cursor_Visibility (Visibility);
  147. End_Windows;
  148. Curses_Free_All;
  149. end Rain;