public void Load(string sFileName) // Загрузка поля { string[] lines = File.ReadAllLines(sFileName); for (byte yy = 0; yy < lines.Length; yy++) { string[] arRows = lines[yy].Split( new[] { ';' }, StringSplitOptions.None); for (byte xx = 0; xx < arRows.Length; xx++) { string sValue = arRows[xx]; switch (sValue) { case "0": //Ячейка травы { cCellField pCell = new cCellField(xx, yy); pCell.Type = false; FieldCellList.Add(pCell); break; } case "1": // Ячейка стены { cCellField pCell = new cCellField(xx, yy); pCell.Type = true; FieldCellList.Add(pCell); break; } case "2": //Змея { cCellSnake pCellSnake = new cCellSnake(xx, yy); Snake.SnakeCellList.Add(pCellSnake); cCellField pCell = new cCellField(xx, yy); pCell.Type = false; FieldCellList.Add(pCell); break; } case "3": // Яблоко { Apple = new cApple(xx, yy); Apple.Type = type.Point; cCellField pCell = new cCellField(xx, yy); pCell.Type = false; FieldCellList.Add(pCell); break; } default: throw new Exception("Неверный формат файла, некорректное значение " + sValue); } } } }
/// <summary> /// Новый тип яблока /// </summary> /// <param name="Apple_old"></param> /// <returns></returns> private cApple AppleType(cApple Apple_old) { cApple Apple = Apple_old; Random rand = new Random(); int N = rand.Next(0, 100); if (N < 60) { Apple.Type = type.Point; } else if ((N > 60) & (N < 80)) { Apple.Type = type.BigPoint; } else if ((N > 80) & (N < 96)) { Apple.Type = type.Surprise; } else { Apple.Type = type.Life; } return(Apple); }