private static PlayerData parseV1(string data) { var reader = new StringReader(data); var player = new PlayerData(); player.Mapdata = new List<MapSaveData>(); var pdata = reader.ReadLine(); if (pdata != null) { pdata = pdata.Trim(); player.DataVersion = pdata; } var index = 0; player.Mapdata = new List<MapSaveData>(); var curdata = -1; while (index < 200) { pdata = reader.ReadLine(); index += 1; if(string.IsNullOrEmpty(pdata))continue;; pdata = pdata.Trim(); switch (pdata) { case "#player": curdata = 1; break; case "#setting": curdata = 2; break; case "#mapdata": curdata = 3; break; default: switch (curdata) { case 1: //read player var dindex = 0; var sdata = pdata.Split(','); if (sdata.Length > 3) { player.Id = sdata[dindex++]; player.PlayerName = sdata[dindex++]; player.Skin = sdata[dindex++]; player.IsFirst = sdata[dindex++] == "1"; player.Data = sdata[dindex++]; } break; case 2: player.Setting = pdata; break; case 3: var map = MapSaveData.Parse(pdata); player.Mapdata.Add(map); break; } break; } } if (index > 100) { } return player; }
private void LoadPlaye_btn_Click(object sender, EventArgs e) { if (File.Exists(playerdatafile_tbx.Text)) { var str = File.ReadAllText(playerdatafile_tbx.Text); _player = PlayerData.ParsePlayerData(str); if (_player != null) { playersaveObjec_lv.SetObjects(_player.Mapdata); player_tbx.Text = string.Format("{0},{1},{2},{3}", _player.Id, _player.PlayerName, _player.Skin, _player.IsFirst); setting_tbx.Text = _player.Setting; } else { MessageBox.Show("Error"); } } }
public static PlayerData InitPlayerData() { var player = new PlayerData(); player.Skin = "0:0:0:0:0:0:0"; var listmap = new List<MapSaveData>(); for (int i = 0; i < 10; i++) { listmap.Add(MapSaveData.Parse(string.Format("{0},{1},{2},{3},{4}", i, 1, i, 2, i))); } player.Mapdata = listmap; return player; }