v1.3.0, Added game saving mechanic (Done)
This commit is contained in:
parent
a0fc2e4790
commit
ae5378090c
@ -119,5 +119,16 @@ namespace Assets.Scripts
|
|||||||
{
|
{
|
||||||
return slime.getExperience();
|
return slime.getExperience();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string saveEnemy()
|
||||||
|
{
|
||||||
|
string result = "";
|
||||||
|
result = result + FileHandler.generateJSON("enemyname", "\"" + enemyname + "\"");
|
||||||
|
if (slime != null)
|
||||||
|
{
|
||||||
|
result = result + ",\r\n" + slime.saveSlime();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,6 +24,7 @@ namespace Assets.Scripts
|
|||||||
}
|
}
|
||||||
sw.Write(data);
|
sw.Write(data);
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
|
sw.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadGame()
|
public static void loadGame()
|
||||||
|
|||||||
@ -80,5 +80,20 @@ namespace Assets.Scripts.Slimes
|
|||||||
{
|
{
|
||||||
return experience;
|
return experience;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string saveSlime()
|
||||||
|
{
|
||||||
|
string result = "";
|
||||||
|
result = result + FileHandler.generateJSON("health", health) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("maxHealth", maxHealth) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("maxSecondary", maxSecondary) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("secondary", secondary) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("strength", strength) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("dexterity", dexterity) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("intelligence", intelligence) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("level", level) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("experience", experience);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -218,6 +218,33 @@ public class Tile : MonoBehaviour
|
|||||||
public string saveTile()
|
public string saveTile()
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
|
GameObject obj;
|
||||||
|
result = result + FileHandler.generateJSON("tiletype", "\"" + tiletype + "\"") + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("positionX", position.x) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("positionY", position.y) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("positionZ", position.z) + ",\r\n";
|
||||||
|
result = result + "\"Objects\": {\r\n";
|
||||||
|
for (int i = 0; i < gameObject.transform.childCount; i++)
|
||||||
|
{
|
||||||
|
obj = gameObject.transform.GetChild(i).gameObject;
|
||||||
|
result = result + "\"Object" + i + "\": {\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("positionX", obj.transform.position.x) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("positionY", obj.transform.position.y) + ",\r\n";
|
||||||
|
result = result + FileHandler.generateJSON("positionZ", obj.transform.position.z) + ",\r\n";
|
||||||
|
if (obj.tag.Contains("Enemy"))
|
||||||
|
{
|
||||||
|
result = result + obj.GetComponent<Enemy>().saveEnemy() + "\r\n}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = result + FileHandler.generateJSON("objectname", "\"" + obj.name + "\"") + "\r\n}";
|
||||||
|
}
|
||||||
|
if (i < gameObject.transform.childCount - 1)
|
||||||
|
{
|
||||||
|
result = result + ",\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = result + "\r\n}";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -182,28 +182,24 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
|
|
||||||
public string saveGame()
|
public string saveGame()
|
||||||
{
|
{
|
||||||
Dictionary<Vector3, GameObject> tiles;
|
|
||||||
GameObject currentTile;
|
|
||||||
string result = "";
|
string result = "";
|
||||||
|
int counter = 0;
|
||||||
result = result + FileHandler.generateJSON("cityAmount", cityAmount) + ",\r\n";
|
result = result + FileHandler.generateJSON("cityAmount", cityAmount) + ",\r\n";
|
||||||
result = result + FileHandler.generateJSON("maxCityAmount", maxCityAmount) + ",\r\n";
|
result = result + FileHandler.generateJSON("maxCityAmount", maxCityAmount) + ",\r\n";
|
||||||
/*result = result + "'playername': " + playername + ",\r\n";
|
result = result + "\"currentTile\": {\r\n";
|
||||||
result = result + "'maxHealth': " + maxHealth + ",\r\n";
|
result = result + currentTile.GetComponent<Tile>().saveTile() + "\r\n},\r\n";
|
||||||
result = result + "'maxSecondary': " + maxSecondary + ",\r\n";
|
result = result + "\"Map\": {\r\n";
|
||||||
result = result + "'secondary': " + secondary + ",\r\n";
|
foreach (GameObject tile in tiles.Values)
|
||||||
result = result + "'health': " + health + ",\r\n";
|
{
|
||||||
result = result + "'strength': " + strength + ",\r\n";
|
result = result + "\"Tile"+counter+"\": {\r\n";
|
||||||
result = result + "'dexterity': " + dexterity + ",\r\n";
|
result = result + tile.GetComponent<Tile>().saveTile() + "\r\n}";
|
||||||
result = result + "'intelligence': " + intelligence + ",\r\n";
|
if (counter < tiles.Count - 1)
|
||||||
result = result + "'level': " + level + ",\r\n";
|
{
|
||||||
result = result + "'experience': " + experience + ",\r\n";
|
result = result + ",\r\n";
|
||||||
result = result + "'maxExperience': " + maxExperience + ",\r\n";
|
}
|
||||||
result = result + "'race': " + race.racename + ",\r\n";
|
counter++;
|
||||||
result = result + "'role': " + role.classname + ",\r\n";
|
}
|
||||||
result = result + "'points': " + points + ",\r\n";
|
result = result + "\r\n}";
|
||||||
result = result + "'isDodging': " + isDodging + ",\r\n";
|
|
||||||
result = result + "'killcount': " + killcount + ",\r\n";
|
|
||||||
result = result + "'difficulty': " + difficulty;*/
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
120
save.json
120
save.json
@ -17,11 +17,125 @@
|
|||||||
"points": 0,
|
"points": 0,
|
||||||
"isDodging": "False",
|
"isDodging": "False",
|
||||||
"killcount": 0,
|
"killcount": 0,
|
||||||
"difficulty": 0,
|
"difficulty": 0
|
||||||
|
|
||||||
},
|
},
|
||||||
"World": {
|
"World": {
|
||||||
|
"cityAmount": 10,
|
||||||
|
"maxCityAmount": 10,
|
||||||
|
"currentTile": {
|
||||||
|
"tiletype": "",
|
||||||
|
"positionX": 0,
|
||||||
|
"positionY": 0,
|
||||||
|
"positionZ": 0,
|
||||||
|
"Objects": {
|
||||||
|
"Object0": {
|
||||||
|
"positionX": -33.3,
|
||||||
|
"positionY": 4.48,
|
||||||
|
"positionZ": 37.8,
|
||||||
|
"objectname": "OakTree"
|
||||||
|
},
|
||||||
|
"Object1": {
|
||||||
|
"positionX": 9.49,
|
||||||
|
"positionY": 4.48,
|
||||||
|
"positionZ": 19.03,
|
||||||
|
"objectname": "PineTree"
|
||||||
|
},
|
||||||
|
"Object2": {
|
||||||
|
"positionX": 30,
|
||||||
|
"positionY": 9.5,
|
||||||
|
"positionZ": 30,
|
||||||
|
"objectname": "HouseIdle"
|
||||||
|
},
|
||||||
|
"Object3": {
|
||||||
|
"positionX": -26.1,
|
||||||
|
"positionY": 1.28,
|
||||||
|
"positionZ": 0,
|
||||||
|
"objectname": "StoneBasic"
|
||||||
|
},
|
||||||
|
"Object4": {
|
||||||
|
"positionX": 0,
|
||||||
|
"positionY": 1.28,
|
||||||
|
"positionZ": -38.56,
|
||||||
|
"objectname": "StoneBasic (1)"
|
||||||
|
},
|
||||||
|
"Object5": {
|
||||||
|
"positionX": -29.6,
|
||||||
|
"positionY": 4.48,
|
||||||
|
"positionZ": -27.38,
|
||||||
|
"objectname": "OakTree (1)"
|
||||||
|
},
|
||||||
|
"Object6": {
|
||||||
|
"positionX": 28.87,
|
||||||
|
"positionY": 4.479999,
|
||||||
|
"positionZ": -12.93,
|
||||||
|
"objectname": "PineTree (1)"
|
||||||
|
},
|
||||||
|
"Object7": {
|
||||||
|
"positionX": 30,
|
||||||
|
"positionY": 9.5,
|
||||||
|
"positionZ": -30,
|
||||||
|
"objectname": "HouseIdle (1)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Map": {
|
||||||
|
"Tile0": {
|
||||||
|
"tiletype": "",
|
||||||
|
"positionX": 0,
|
||||||
|
"positionY": 0,
|
||||||
|
"positionZ": 0,
|
||||||
|
"Objects": {
|
||||||
|
"Object0": {
|
||||||
|
"positionX": -33.3,
|
||||||
|
"positionY": 4.48,
|
||||||
|
"positionZ": 37.8,
|
||||||
|
"objectname": "OakTree"
|
||||||
|
},
|
||||||
|
"Object1": {
|
||||||
|
"positionX": 9.49,
|
||||||
|
"positionY": 4.48,
|
||||||
|
"positionZ": 19.03,
|
||||||
|
"objectname": "PineTree"
|
||||||
|
},
|
||||||
|
"Object2": {
|
||||||
|
"positionX": 30,
|
||||||
|
"positionY": 9.5,
|
||||||
|
"positionZ": 30,
|
||||||
|
"objectname": "HouseIdle"
|
||||||
|
},
|
||||||
|
"Object3": {
|
||||||
|
"positionX": -26.1,
|
||||||
|
"positionY": 1.28,
|
||||||
|
"positionZ": 0,
|
||||||
|
"objectname": "StoneBasic"
|
||||||
|
},
|
||||||
|
"Object4": {
|
||||||
|
"positionX": 0,
|
||||||
|
"positionY": 1.28,
|
||||||
|
"positionZ": -38.56,
|
||||||
|
"objectname": "StoneBasic (1)"
|
||||||
|
},
|
||||||
|
"Object5": {
|
||||||
|
"positionX": -29.6,
|
||||||
|
"positionY": 4.48,
|
||||||
|
"positionZ": -27.38,
|
||||||
|
"objectname": "OakTree (1)"
|
||||||
|
},
|
||||||
|
"Object6": {
|
||||||
|
"positionX": 28.87,
|
||||||
|
"positionY": 4.479999,
|
||||||
|
"positionZ": -12.93,
|
||||||
|
"objectname": "PineTree (1)"
|
||||||
|
},
|
||||||
|
"Object7": {
|
||||||
|
"positionX": 30,
|
||||||
|
"positionY": 9.5,
|
||||||
|
"positionZ": -30,
|
||||||
|
"objectname": "HouseIdle (1)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Loading…
x
Reference in New Issue
Block a user