В чём причина возникновения TypeInitializationException? - C#

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

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

Возникла проблема. Поскольку я чрезвычайно начинающ, понятия не имею, что с этим делать. Справка дает очень расплывчатое и непонятное определение. Скриншот и файлы прилагаются, под катом класс, на который ссылается компилятор.
Листинг программы
  1. static class Game
  2. {
  3. public static World w1 = new World();
  4. public static Player player = w1.player;
  5. public static bool bool_game {
  6. get {
  7. return player.alive;
  8. }
  9. set {
  10. bool_game = value;
  11. }
  12. }
  13. public static ConsoleKeyInfo key;
  14. public static ItemCharact[] items = {
  15. new ItemCharact ("Посох огня", 50, false, 1, "other", new SpellCircle ())
  16. };
  17. //----------
  18. public static void Main ()
  19. {
  20. try
  21. {
  22. Console.ReadKey ();
  23. Console.SetWindowSize (85, 43);
  24. charactChoose ();
  25. while (bool_game) {
  26. Console.Clear ();
  27. w1.showLevel ();
  28. key = new ConsoleKeyInfo ();
  29. key = Console.ReadKey ();
  30. UseKey (w1, key);
  31. w1.everyTime ();
  32. }
  33. Console.WriteLine ("You're dead. Lol.");
  34. Console.ReadKey ();
  35. }
  36. catch (TypeInitializationException ex)
  37. {
  38. Console.WriteLine(ex.InnerException);
  39. }
  40. }
  41. public static void UseKey (World w, ConsoleKeyInfo usingKey) // выполняет действие, соответствующее символу char
  42. {
  43. switch (usingKey.Key)
  44. {
  45. case ConsoleKey.W:
  46. w.player.ChangeCell (w.player.x, w.player.y - 1);
  47. break;
  48. case ConsoleKey.A:
  49. w.player.ChangeCell (w.player.x - 1, w.player.y);
  50. break;
  51. case ConsoleKey.S:
  52. w.player.ChangeCell (w.player.x, w.player.y + 1);
  53. break;
  54. case ConsoleKey.D:
  55. w.player.ChangeCell (w.player.x + 1, w.player.y);
  56. break;
  57. case ConsoleKey.F:
  58. SpellCircle s = new SpellCircle (player, w1);
  59. s.FirstUse ();
  60. break;
  61. case ConsoleKey.I:
  62. player.it.Use ();
  63. break;
  64. }
  65. }
  66. public static void charactChoose ()
  67. {
  68. ConsoleKey k = ConsoleKey.Q;
  69. int freePoints = 20;
  70. int cursor = 0;
  71. while (k != ConsoleKey.Enter || !(freePoints <= 0)) {
  72. Console.Clear ();
  73. Console.ResetColor ();
  74. int i = 0;
  75. foreach (string prof in player.profs) {
  76. if (cursor == i) {
  77. Console.Write (" > {0}", prof);
  78. } else {
  79. Console.Write (" {0}", prof);
  80. }
  81. switch (i) {
  82. case 0:
  83. Console.WriteLine (" < {0} > ", player.pclnow);
  84. break;
  85. case 1:
  86. Console.WriteLine (" < {0} > ", player.rcenow);
  87. Console.WriteLine ("");
  88. Console.WriteLine ("\tХарактеристики:");
  89. break;
  90. case 2:
  91. Console.WriteLine (" < {0} > ", player.strenght);
  92. break;
  93. case 3:
  94. Console.WriteLine (" < {0} > ", player.skill);
  95. break;
  96. case 4:
  97. Console.WriteLine (" < {0} > ", player.magic);
  98. Console.WriteLine ("");
  99. break;
  100. case 5:
  101. Console.WriteLine (" < {0} > ", player.killer);
  102. break;
  103. case 6:
  104. Console.WriteLine (" < {0} > ", player.hunter);
  105. break;
  106. case 7:
  107. Console.WriteLine (" < {0} > ", player.healer);
  108. Console.WriteLine ("");
  109. break;
  110. case 8:
  111. Console.WriteLine (" < {0} > ", player.miner);
  112. break;
  113. case 9:
  114. Console.WriteLine (" < {0} > ", player.blacksmith);
  115. break;
  116. case 10:
  117. Console.WriteLine (" < {0} > ", player.enchanter);
  118. Console.WriteLine ("");
  119. break;
  120. case 11:
  121. Console.WriteLine (" < {0} > ", player.blackmage);
  122. break;
  123. case 12:
  124. Console.WriteLine (" < {0} > ", player.whitemage);
  125. break;
  126. case 13:
  127. Console.WriteLine (" < {0} > ", player.othermage);
  128. Console.WriteLine ("");
  129. break;
  130. case 14:
  131. Console.WriteLine (" < {0} > ", player.carpenter);
  132. Console.WriteLine ("\n Осталось очков навыков: {0}" +
  133. "\n\n W - вверх" +
  134. "\n S - вниз" +
  135. "\n A - уменьшить количество очков" +
  136. "\n D - увеличить количество очков" +
  137. "\n\n [Enter] - выйти" +
  138. "\n Выйти можно, когда все очки будут распределены по навыкам", freePoints);
  139. break;
  140. }
  141. i++;
  142. }
  143. k = Console.ReadKey ().Key;
  144. switch (k) {
  145. case ConsoleKey.S:
  146. case ConsoleKey.DownArrow:
  147. cursor = (cursor + 1) % player.profs.Length;
  148. break;
  149. case ConsoleKey.W:
  150. case ConsoleKey.UpArrow:
  151. cursor--;
  152. if (cursor < 0)
  153. cursor = player.profs.Length - 1;
  154. break;
  155. case ConsoleKey.D:
  156. case ConsoleKey.RightArrow:
  157. if (freePoints > 0) {
  158. if (cursor == 0) {
  159. player.pclass++;
  160. } else if (cursor == 1) {
  161. player.race++;
  162. } else {
  163. freePoints--;
  164. unsafe {
  165. int* d = player.GetCharactVar (cursor);
  166. (*d)++;
  167. }
  168. }
  169. }
  170. break;
  171. case ConsoleKey.A:
  172. case ConsoleKey.LeftArrow:
  173. unsafe {
  174. if (cursor == 0) {
  175. player.pclass--;
  176. } else if (cursor == 1) {
  177. player.race--;
  178. } else {
  179. int* b = player.GetCharactVar (cursor);
  180. if (*b > 0) {
  181. freePoints++;
  182. (*b)--;
  183. }
  184. }
  185. }
  186. break;
  187. case ConsoleKey.F1:
  188. player.strenght += 5;
  189. player.skill += 10;
  190. player.magic += 5;
  191. return;
  192. }
  193. }
  194. }
  195. }
old_rogue1.x.rar

Решение задачи: «В чём причина возникновения TypeInitializationException?»

textual
Листинг программы
  1.         static Game()
  2.         {
  3.             items = new[]
  4.             {
  5.                 new ItemCharact("Посох огня", 50, false, 1, "other", new SpellCircle())
  6.             };
  7.  
  8.             w1 = new World();
  9.             player = w1.player;
  10.         }

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


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

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

7   голосов , оценка 4 из 5

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

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

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