Advertisement
Guest User

ASmeise

a guest
Jun 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication42
  8. {
  9. class Ameise
  10. {
  11. public int PosX = 1;
  12. public int PosY = 1;
  13. public string Zeichen;
  14. public int Tage = 0;
  15.  
  16. public void ZeichneDich()
  17. {
  18. Zeichen = "*";
  19. }
  20.  
  21. public void Sterbe()
  22. {
  23. if (Tage >= 70 & Tage <= 70)
  24. {
  25. Zeichen = "T";
  26. }
  27. }
  28.  
  29. public void Rotte()
  30. {
  31. if (Tage > 100)
  32. {
  33. System.Console.SetCursorPosition(PosX, PosY);
  34. Console.Write(" ");
  35. }
  36. }
  37.  
  38. public void MacheSchritt()
  39. {
  40. int PosXR = PosX + 1;
  41. int PosXL = PosX - 1;
  42. int PosYU = PosY - 1;
  43. int PosYO = PosY + 1;
  44.  
  45. System.Console.SetCursorPosition(PosX, PosY);
  46. Console.Write(" ");
  47.  
  48.  
  49.  
  50. if (Tage <= 70)
  51. {
  52. int Zufallsschritt;
  53.  
  54. Random random = new Random();
  55.  
  56. Zufallsschritt = random.Next(1, 5);
  57. System.Threading.Thread.Sleep(1);
  58.  
  59.  
  60. if (Zufallsschritt == 1)
  61. {
  62.  
  63.  
  64. if (PosY == 29)
  65. {
  66. PosY--;
  67. }
  68. PosY++;
  69. }
  70.  
  71.  
  72. if (Zufallsschritt == 2)
  73. {
  74. if (PosY == 1)
  75. {
  76. PosY++;
  77. }
  78. PosY--;
  79. }
  80.  
  81.  
  82. if (Zufallsschritt == 3)
  83. {
  84. if (PosX == 114)
  85. {
  86. PosX--;
  87. }
  88. PosX++;
  89. }
  90.  
  91.  
  92. if (Zufallsschritt == 4)
  93. {
  94. if (PosX == 1)
  95. {
  96. PosX++;
  97. }
  98. PosX--;
  99. }
  100. }
  101.  
  102. System.Console.SetCursorPosition(PosX, PosY);
  103. Console.Write(Zeichen);
  104. Tage++;
  105. }
  106. }
  107.  
  108. class Königin
  109. {
  110. public string Zeichen;
  111. public int PosX = 1;
  112. public int PosY = 5;
  113. public int Tage = 0;
  114. public int EI;
  115. public int Eier;
  116.  
  117. public void ZeichneDich()
  118. {
  119. Zeichen = "K";
  120. }
  121.  
  122. public void Sterbe()
  123. {
  124. if (Tage >= 70 & Tage <= 70)
  125. {
  126. Zeichen = "T";
  127. }
  128. }
  129.  
  130. public void Rotte()
  131. {
  132. if (Tage > 100)
  133. {
  134. System.Console.SetCursorPosition(PosX, PosY);
  135. Console.Write(" ");
  136. }
  137. }
  138.  
  139. public void MacheSchritt()
  140. {
  141. System.Console.SetCursorPosition(PosX, PosY);
  142. Console.Write(" ");
  143.  
  144. if (Tage <= 70)
  145. {
  146. int Zufallsschritt;
  147.  
  148. Random random = new Random();
  149.  
  150. Zufallsschritt = random.Next(1, 5);
  151. System.Threading.Thread.Sleep(1);
  152.  
  153. if (Zufallsschritt == 1)
  154. {
  155. if (PosY == 29)
  156. {
  157. PosY--;
  158. }
  159. PosY++;
  160. }
  161.  
  162.  
  163. if (Zufallsschritt == 2)
  164. {
  165. if (PosY == 1)
  166. {
  167. PosY++;
  168. }
  169. PosY--;
  170. }
  171.  
  172.  
  173. if (Zufallsschritt == 3 && Tage != 10 && Tage != 20 && Tage != 30)
  174. {
  175. if (PosX == 114)
  176. {
  177. PosX--;
  178. }
  179. PosX++;
  180. }
  181.  
  182. if (Zufallsschritt == 3 || Tage == 10 || Tage == 20 || Tage == 30)
  183. {
  184. if (PosX == 114)
  185. {
  186. PosX++;
  187. }
  188. PosX++;
  189. }
  190.  
  191. if (Zufallsschritt == 4)
  192. {
  193. if (PosX == 1)
  194. {
  195. PosX++;
  196. }
  197. PosX--;
  198. }
  199. }
  200.  
  201. System.Console.SetCursorPosition(PosX, PosY);
  202. Console.Write(Zeichen);
  203. Tage++;
  204. }
  205.  
  206. public void LegeEI()
  207. {
  208.  
  209. if (Tage == 10 || Tage == 20 || Tage == 60 || Tage == 30 || Tage == 40 || Tage == 50)
  210. {
  211. EI = PosX - 1;
  212. System.Console.SetCursorPosition(EI, PosY);
  213. Console.Write(".");
  214. Eier++;
  215. }
  216. }
  217. }
  218.  
  219. class Spielfeld
  220. {
  221. public int xAnfang = 0;
  222. public int xEnde = 116;
  223. public int yAnfang = 0;
  224. public int yEnde = 30;
  225. public int Tage = 0;
  226.  
  227. public void MainFeld()
  228. {
  229. string[,] array = new string[116, 31];
  230.  
  231. for (int i = 0; i <= 30; i++)
  232. {
  233. for (int n = 0; n <= 115; n++)
  234. {
  235. if (i == 30 || i == 0)
  236. {
  237. array[n, i] = "-";
  238. }
  239.  
  240. else if ( n == 115 || n == 0)
  241. {
  242. array[n, i] = "|";
  243. }
  244.  
  245. else
  246. {
  247. array[n, i] = " ";
  248. }
  249.  
  250. }
  251. }
  252.  
  253. for (int i = 0; i < 30; i++)
  254. {
  255. for (int n = 0; n < 115; n++)
  256. {
  257. Console.Write(array[n, i]);
  258. }
  259. Console.WriteLine();
  260. }
  261.  
  262. }
  263.  
  264. public void Tagzähler()
  265. {
  266. System.Console.SetCursorPosition(1, 32);
  267. Tage++;
  268. Console.WriteLine("Tag:" + Tage);
  269. }
  270. }
  271.  
  272. class Programm
  273. {
  274.  
  275. public static void Main(string[] args)
  276. {
  277.  
  278. bool bWeitermachen = true;
  279. Ameise[] ameisen = new Ameise[50];
  280. Random random = new Random();
  281.  
  282. int[,] array = new int[50, 3];
  283.  
  284. for (int i = 0; i < ameisen.Length; i++)
  285. {
  286. ameisen[i] = new Ameise();
  287.  
  288.  
  289.  
  290. int StartpositionX = random.Next(1, 115);
  291. int StartpositionY = random.Next(1, 30);
  292.  
  293. System.Threading.Thread.Sleep(1);
  294.  
  295.  
  296. ameisen[i].PosX = StartpositionX;
  297. ameisen[i].PosY = StartpositionY;
  298.  
  299.  
  300. ameisen[i].ZeichneDich();
  301.  
  302. }
  303.  
  304. Königin königin = new Königin();
  305. Spielfeld spielfeld = new Spielfeld();
  306. Spielfeld Tagzähler = new Spielfeld();
  307.  
  308. königin.PosX = 58;
  309. königin.PosY = 15;
  310.  
  311. spielfeld.MainFeld();
  312.  
  313. königin.ZeichneDich();
  314.  
  315.  
  316. while (bWeitermachen)
  317. {
  318. for (int i = 0; i < ameisen.Length; i++)
  319. {
  320. ameisen[i].MacheSchritt();
  321. System.Threading.Thread.Sleep(1);
  322. ameisen[i].Sterbe();
  323. ameisen[i].Rotte();
  324. }
  325.  
  326.  
  327.  
  328. königin.MacheSchritt();
  329. königin.LegeEI();
  330. königin.Sterbe();
  331. königin.Rotte();
  332.  
  333. System.Threading.Thread.Sleep(0); //System einschlafen lassen, zum ausbremsen der Ameise
  334.  
  335. spielfeld.Tagzähler();
  336.  
  337.  
  338.  
  339.  
  340. }
  341.  
  342. }
  343.  
  344. }
  345. }
  346. // In der Klasse Spielfeld mit festgelegten Blumenplätzen
  347. // In der Klasse Ameise eine Methode ( in der die Ameise immer überprüft ob an ihrem Platz eine Blume ist oder nicht (Abfrage))
  348. // ( wenn ja wird die Blume gefressen )
  349. // Ab
  350. /*string[,] array = new string[115, 30];
  351.  
  352. for (int i = 0; i < 30; i++)
  353. {
  354. for (int n = 0; n < 115; n++)
  355. {
  356. if(i == 0 || i == 30)
  357. {
  358. array[n, i] = "-";
  359. }
  360.  
  361. else if(n == 0 || n == 115)
  362. {
  363. array[n, i] = "|";
  364. }
  365. else
  366. {
  367. array[n, i] = " ";
  368. }
  369.  
  370. }
  371. }
  372.  
  373. for (int i = 0; i < 30; i++)
  374. {
  375. for (int n = 0; n < 115; n++)
  376. {
  377. Console.Write(array[n, i]);
  378. }
  379. Console.WriteLine();
  380. }
  381.  
  382.  
  383.  
  384.  
  385. Console.SetCursorPosition(xAnfang, yAnfang);
  386. Console.WriteLine(" ---------------------------------------------------------------");
  387.  
  388. for (int c = 0; c < yEnde; c++)
  389. {
  390. Console.WriteLine("| |");
  391. }
  392.  
  393. Console.WriteLine(" ---------------------------------------------------------------");
  394.  
  395. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement