Ошибка при переносе из pascal в c#

Узнай цену своей работы

Формулировка задачи:

Здравствуйте,просматривая стандартные програмки на паскаль обнаружил интересную прогр. о моделировании поведения рыб(),я решил портировать эту програмку на c# с помощью библиотеки smallbasic. Код я переписал но программа не работает(.Под скажите в чем проблема пж. Код на PascalAbc.Net
Листинг программы
  1. uses GraphABC;
  2. const types = 3; //число типов рыб минус 1
  3. rmax = 4; //радиус всех рыб
  4. CanEat = rmax; //максимальное расстояние при поедании
  5. eps = 0.00001; //необходимо при операциях с данными real
  6. epsustupi = 0.1; //насколько значима иерархия среди хищников
  7. strahkraj = 3; //во сколько раз жертвы боятся края меньше, чем хищников
  8. ustupi = CanEat*10; //насколько значима иерархия среди хищников
  9. BkColor = clBlack; //Фон
  10. Height = 600; //Высота графического окна
  11. Width = 780; //Ширина графического окна
  12. xmin = 10; //
  13. ymin = 10; //Минимальные и максимальные значения координат,
  14. xmax = Width - 100; //которые могут принимать рыбы
  15. ymax = Height - 140; //
  16. Type
  17. fishtype = class //Описание одной стаи
  18. c : color;
  19. public
  20. CanRazm, MaxKol, Kol, MaxLife, MinFood: integer;
  21. //цвет, размножение, макс. кол-во, текущее кол-во, макс. жизнь,
  22. //сколько хищнику нужно есть для размножения
  23. Speed, See: real; //Нормальная скорость и зрение в пикселях
  24. constructor create(ac:color; aCanRazm, aMaxKol, aMaxLife, aMinFood:integer; aSpeed, aSee: real);
  25. begin
  26. c:= ac; CanRazm:= aCanRazm; MaxKol:= aMaxKol; Kol:= 1;
  27. MaxLife:= aMaxLife; MinFood:= aMinFood; Speed:= aSpeed; See:= aSee
  28. end;
  29. procedure ShowKol(y: integer); //отобразить текущее кол-во
  30. var s: string;
  31. begin
  32. SetFontColor(c);
  33. TextOut(xmax + 20, y, ' ');
  34. s := IntToStr(kol);
  35. TextOut(xmax + 20, y, s);
  36. end;
  37. end;
  38. var opisanie: array[0..types] of fishtype; //данные для всех стай
  39. Type
  40. fish = class
  41. x, y, r, dx0, dy0: real; //текущие координаты, радиус и предыдущий шаг
  42. tip, life, razm, status, food: integer;
  43. //razm - время с момента последнего размножения,
  44. //status - состояние - спокойное или возбуждённое
  45. next, prev: fish; //двусвязный циклический список
  46. constructor Create(ax, ay, ar: real; atip: integer; aprev, anext: fish);
  47. begin
  48. x:= ax; y:= ay; r:= ar; tip:= atip; prev:= aprev; next:= anext;
  49. life:= 0; razm:= 0; dx0:= random; dy0:= random; status:= 1; food:= 0;
  50. end;
  51. procedure show;
  52. begin
  53. SetPenColor(opisanie[tip].c);
  54. circle(round(x), round(y), round(r))
  55. end;
  56. procedure hide;
  57. begin
  58. SetPenColor(BkColor);
  59. circle(round(x), round(y), round(r))
  60. end;
  61. procedure Destroy;
  62. begin
  63. hide;
  64. opisanie[tip].kol:= opisanie[tip].kol - 1;
  65. opisanie[tip].ShowKol(tip*40 + 20);
  66. end;
  67. procedure moveto(dx, dy: real);
  68. begin
  69. hide;
  70. x:= x + dx; y:= y + dy;
  71. if x > xmax then x:= xmax;
  72. if x < xmin then x:= xmin;
  73. if y > ymax then y:= ymax;
  74. if y < ymin then y:= ymin;
  75. show
  76. end;
  77. procedure MakeDeti(var mama, StartAkula, KonAkula, StartKilka, KonKilka : fish);
  78. //произвести потомство
  79. var d: fish;
  80. begin
  81. razm:= 0;
  82. food:= 0;
  83. d:= fish.create(x, y, r, tip, mama, next);
  84. next.prev:= d;
  85. next:= d;
  86. if mama = KonAkula then KonAkula:= d;
  87. if mama = KonKilka then KonKilka:= d;
  88. opisanie[tip].kol:= opisanie[tip].kol + 1;
  89. opisanie[tip].ShowKol(tip*40 + 20);
  90. end;
  91. procedure step(var ribka, StartAkula, KonAkula, StartKilka, KonKilka : fish);
  92. //Здесь алгоритмы для рыб
  93. var
  94. dx, dy, d, dx2, dy2, dmin: real;
  95. t, trup, found: fish;
  96. FoundOhot: boolean;
  97. begin
  98. status:= 1; //Нормальное состояние
  99. dx:= 0; dy:= 0;
  100. if tip > 0 then
  101. begin //Начало алгоритма для жертв
  102. t:= StartAkula;
  103. if t<>nil then
  104. repeat //Ищем всех хищников в поле видимости
  105. d:= sqrt((x - t.x)*(x - t.x) + (y - t.y)*(y - t.y));
  106. if d < opisanie[tip].See then
  107. begin
  108. if d < eps then d:= eps;
  109. dx2:= (x - t.x)/(d*d);
  110. dy2:= (y - t.y)/(d*d);
  111. dx:= dx + dx2;
  112. dy:= dy + dy2;
  113. status:= 2; //Возбуждённое состояние
  114. end;
  115. t:= t.next
  116. until t = KonAkula.next;
  117. //И обратим внимание на края:
  118. if x - xmin < opisanie[tip].See then dx:= dx + 1/((x - xmin + eps)*strahkraj);
  119. if xmax - x < opisanie[tip].See then dx:= dx + 1/((x - xmax - eps)*strahkraj);
  120. if y - ymin < opisanie[tip].See then dy:= dy + 1/((y - ymin + eps)*strahkraj);
  121. if ymax - y < opisanie[tip].See then dy:= dy + 1/((y - ymax - eps)*strahkraj);
  122. d:= sqrt(dx*dx + dy*dy);
  123. if d < eps then
  124. begin
  125. dx:= 2*status*random()*opisanie[tip].Speed - status*opisanie[tip].Speed;
  126. dy:= 2*status*random()*opisanie[tip].Speed - status*opisanie[tip].Speed
  127. end
  128. else
  129. begin
  130. dx:= status*opisanie[tip].Speed*dx/d;
  131. dy:= status*opisanie[tip].Speed*dy/d
  132. end
  133. end
  134. else {tip = 0}
  135. begin //Начало алгоритма для хищников
  136. dmin:= 11000;
  137. t:= StartAkula;
  138. while t<>ribka do //Проверяем всех выше по иерархии
  139. begin
  140. d:= sqrt((x - t.x)*(x - t.x) + (y - t.y)*(y - t.y));
  141. if (d < dmin) and (abs(dx0 - t.dx0) < epsustupi) and
  142. (abs(dy0 - t.dy0) < epsustupi) then dmin:= d;
  143. t:= t.next
  144. end;
  145. FoundOhot:= dmin < ustupi;
  146. dmin:= 11000;
  147. found:= nil;
  148. t:= StartKilka;
  149. if (t<>nil) and (life > 100) and not FoundOhot then
  150. repeat
  151. d:= sqrt((x - t.x)*(x - t.x) + (y - t.y)*(y - t.y));
  152. if d < dmin then
  153. begin
  154. dmin:= d;
  155. found:= t //found - ближайшая жертва
  156. end;
  157. t:= t.next
  158. until t = KonKilka.next;
  159. if (found <> nil) and (dmin < opisanie[tip].See) then
  160. begin
  161. status:= 2; //Возбуждённое состояние
  162. dx:= found.x - x;
  163. dy:= found.y - y;
  164. if dmin < CanEat + status*opisanie[tip].Speed then
  165. begin //Поедание
  166. found.next.prev:= found.prev;
  167. found.prev.next:= found.next;
  168. if (found = StartKilka) and (found = KonKilka) then
  169. begin
  170. //StartKilka:= nil;
  171. //KonKilka:= nil
  172. end;
  173. if found = StartKilka then
  174. StartKilka:= StartKilka.next;
  175. if found = KonKilka then
  176. KonKilka:= KonKilka.prev;
  177. found.destroy;
  178. found := nil;
  179. food:= food + 1
  180. end
  181. end
  182. else
  183. if (x <= xmin) or (x >= xmax) or (y <= ymin) or (y >= ymax) then
  184. begin
  185. dx:= 2*status*random()*opisanie[tip].Speed - status*opisanie[tip].Speed;
  186. dy:= 2*status*random()*opisanie[tip].Speed - status*opisanie[tip].Speed
  187. end
  188. else
  189. begin
  190. dx:= dx0; dy:= dy0 //Повтор предыдущего шага - патрулирование
  191. end;
  192. d:= sqrt(dx*dx + dy*dy);
  193. if d > eps then
  194. begin
  195. dx:= status*opisanie[tip].Speed*dx/d;
  196. dy:= status*opisanie[tip].Speed*dy/d;
  197. end
  198. end;
  199. //Начало алгоритма для всех рыб
  200. moveto(dx, dy);
  201. dx0:= dx; dy0:= dy;
  202. life:= life + 1; razm:= razm + 1;
  203. if opisanie[tip].Kol >= opisanie[tip].MaxKol then Razm:= 0;
  204. if (razm > opisanie[tip].CanRazm) and (food >= opisanie[tip].minfood) then
  205. MakeDeti(ribka, StartAkula, KonAkula, StartKilka, KonKilka);
  206. if life > opisanie[tip].MaxLife then //Смерть от старости
  207. begin
  208. trup:= ribka; ribka:= ribka.prev;
  209. trup.next.prev:= trup.prev;
  210. trup.prev.next:= trup.next;
  211. if trup = StartKilka then
  212. StartKilka:= StartKilka.next;
  213. if trup = KonKilka then
  214. KonKilka:= KonKilka.prev;
  215. if trup = StartAkula then
  216. StartAkula:= StartAkula.next;
  217. if trup = KonAkula then
  218. KonAkula:= KonAkula.prev;
  219. if trup = trup.next then ribka:= nil;
  220. if trup <> nil then
  221. trup.destroy;
  222. trup := nil;
  223. end
  224. end;
  225. end;
  226. function getAllCount:integer;
  227. var i,c:integer;
  228. begin
  229. c:=0;
  230. for i:=0 to types do
  231. c:=c+opisanie[i].Kol;
  232. getAllCount:=c;
  233. end;
  234. var i: integer;
  235. p, q, StartAkula, StartKilka, KonAkula, KonKilka, tek: fish;
  236. begin
  237. SetSmoothing(False);
  238. SetWindowSize(Width, Height);
  239. SetWindowLeft(200);
  240. SetWindowTop(50);
  241. SetWindowCaption('Битва за жизнь');
  242. SetFontSize(7);
  243. SetFontName('Arial');
  244. SetBrushColor(BkColor);
  245. FillRectangle(0, 0, Width, Height);
  246. SetFontColor(clWhite);
  247. TextOut(10, ymax + 20, 'Автор программы - Иванов С.О. e-mail: [email]removed@mail.ru[/email]');
  248. TextOut(10, ymax + 20+1*18, 'Программа моделирует поведение нескольких стай рыб. Справа - количества рыб в текущий');
  249. TextOut(10, ymax + 20+2*18, 'момент времени. Изменяя параметры в коде программы, можно влиять на ход битвы.');
  250. TextOut(10, ymax + 20+3*18, 'По умолчанию: красные - хищники, поедают любых рыб из других стай, не плодятся,');
  251. TextOut(10, ymax + 20+4*18, 'пока не поели; синие - жертвы, самые медленные, но быстрее всех плодятся; зелёные - жертвы,');
  252. TextOut(10, ymax + 20+5*18, 'быстрее синих, но плодятся медленнее; желтые - самые быстрые среди жертв, но желтых мало.');
  253. SetFontSize(12);
  254. StartAkula:= nil;
  255. StartKilka:= nil;
  256. KonAkula:= nil;
  257. KonKilka:= nil;
  258. //c - цвет.
  259. //CanRazm - минимальное количество ходов отдельно взятой рыбы между двумя
  260. // её последовательными размножениями.
  261. //MaxKol - максимально допустимое количество рыб данного вида.
  262. //Kol - количество рыб данного вида в текущий момент времени.
  263. //MaxLife - максимальная продолжительность жизни.
  264. // После того, как рыба сделает больше шагов, чем это число, она умирает.
  265. //MinFood - минимальное количество съеденных жертв, необходимое для размножения
  266. // (только для хищников; для жертв это количество принято за -1).
  267. //Speed - нормальная скорость. Максимальная скорость рыбы в 2 раза больше этого числа.
  268. //See - радиус обзора - как далеко видит рыба.
  269. //c, CanRazm, MaxKol, MaxLife, MinFood, Speed, See
  270. opisanie[3]:= fishtype.create(clYellow, 300, 15, 1500, -1, 0.99, 50);
  271. opisanie[2]:= fishtype.create(clGreen, 150, 50, 1500, -1, 0.9, 50);
  272. opisanie[1]:= fishtype.create(clBlue, 30, 50, 500, -1, 0.7, 35);
  273. opisanie[0]:= fishtype.create(clRed, 1000, 40, 5000, 1, 1, 500);
  274. SetPenColor(clWhite);
  275. rectangle(round(xmin - rmax - 1), round(ymin - rmax - 1),
  276. round(xmax + rmax + 1), round(ymax + rmax + 1));
  277. //Теперь нужно построить первоначальный список
  278. q:= fish.create(xmin + 10, ymax - 10, rmax, 0, nil, nil);
  279. p:= fish.create(xmin + 10, ymin + 10, rmax, 1, q, q);
  280. q.next:= p; q.prev:= p;
  281. StartAkula:= q; KonAkula:= q;
  282. StartKilka:= p; KonKilka:= p;
  283. p:= fish.create(xmax - 10, ymin + 10, rmax, 2, KonKilka, StartAkula);
  284. StartAkula.prev:= p;
  285. KonKilka.next:= p; KonKilka:= p;
  286. p:= fish.create(xmax - 10, ymax - 10, rmax, 3, KonKilka, StartAkula);
  287. StartAkula.prev:= p;
  288. KonKilka.next:= p; KonKilka:= p;
  289. for i:= 0 to types do opisanie[i].ShowKol(i*40 + 20);
  290. //И все ходят по очереди, пока хоть кто-то жив.
  291. tek:= StartKilka;
  292. //i:=0;c:=getallcount;LockDrawing;
  293. repeat
  294. tek:= tek.next;
  295. tek.step(tek, StartAkula, KonAkula, StartKilka, KonKilka);
  296. {i:=i+1;
  297. if i>=c then begin
  298. i:=0;c:=getallcount;
  299. Redraw;
  300. end;}
  301. until (tek = nil);
  302. end.

