В чём причина возникновения TypeInitializationException? - C#
Формулировка задачи:
Возникла проблема. Поскольку я чрезвычайно начинающ, понятия не имею, что с этим делать. Справка дает очень расплывчатое и непонятное определение. Скриншот и файлы прилагаются, под катом класс, на который ссылается компилятор.
old_rogue1.x.rar
static class Game
{
public static World w1 = new World();
public static Player player = w1.player;
public static bool bool_game {
get {
return player.alive;
}
set {
bool_game = value;
}
}
public static ConsoleKeyInfo key;
public static ItemCharact[] items = {
new ItemCharact ("Посох огня", 50, false, 1, "other", new SpellCircle ())
};
//----------
public static void Main ()
{
try
{
Console.ReadKey ();
Console.SetWindowSize (85, 43);
charactChoose ();
while (bool_game) {
Console.Clear ();
w1.showLevel ();
key = new ConsoleKeyInfo ();
key = Console.ReadKey ();
UseKey (w1, key);
w1.everyTime ();
}
Console.WriteLine ("You're dead. Lol.");
Console.ReadKey ();
}
catch (TypeInitializationException ex)
{
Console.WriteLine(ex.InnerException);
}
}
public static void UseKey (World w, ConsoleKeyInfo usingKey) // выполняет действие, соответствующее символу char
{
switch (usingKey.Key)
{
case ConsoleKey.W:
w.player.ChangeCell (w.player.x, w.player.y - 1);
break;
case ConsoleKey.A:
w.player.ChangeCell (w.player.x - 1, w.player.y);
break;
case ConsoleKey.S:
w.player.ChangeCell (w.player.x, w.player.y + 1);
break;
case ConsoleKey.D:
w.player.ChangeCell (w.player.x + 1, w.player.y);
break;
case ConsoleKey.F:
SpellCircle s = new SpellCircle (player, w1);
s.FirstUse ();
break;
case ConsoleKey.I:
player.it.Use ();
break;
}
}
public static void charactChoose ()
{
ConsoleKey k = ConsoleKey.Q;
int freePoints = 20;
int cursor = 0;
while (k != ConsoleKey.Enter || !(freePoints <= 0)) {
Console.Clear ();
Console.ResetColor ();
int i = 0;
foreach (string prof in player.profs) {
if (cursor == i) {
Console.Write (" > {0}", prof);
} else {
Console.Write (" {0}", prof);
}
switch (i) {
case 0:
Console.WriteLine (" < {0} > ", player.pclnow);
break;
case 1:
Console.WriteLine (" < {0} > ", player.rcenow);
Console.WriteLine ("");
Console.WriteLine ("\tХарактеристики:");
break;
case 2:
Console.WriteLine (" < {0} > ", player.strenght);
break;
case 3:
Console.WriteLine (" < {0} > ", player.skill);
break;
case 4:
Console.WriteLine (" < {0} > ", player.magic);
Console.WriteLine ("");
break;
case 5:
Console.WriteLine (" < {0} > ", player.killer);
break;
case 6:
Console.WriteLine (" < {0} > ", player.hunter);
break;
case 7:
Console.WriteLine (" < {0} > ", player.healer);
Console.WriteLine ("");
break;
case 8:
Console.WriteLine (" < {0} > ", player.miner);
break;
case 9:
Console.WriteLine (" < {0} > ", player.blacksmith);
break;
case 10:
Console.WriteLine (" < {0} > ", player.enchanter);
Console.WriteLine ("");
break;
case 11:
Console.WriteLine (" < {0} > ", player.blackmage);
break;
case 12:
Console.WriteLine (" < {0} > ", player.whitemage);
break;
case 13:
Console.WriteLine (" < {0} > ", player.othermage);
Console.WriteLine ("");
break;
case 14:
Console.WriteLine (" < {0} > ", player.carpenter);
Console.WriteLine ("\n Осталось очков навыков: {0}" +
"\n\n W - вверх" +
"\n S - вниз" +
"\n A - уменьшить количество очков" +
"\n D - увеличить количество очков" +
"\n\n [Enter] - выйти" +
"\n Выйти можно, когда все очки будут распределены по навыкам", freePoints);
break;
}
i++;
}
k = Console.ReadKey ().Key;
switch (k) {
case ConsoleKey.S:
case ConsoleKey.DownArrow:
cursor = (cursor + 1) % player.profs.Length;
break;
case ConsoleKey.W:
case ConsoleKey.UpArrow:
cursor--;
if (cursor < 0)
cursor = player.profs.Length - 1;
break;
case ConsoleKey.D:
case ConsoleKey.RightArrow:
if (freePoints > 0) {
if (cursor == 0) {
player.pclass++;
} else if (cursor == 1) {
player.race++;
} else {
freePoints--;
unsafe {
int* d = player.GetCharactVar (cursor);
(*d)++;
}
}
}
break;
case ConsoleKey.A:
case ConsoleKey.LeftArrow:
unsafe {
if (cursor == 0) {
player.pclass--;
} else if (cursor == 1) {
player.race--;
} else {
int* b = player.GetCharactVar (cursor);
if (*b > 0) {
freePoints++;
(*b)--;
}
}
}
break;
case ConsoleKey.F1:
player.strenght += 5;
player.skill += 10;
player.magic += 5;
return;
}
}
}
}Решение задачи: «В чём причина возникновения TypeInitializationException?»
textual
Листинг программы
static Game()
{
items = new[]
{
new ItemCharact("Посох огня", 50, false, 1, "other", new SpellCircle())
};
w1 = new World();
player = w1.player;
}