DEVLOG#4 RuntimeGameData Day!
Muchas cosas se podrían agregar a esta clase / script, por el momento queda así. Y funciona! Como en otros posts, el código abajo.
Usé un poco de ideas de SOLID / Clean Code (sin extremos y a mi nivel) para refactorizar un poco el código original que era el siguiente:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RuntimeGameData : MonoBehaviour
{
// Player data
public PlayerData playerData;
// FAMILY
public FamilyMember playerMother;
public FamilyMember playerFather;
public FamilyMember playerSister;
public FamilyMember playerBrother;
public FamilyMember playerGrandFather;
public FamilyMember playerGrandMother;
public FamilyMember playerUncle;
public FamilyMember playerAunt;
// FRIENDS
public FriendMember[] playerFriends;
// RELATIONSHIPS
public string[] playerPetName;
public FriendMember playerGirlfriend;
public RandomNPCNameSurnameGenerator randomNPCNameSurnameGenerator;
public void Start()
{
playerFriends = new FriendMember[500]; // Limiting the number of friends
playerData = new PlayerData("Player1", 20, 100, 100, 100, 100, 100, 100, 100, GameEnums.Gender.Male, 100, 100);
}
public void TestRuntimeGameData()
{
playerFriends[0] = new FriendMember("John", 25, GameEnums.Gender.Male, true);
playerGirlfriend = new FriendMember("Priscilla", 30, GameEnums.Gender.Female, true);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha7))
{
TestRuntimeGameData();
playerData.UpdateGold(50); // Example of modifying player data
Debug.Log("Player's Name: " + playerData.name); // Access player name
Debug.Log("Player's Age: " + playerData.age); // Access player age
}
}
[System.Serializable]
public class FamilyMember
{
public string name;
public int age;
public GameEnums.Gender gender;
public bool isAlive;
public FamilyMember(string name, int age, GameEnums.Gender gender)
{
this.name = name;
this.age = age;
this.gender = gender;
this.isAlive = true;
}
}
[System.Serializable]
public class FriendMember
{
public string name;
public int age;
public GameEnums.Gender gender;
public bool isBestFriend;
public FriendMember(string name, int age, GameEnums.Gender gender, bool isBestFriend)
{
this.name = name;
this.age = age;
this.gender = gender;
this.isBestFriend = isBestFriend;
}
}
[System.Serializable]
public class PlayerData
{
public string name;
public int age;
public int gold;
// PLAYER ATTRIBUTES
public int health;
public int IQ;
public int willPower;
public int happiness;
public int appearance;
public int skillWinGame;
public GameEnums.Gender gender;
internal int vitality;
internal int contemptment;
public PlayerData(string name, int age, int gold, int health, int IQ, int willPower, int happiness,
int appearance, int skillWinGame, GameEnums.Gender gender, int vitality, int contemptment)
{
this.name = name;
this.age = age;
this.gold = gold;
this.health = health;
this.IQ = IQ;
this.willPower = willPower;
this.happiness = happiness;
this.appearance = appearance;
this.skillWinGame = skillWinGame;
this.gender = gender;
this.vitality = vitality;
this.contemptment = contemptment;
}
public void UpdateGold(int amount)
{
gold += amount;
}
public void UpdateAge(int years)
{
age += years;
}
}
}
De esta forma se llega a:
Probablemente pase a otra refactorización en otra sesión, pero de momento es una mejora.
Si te apasionan los juegos con una rica narrativa y un diseño profundo, no te pierdas el desarrollo de Medieval Life Sim 2D. ¡Pronto habrá más actualizaciones en el DevLog, que se están poniendo más entretenidas que desarrollar en una cueva! ¡Nos vemos en la próxima entrega!
Get Medieval Life Simulator 2D Pre Alpha
Medieval Life Simulator 2D Pre Alpha
Medieval Life Simulator Game
Status | In development |
Author | Digital Paper Games |
Genre | Simulation |
More posts
- DEVLOG#6 SeedController se integróJan 16, 2025
- DEVLOG#5 Medieval Life Sim 2D: LifeEventGeneratorJan 16, 2025
- DEVLOG#3 Arreglando "Tu Benedict te dejó y perdiste 88 puntos de contemptment.Jan 14, 2025
- DEVLOG #2 Medieval Life Sim 2D: LifeStatsRandomizerJan 10, 2025
- DEVLOG #1 Medieval Life Sim 2D: RandomLogGeneratorJan 10, 2025
Leave a comment
Log in with itch.io to leave a comment.