Решение задачи: «Ошибка при переносе из pascal в c#»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using sb=Microsoft.SmallBasic.Library;
  7. namespace lost_fish
  8. {
  9.    
  10.     public class Maini
  11.     {
  12.     static Random rand = new Random();
  13.          const int  types=4;
  14.          const int strahkraj = 3;
  15.         const  int rmax=4;
  16.         const  int CanEat = rmax;
  17.      
  18.          const  double eps = 0.00001;
  19.         const    double epsustupi = 0.1;  
  20.          const  int ustupi = CanEat*10;
  21.       const  int  Height = 600;
  22.       const  int Width = 780;
  23.          const int xmin = 10;
  24.         const int ymin = 10;
  25.         const int    xmax = Width - 100;
  26.          const int ymax = Height - 140;
  27.         public class fishtype
  28.         {
  29.  
  30.             public string s;
  31.             public int canrazm, maxkol, kol, maxlife, minfood;
  32.             public double speed, see;
  33.            
  34.             public fishtype(string s, int canrazm, int maxkol, int maxlife, int minfood, double speed, double see)
  35.             {
  36.                 this.s = s;
  37.                 this.canrazm = canrazm;
  38.                 this.maxkol = maxkol;
  39.                 this.maxlife = maxlife;
  40.                 this.minfood = minfood;
  41.                 this.speed = speed;
  42.                 this.see = see;
  43.             }
  44.             public void showkol(int y)
  45.             {
  46.  
  47.                 string b;
  48.                 sb.GraphicsWindow.PenColor = "White";
  49.                 sb.GraphicsWindow.DrawText(xmax + 20, y, "     ");
  50.                 b = kol.ToString();
  51.                 sb.GraphicsWindow.DrawText(xmax + 20, y, b);
  52.             }
  53.         }
  54.         static fishtype[] opisanie = new fishtype[types];
  55.         public class fish
  56.         {
  57.          
  58.             public double x, y, r, dx0, dy0;
  59.             public int tip, life, razm, status, food;
  60.             public fish next;
  61.             public fish prev;
  62.             public sb.Primitive kr = new sb.Primitive();
  63.             public fish()
  64.             {
  65.  
  66.             }
  67.             public fish(double x,double y,int r,int tip,fish prev,fish next)
  68.             {
  69.                
  70.                 this.x=x;
  71.                 this.y = y;
  72.                 this.r = r;
  73.                 this.tip = tip;
  74.                 this.prev = prev;
  75.                 this.next = next;
  76.                 this.life = 0;
  77.                 this.razm = 0;
  78.                 this.dx0 =rand.Next(1,Width - 100);
  79.                 this.dy0 = rand.Next(1,Height - 100);
  80.                 status = 1;
  81.                 food = 0;
  82.                 show();
  83.             }
  84.             public void show()
  85.             {
  86.                 sb.GraphicsWindow.PenColor = "White";
  87.                 kr = sb.Shapes.AddEllipse(r*2, r*2);
  88.                 sb.Shapes.Move(kr, Math.Round(x), Math.Round(y));
  89.                
  90.             }
  91.             public void Hide()
  92.             {
  93.                // sb.GraphicsWindow.PenColor = sb.GraphicsWindow.BackgroundColor;
  94.                 sb.Shapes.Remove(kr);
  95.             }
  96.             public void destroy()
  97.             {//
  98.                 Hide();
  99.                 opisanie[tip].kol = opisanie[tip].kol - 1;
  100.                 opisanie[tip].showkol(tip * 40 + 40);
  101.             }
  102.             public void moveto(int dx,int dy)
  103.             {
  104.                 x = x + dx;
  105.                 y=y+dy;
  106.                 if (x>xmax) x=xmax;
  107.                 if (y < xmin) x = xmin;
  108.                 if (y > ymax) y = ymax;
  109.                 if (y < ymin) y = ymin;
  110.                 sb.Shapes.Move(kr, x, y);
  111.             }
  112.             public void Makedeti(fish mama, fish startakula, fish konakula, fish startkilka, fish konkilka)
  113.             {
  114.                 fish d = new fish();
  115.                 d.x = x;
  116.                 d.y = y;
  117.                 d.r = r;
  118.                 d.prev = mama;
  119.                 d.next = next;
  120.              
  121.  
  122.                 razm = 0;
  123.                 food = 0;
  124.                 next.prev = d;
  125.                 next = d;
  126.                 if (mama == konakula) konakula = d;
  127.                 if (mama == konkilka) konkilka = d;
  128.                 opisanie[tip].kol = opisanie[tip].kol + 1;
  129.                 opisanie[tip].showkol(tip * 40 + 20);
  130.            
  131.  
  132.  
  133.             }
  134.             private double rain()
  135.             {
  136.                 return (double)rand.Next(0, 10000000) / 10000000;
  137.            
  138.             }
  139.             public void step(fish ribka, fish startakula, fish konakula,fish startkilka, fish konkilka)
  140.             {
  141.                 double dx, dy, d, dx2, dy2, dmin;
  142.                 fish t, trup, found;
  143.                 bool foundohot;
  144.                 status = 1;
  145.                 dx = 0;
  146.                 dy = 0;
  147.                 if (tip > 0)
  148.                 {
  149.                     t = startakula;
  150.                     if (t != null)
  151.                     {
  152.                         do
  153.                         {
  154.                             d = Math.Sqrt((x - t.x) * (x - t.x) + (y - t.y) * (y - t.y));
  155.                             if (d < opisanie[tip].see)
  156.                             {
  157.                                 dx2 = (x - t.x) / (d * d);
  158.                                 dy2 = (y - t.y) / (d * d);
  159.                                 dx = dx + dx2;
  160.                                 dy = dy + dy2;
  161.                                 status = 2;
  162.  
  163.                             }
  164.                             t = t.next;
  165.                         } while (t != konakula.next);
  166.                         if ((x - xmin) < opisanie[tip].see) dx = (dx + 1) / ((x - xmin + eps) * strahkraj);
  167.                         if ((xmax - x) < opisanie[tip].see) dx = (dx + 1) / ((x - xmin - eps) * strahkraj);
  168.                         if ((y - ymin) < opisanie[tip].see) dy = (dy + 1) / ((y - ymin + eps) * strahkraj);
  169.                         if ((ymax - y) < opisanie[tip].see) dy = (dy + 1) / ((y - ymin - eps) * strahkraj);
  170.                         d = Math.Sqrt(dx * dx + dy * dy);
  171.                         if (d < eps)
  172.                         {
  173.                             dx = 2 * status * rain() * opisanie[tip].speed - status * opisanie[tip].speed;
  174.                             dy = 2 * status * rain()*opisanie[tip].speed - status*opisanie[tip].speed;
  175.  
  176.                         }
  177.                         else
  178.                         {
  179.                             dx = status * opisanie[tip].speed * dx / d;
  180.                             dy = status * opisanie[tip].speed * dy / d;
  181.                         }
  182.  
  183.  
  184.                     }
  185.                     else
  186.                     {
  187.                         dmin = 11000;
  188.                         t = startakula;
  189.                         while(t!=ribka)
  190.                         {
  191.                              d = Math.Sqrt((x - t.x) * (x - t.x) + (y - t.y) * (y - t.y));
  192.                              if ((d < dmin) && (Math.Abs(dx0 - t.dx0) < epsustupi) && (Math.Abs(dy0 - t.dy0) < epsustupi)) dmin = d;
  193.                              t = t.next;
  194.                         }
  195.                         foundohot = dmin < ustupi;
  196.                         dmin = 11000;
  197.                         found = null;
  198.                         t = startkilka;
  199.                         if ((t != null) && (life > 100) && !foundohot)
  200.                         {
  201.                             do
  202.                             {
  203.                                 d = Math.Sqrt((x - t.x) * (x - t.x) + (y - t.y) * (y - t.y));
  204.                             } while (t != konkilka.next);
  205.                             if ((found!=null)&&(dmin<opisanie[tip].see))
  206.                             {
  207.                                 status=2;
  208.                                 dx=found.x-x;
  209.                                 dy=found.y-y;
  210.                                 if((dmin<(CanEat+status*opisanie[tip].speed)))
  211.                                 {
  212.                                     found.next.prev=found.prev;
  213.                                     found.prev.next=found.next;
  214.                                     if ((found==startkilka)&&(found==konkilka))
  215.                                     {
  216.                                        // startkilka=null;
  217.                                         //konkilka=null;
  218.                                     }
  219.                                     if (found==startkilka)startkilka=startkilka.next;
  220.                                     if (found==konkilka)konkilka=konkilka.prev;
  221.                                     found.destroy();
  222.                                     found=null;
  223.                                     food=food+1;
  224.                                 }
  225.                             }
  226.                             else if ((x<=xmin)||(x>=xmax)||(y<=ymin)||(y>=ymin))
  227.                             {
  228.                                 dx= 2*status*rain()*opisanie[tip].speed - status*opisanie[tip].speed;
  229.                                 dy= 2*status*rain()*opisanie[tip].speed - status*opisanie[tip].speed;
  230.  
  231.                             }
  232.                             else
  233.                             {
  234.                                 dx=dx0;
  235.                                 dy=dy0;
  236.  
  237.                             }
  238.                             d=Math.Sqrt(dx*dx+dy*dy);
  239.                             if (d>eps)
  240.                             {
  241.                                 dx=status*opisanie[tip].speed*dx/d;
  242.                                 dy= status*opisanie[tip].speed*dy/d;
  243.                             }
  244.                         }
  245.                        moveto(Convert.ToInt32(dx),Convert.ToInt32(dy));
  246.                        dx0=dx;
  247.                         dy0=dy;
  248.                         life=life+1;
  249.                         razm=razm+1;
  250.                         if (opisanie[tip].kol>=opisanie[tip].maxkol)razm=0;
  251.                         if (razm>opisanie[tip].canrazm&&food>=opisanie[tip].minfood)
  252.                        Makedeti(ribka,startakula,konakula,startkilka,konkilka);
  253.                         if (life>opisanie[tip].maxlife)
  254.                         {
  255.                             trup=ribka;
  256.                             ribka=ribka.prev;
  257.                             trup.next.prev=trup.prev;
  258.                             trup.prev.next=trup.next;
  259.                             if (trup ==startkilka) startkilka = startkilka.next;
  260.                             if (trup==konkilka)konkilka=konkilka.prev;
  261.                             if (trup==startakula)startakula=startakula.next;
  262.                             if (trup==konakula)konakula=konakula.prev;
  263.                             if (trup==trup.next)ribka=null;
  264.                             if (trup!=null)trup.destroy();
  265.                             trup=null;
  266.  
  267.                            
  268.                         }
  269.  
  270.                     }
  271.  
  272.                 }
  273.             }
  274.            
  275.         }
  276.         public int getallcount()
  277.         {
  278.             int i,c=0;
  279.             for (i=0;i<=types;i++)
  280.             {
  281.                 c+=opisanie[i].kol;
  282.             }
  283.             return c;
  284.         }
  285.  
  286.        static void Main()
  287.         {
  288.             sb.GraphicsWindow.BackgroundColor = "Black";
  289.             fish p,q,startakula,startkilka,konakula,konkilka,tek;
  290.             sb.GraphicsWindow.Height=Height;
  291.             sb.GraphicsWindow.Width=Width;
  292.             sb.GraphicsWindow.Left=200;
  293.             sb.GraphicsWindow.Top=50;
  294.             sb.GraphicsWindow.FontSize=7;
  295.             sb.GraphicsWindow.FontName="Arial";
  296.             sb.GraphicsWindow.BrushColor=sb.GraphicsWindow.BackgroundColor;
  297.             sb.GraphicsWindow.FillRectangle(0,0,Width,Height);
  298.             sb.GraphicsWindow.FontSize=12;
  299.             startakula=null;
  300.             startkilka=null;
  301.             konakula=null;;
  302.             konkilka=null;
  303.          
  304.             opisanie[3]= new fishtype("Yellow", 300,     15,     1500,    -1,      0.99,    50);
  305.             opisanie[2]= new fishtype("Green",  150,     50,     1500,    -1,      0.9,     50);
  306.             opisanie[1]= new fishtype("Blue",   30,      50,     500,     -1,      0.7,     35);
  307.          opisanie[0]= new fishtype("Red",    1000,    40,     5000,     1,       1,     500);
  308.             sb.GraphicsWindow.PenColor="White";
  309.             sb.GraphicsWindow.DrawRectangle(Math.Round((decimal)xmin - rmax - 1),Math.Round((decimal)ymin - rmax - 1),Math.Round((decimal)xmax+rmax+1),Math.Round((decimal)ymax+rmax+1));
  310.             q=new fish(xmin+10,ymax-10,rmax,0,null,null);
  311.            
  312.             p=new fish(xmin+10,ymin+10,rmax,1,q,q);
  313.             q.next = p; q.prev = p;
  314.             startakula = q;
  315.             startkilka = p;
  316.             konakula = q;
  317.             konkilka = p;
  318.             p = new fish(xmax - 10, ymin + 10, rmax, 2, konkilka, startakula);
  319.             startakula.prev = p;
  320.             konakula.next = p;
  321.             konkilka = p;
  322.             p = new fish(xmax - 10, ymax - 10, rmax,3, konkilka, startakula);
  323.             startakula.prev = p;
  324.             konkilka.next = p;
  325.             konkilka = p;
  326.             int i;
  327.             for ( i = 0; i < types;i++)
  328.                 opisanie[i].showkol(i * 40 + 20); tek = startkilka;
  329.             int j = 0;
  330.            do
  331.             {
  332.                 j++;
  333.                 tek = tek.next;
  334.                 tek.step(tek, startakula, konakula, startkilka, konkilka);
  335.                
  336.             } while (tek != null);
  337.            // sb.GraphicsWindow.PenColor = "Red";
  338.            //sb.GraphicsWindow.DrawText(100, 100, "GAme over");
  339.  
  340.  
  341.        
  342.         }
  343.  
  344.  
  345.  
  346.  
  347.     }
  348.    
  349. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 3.571 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы