本文整理汇总了C#中Level.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Level.Dispose方法的具体用法?C# Level.Dispose怎么用?C# Level.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level
的用法示例。
在下文中一共展示了Level.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Use
public override void Use(Player p, string message) {
string[] args = message.Split(' ');
if (args.Length < 5 || args.Length > 6) {
Help(p); return;
}
if (!MapGen.IsRecognisedFormat(args[4])) {
MapGen.PrintValidFormats(p); return;
}
ushort x, y, z;
string name = args[0].ToLower();
if (!UInt16.TryParse(args[1], out x) || !UInt16.TryParse(args[2], out y) || !UInt16.TryParse(args[3], out z)) {
Player.SendMessage(p, "Invalid dimensions."); return;
}
int seed = 0;
bool useSeed = args.Length == 6;
if (useSeed && !Int32.TryParse(args[5], out seed))
seed = args[5].GetHashCode();
if (!MapGen.OkayAxis(x)) { Player.SendMessage(p, "width must be a power of two >= to 16."); return; }
if (!MapGen.OkayAxis(y)) { Player.SendMessage(p, "height must be a power of two >= to 16."); return; }
if (!MapGen.OkayAxis(z)) { Player.SendMessage(p, "length must be a power of two >= to 16."); return; }
if (!Player.ValidName(name)) {
Player.SendMessage(p, "Invalid name!"); return;
}
if (File.Exists("levels/" + name + ".lvl")) {
Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return;
}
if (p != null) {
int limit = p.group.Permission < LevelPermission.Admin ? 30000000 : 225000000;
if (x * y * z > limit ) {
string text = String.Format("Cannot create a map with over {0} million blocks",
limit / 1000000);
Player.SendMessage(p, text); return;
}
}
try {
using (Level lvl = new Level(name, x, y, z, args[4], seed, useSeed)) {
lvl.Save(true);
lvl.Dispose();
}
} finally {
GC.Collect();
GC.WaitForPendingFinalizers();
}
string format = useSeed ? "Level \"{0}\" created with seed \"{1}\"" : "Level \"{0}\" created";
if (useSeed)
Player.GlobalMessage(String.Format(format, name, args[5]));
else
Player.GlobalMessage(String.Format(format, name));
}
示例2: Use
public override void Use(Player p, string message)
{
if (message == "") { Help(p); return; }
string[] parameters = message.Split(' '); // Grab the parameters from the player's message
if (parameters.Length >= 5 && parameters.Length <= 6) // make sure there are 5 or 6 params
{
switch (parameters[4])
{
case "flat":
case "pixel":
case "island":
case "mountains":
case "ocean":
case "forest":
case "desert":
case "space":
case "rainbow":
case "hell":
break;
default:
Player.SendMessage(p, "Valid types: island, mountains, forest, ocean, flat, pixel, desert, space, rainbow, and hell"); return;
}
string name = parameters[0].ToLower();
ushort x = 1, y = 1, z = 1;
int seed = 0;
bool useSeed = false;
try
{
x = Convert.ToUInt16(parameters[1]);
y = Convert.ToUInt16(parameters[2]);
z = Convert.ToUInt16(parameters[3]);
}
catch { Player.SendMessage(p, "Invalid dimensions."); return; }
if (parameters.Length == 6)
{
try { seed = Convert.ToInt32(parameters[5]); }
catch { seed = parameters[5].GetHashCode(); }
useSeed = true;
}
if (!isGood(x)) { Player.SendMessage(p, x + " is not a good dimension! Use a power of 2 next time."); return; }
if (!isGood(y)) { Player.SendMessage(p, y + " is not a good dimension! Use a power of 2 next time."); return; }
if (!isGood(z)) { Player.SendMessage(p, z + " is not a good dimension! Use a power of 2 next time."); return; }
if (!Player.ValidName(name)) { Player.SendMessage(p, "Invalid name!"); return; }
if (System.IO.File.Exists("levels/" + name + ".lvl")) { Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return; }
/*try
{
if (p != null)
if (p.group.Permission < LevelPermission.Admin)
{
if (x * y * z > 30000000) { Player.SendMessage(p, "Cannot create a map with over 30million blocks"); return; }
}
else
{
if (x * y * z > 225000000) { Player.SendMessage(p, "You cannot make a map with over 225million blocks"); return; }
}
}
catch
{
Player.SendMessage(p, "An error occured");
}*/
// create a new level...
try
{
using (Level lvl = new Level(name, x, y, z, parameters[4], seed, useSeed))
{
lvl.Save(true); //... and save it.
lvl.Dispose(); // Then take out the garbage.
}
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
Player.GlobalMessage("Level \"" + name + "\" created" + (useSeed ? " with seed \"" + parameters[5] + "\"" : "")); // The player needs some form of confirmation.
}
else
Help(p);
}