本文整理汇总了C#中Level.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Level.Save方法的具体用法?C# Level.Save怎么用?C# Level.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level
的用法示例。
在下文中一共展示了Level.Save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSaveAndLoad
public void TestSaveAndLoad()
{
var level = new Level();
level.LevelName = "Example";
level.Save("test.dat");
var loaded = Level.Load("test.dat");
Assert.AreEqual(level.LevelName, loaded.LevelName);
}
示例2: SaveLevel
public void SaveLevel( Level level )
{
JSONObject root = new JSONObject(JSONObject.Type.OBJECT);
level.Save(root);
string filePath = Application.dataPath + "/Resources/level_" + level.Number + ".json";
File.WriteAllBytes(filePath, System.Text.Encoding.UTF8.GetBytes (root.Print(true)));
}
示例3: 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));
}
示例4: 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);
}
示例5: Start
//.........这里部分代码省略.........
ml.Queue(delegate
{
try
{
levels = new List<Level>(Server.maps);
MapGen = new MapGenerator();
Random random = new Random();
if (File.Exists("levels/" + Server.level + ".lvl"))
{
mainLevel = Level.Load(Server.level);
mainLevel.unload = false;
if (mainLevel == null)
{
if (File.Exists("levels/" + Server.level + ".lvl.backup"))
{
Log("Attempting to load backup.");
File.Copy("levels/" + Server.level + ".lvl.backup", "levels/" + Server.level + ".lvl", true);
mainLevel = Level.Load(Server.level);
if (mainLevel == null)
{
Log("BACKUP FAILED!");
Console.ReadLine(); return;
}
}
else
{
Log("mainlevel not found");
mainLevel = new Level(Server.level, 128, 64, 128, "flat");
mainLevel.permissionvisit = LevelPermission.Guest;
mainLevel.permissionbuild = LevelPermission.Guest;
mainLevel.Save();
}
}
}
else
{
Log("mainlevel not found");
mainLevel = new Level(Server.level, 128, 64, 128, "flat");
mainLevel.permissionvisit = LevelPermission.Guest;
mainLevel.permissionbuild = LevelPermission.Guest;
mainLevel.Save();
}
addLevel(mainLevel);
mainLevel.physThread.Start();
} catch (Exception e) { Server.ErrorLog(e); }
});
ml.Queue(delegate
{
bannedIP = PlayerList.Load("banned-ip.txt", null);
ircControllers = PlayerList.Load("IRC_Controllers.txt", null);
foreach (Group grp in Group.GroupList)
grp.playerList = PlayerList.Load(grp.fileName, grp);
if (Server.useWhitelist)
whiteList = PlayerList.Load("whitelist.txt", null);
});
ml.Queue(delegate
{
if (File.Exists("text/autoload.txt"))
{
示例6: 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) // make sure there are 5 params
{
switch (parameters[4])
{
case "flat":
case "pixel":
case "island":
case "mountains":
case "ocean":
case "forest":
case "desert":
break;
default:
Player.SendMessage(p, "Valid types: island, mountains, forest, ocean, flat, pixel, desert"); return;
}
string name = parameters[0].ToLower();
ushort x = 1, y = 1, z = 1;
try
{
x = Convert.ToUInt16(parameters[1]);
y = Convert.ToUInt16(parameters[2]);
z = Convert.ToUInt16(parameters[3]);
}
catch { Player.SendMessage(p, "Invalid dimensions."); return; }
if (!isGood(x)) { Player.SendMessage(p, x + " is not a good dimension! Use a power of 2 next time."); }
if (!isGood(y)) { Player.SendMessage(p, y + " is not a good dimension! Use a power of 2 next time."); }
if (!isGood(z)) { Player.SendMessage(p, z + " is not a good dimension! Use a power of 2 next time."); }
if (!Player.ValidName(name)) { Player.SendMessage(p, "Invalid name!"); 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
{
Level lvl = new Level(name, x, y, z, parameters[4]);
lvl.Save(true); //... and save it.
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
Player.GlobalMessage("Level " + name + " created"); // The player needs some form of confirmation.
}
else
Help(p);
}
示例7: Load
public static Level Load(Stream stream, string fileName)
{
byte[] temp = new byte[8];
using (Level lvl = new Level(fileName, 0, 0, 0, "empty"))
{
try
{
stream.Seek(-4, SeekOrigin.End);
stream.Read(temp, 0, sizeof(int));
stream.Seek(0, SeekOrigin.Begin);
int length = BitConverter.ToInt32(temp, 0);
byte[] data = new byte[length];
using (GZipStream reader = new GZipStream(stream, CompressionMode.Decompress, true))
reader.Read(data, 0, length);
for (int i = 0; i < length - 1; i++)
{
if (data[i] == 0xAC && data[i + 1] == 0xED)
{
// bypassing the header crap
int pointer = i + 6;
Array.Copy(data, pointer, temp, 0, sizeof(short));
pointer += IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
pointer += 13;
int headerEnd = 0;
// find the end of serialization listing
for (headerEnd = pointer; headerEnd < data.Length - 1; headerEnd++)
{
if (data[headerEnd] == 0x78 && data[headerEnd + 1] == 0x70)
{
headerEnd += 2;
break;
}
}
// start parsing serialization listing
int offset = 0;
while (pointer < headerEnd)
{
if (data[pointer] == 'Z') offset++;
else if (data[pointer] == 'I' || data[pointer] == 'F') offset += 4;
else if (data[pointer] == 'J') offset += 8;
pointer += 1;
Array.Copy(data, pointer, temp, 0, sizeof(short));
short skip = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(temp, 0));
pointer += 2;
// look for relevant variables
Array.Copy(data, headerEnd + offset - 4, temp, 0, sizeof(int));
if (MemCmp(data, pointer, "width"))
{
lvl.Width = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
}
else if (MemCmp(data, pointer, "depth"))
{
lvl.Height = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
}
else if (MemCmp(data, pointer, "height"))
{
lvl.Length = (ushort)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(temp, 0));
}
pointer += skip;
}
lvl.spawnx = (ushort)(lvl.Width / 1.3);
lvl.spawny = (ushort)(lvl.Height / 1.3);
lvl.spawnz = (ushort)(lvl.Length / 1.3);
// find the start of the block array
bool foundBlockArray = false;
offset = Array.IndexOf<byte>(data, 0x00, headerEnd);
while (offset != -1 && offset < data.Length - 2)
{
if (data[offset] == 0x00 && data[offset + 1] == 0x78 && data[offset + 2] == 0x70)
{
foundBlockArray = true;
pointer = offset + 7;
}
offset = Array.IndexOf<byte>(data, 0x00, offset + 1);
}
// copy the block array... or fail
if (foundBlockArray)
{
CopyBlocks(lvl, data, pointer);
lvl.Save(true);
}
else
{
throw new Exception("Could not locate block array.");
}
break;
}
}
}
catch (Exception ex)
//.........这里部分代码省略.........