Age

From Intrigues Wiki
Revision as of 14:20, 19 December 2023 by Tayfunwiki (talk | contribs) (Created page with " == <code>Age</code> Property in Actor Class == === Overview === The <code>Age</code> property within the <code>Actor</code> class serves to provide the age of an actor, an essential attribute in many game scenarios. === Syntax === <syntaxhighlight lang="c#"> /// <summary> /// Gets the age of the actor. /// </summary> public int Age { get; protected set; } </syntaxhighlight> === Description === * Property Type: <code>int</code>. This property is an integer representi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Age Property in Actor Class

Overview

The Age property within the Actor class serves to provide the age of an actor, an essential attribute in many game scenarios.

Syntax

/// <summary>
/// Gets the age of the actor.
/// </summary>
public int Age { get; protected set; }

Description

  • Property Type: int. This property is an integer representing the actor's age.
  • Accessibility: The property is publicly accessible for reading but can only be modified within the Actor class or its derived classes. This protected setter helps to maintain the integrity of the actor's age, preventing unauthorized modifications.
  • Purpose: Age is often a critical attribute in games, used for defining the behavior, appearance, or capabilities of an actor.

Usage

The Age property is used to retrieve the actor's age, which can be a deciding factor in game logic, such as determining eligibility for certain roles, abilities, or actions. It is also vital for scenarios where age progression or regression is a game feature.

Example:

int actorAge = someActor.Age;
if (actorAge >= 18) {
    // Execute logic for adult actor
}

In this example, the actor's age is checked to determine if they are an adult and execute corresponding logic.

Remarks

  • The encapsulation provided by the protected set accessor is crucial to prevent external classes from arbitrarily changing the actor's age, which could disrupt game logic or narrative consistency.
  • In games where age is dynamic (such as aging over time or in response to events), the protected setter allows controlled updates within the game's rules.