{"id":53,"date":"2023-03-16T02:53:29","date_gmt":"2023-03-16T02:53:29","guid":{"rendered":"https:\/\/www.brigadiercomputers.com\/index.php\/2023\/03\/16\/an-entity-class-that-stores-rpg-d6-stats-position-state-and-other-properties\/"},"modified":"2023-03-16T02:53:29","modified_gmt":"2023-03-16T02:53:29","slug":"an-entity-class-that-stores-rpg-d6-stats-position-state-and-other-properties","status":"publish","type":"post","link":"https:\/\/www.brigadiercomputers.com\/index.php\/2023\/03\/16\/an-entity-class-that-stores-rpg-d6-stats-position-state-and-other-properties\/","title":{"rendered":"An Entity Class that stores RPG D6 stats, position, state, and other Properties"},"content":{"rendered":"<p>Here&#8217;s an example implementation of an entity class in C++ that stores RPG d6 stats, position, state, speed, and direction:<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\">\n<!--more-->\n<\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-cpp\"><span class=\"hljs-meta\">#<span class=\"hljs-keyword\">include<\/span> <span class=\"hljs-string\">&lt;iostream&gt;<\/span><\/span><\/p>\n<p><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">Entity<\/span> {<br \/>\n<span class=\"hljs-keyword\">public<\/span>:<br \/>\n    <span class=\"hljs-keyword\">struct<\/span> <span class=\"hljs-title class_\">Stats<\/span> {<br \/>\n        <span class=\"hljs-type\">int<\/span> strength;<br \/>\n        <span class=\"hljs-type\">int<\/span> dexterity;<br \/>\n        <span class=\"hljs-type\">int<\/span> constitution;<br \/>\n        <span class=\"hljs-type\">int<\/span> intelligence;<br \/>\n        <span class=\"hljs-type\">int<\/span> wisdom;<br \/>\n        <span class=\"hljs-type\">int<\/span> charisma;<br \/>\n    };<\/p>\n<p>    <span class=\"hljs-keyword\">enum class<\/span> <span class=\"hljs-title class_\">State<\/span> {<br \/>\n        IDLE,<br \/>\n        MOVING,<br \/>\n        ATTACKING,<br \/>\n        DEFENDING<br \/>\n    };<\/p>\n<p>    <span class=\"hljs-built_in\">Entity<\/span>(<span class=\"hljs-type\">int<\/span> x, <span class=\"hljs-type\">int<\/span> y, <span class=\"hljs-type\">float<\/span> speed, <span class=\"hljs-type\">float<\/span> direction) :<br \/>\n        <span class=\"hljs-built_in\">m_positionX<\/span>(x), <span class=\"hljs-built_in\">m_positionY<\/span>(y), <span class=\"hljs-built_in\">m_speed<\/span>(speed), <span class=\"hljs-built_in\">m_direction<\/span>(direction)<br \/>\n    {<br \/>\n        <span class=\"hljs-comment\">\/\/ Initialize the d6 stats to default values<\/span><br \/>\n        m_stats.strength = <span class=\"hljs-number\">3<\/span>;<br \/>\n        m_stats.dexterity = <span class=\"hljs-number\">3<\/span>;<br \/>\n        m_stats.constitution = <span class=\"hljs-number\">3<\/span>;<br \/>\n        m_stats.intelligence = <span class=\"hljs-number\">3<\/span>;<br \/>\n        m_stats.wisdom = <span class=\"hljs-number\">3<\/span>;<br \/>\n        m_stats.charisma = <span class=\"hljs-number\">3<\/span>;<\/p>\n<p>        <span class=\"hljs-comment\">\/\/ Set the initial state to idle<\/span><br \/>\n        m_state = State::IDLE;<br \/>\n    }<\/p>\n<p>    <span class=\"hljs-comment\">\/\/ Getter functions for retrieving entity stats, position, and state<\/span><br \/>\n    <span class=\"hljs-function\">Stats <span class=\"hljs-title\">getStats<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-type\">const<\/span> <\/span>{ <span class=\"hljs-keyword\">return<\/span> m_stats; }<br \/>\n    <span class=\"hljs-function\"><span class=\"hljs-type\">int<\/span> <span class=\"hljs-title\">getPositionX<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-type\">const<\/span> <\/span>{ <span class=\"hljs-keyword\">return<\/span> m_positionX; }<br \/>\n    <span class=\"hljs-function\"><span class=\"hljs-type\">int<\/span> <span class=\"hljs-title\">getPositionY<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-type\">const<\/span> <\/span>{ <span class=\"hljs-keyword\">return<\/span> m_positionY; }<br \/>\n    <span class=\"hljs-function\">State <span class=\"hljs-title\">getState<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-type\">const<\/span> <\/span>{ <span class=\"hljs-keyword\">return<\/span> m_state; }<\/p>\n<p>    <span class=\"hljs-comment\">\/\/ Setter functions for changing the entity position, state, speed, and direction<\/span><br \/>\n    <span class=\"hljs-function\"><span class=\"hljs-type\">void<\/span> <span class=\"hljs-title\">setPosition<\/span><span class=\"hljs-params\">(<span class=\"hljs-type\">int<\/span> x, <span class=\"hljs-type\">int<\/span> y)<\/span> <\/span>{ m_positionX = x; m_positionY = y; }<br \/>\n    <span class=\"hljs-function\"><span class=\"hljs-type\">void<\/span> <span class=\"hljs-title\">setState<\/span><span class=\"hljs-params\">(State state)<\/span> <\/span>{ m_state = state; }<br \/>\n    <span class=\"hljs-function\"><span class=\"hljs-type\">void<\/span> <span class=\"hljs-title\">setSpeed<\/span><span class=\"hljs-params\">(<span class=\"hljs-type\">float<\/span> speed)<\/span> <\/span>{ m_speed = speed; }<br \/>\n    <span class=\"hljs-function\"><span class=\"hljs-type\">void<\/span> <span class=\"hljs-title\">setDirection<\/span><span class=\"hljs-params\">(<span class=\"hljs-type\">float<\/span> direction)<\/span> <\/span>{ m_direction = direction; }<\/p>\n<p><span class=\"hljs-keyword\">private<\/span>:<br \/>\n    Stats m_stats;<br \/>\n    <span class=\"hljs-type\">int<\/span> m_positionX;<br \/>\n    <span class=\"hljs-type\">int<\/span> m_positionY;<br \/>\n    State m_state;<br \/>\n    <span class=\"hljs-type\">float<\/span> m_speed;<br \/>\n    <span class=\"hljs-type\">float<\/span> m_direction;<br \/>\n};<\/p>\n<p><span class=\"hljs-function\"><span class=\"hljs-type\">int<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">()<\/span> <\/span>{<br \/>\n    <span class=\"hljs-comment\">\/\/ Create a new entity at position (0, 0) with speed 2.0 and direction 0.5<\/span><br \/>\n    <span class=\"hljs-function\">Entity <span class=\"hljs-title\">entity<\/span><span class=\"hljs-params\">(<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">2.0f<\/span>, <span class=\"hljs-number\">0.5f<\/span>)<\/span><\/span>;<\/p>\n<p>    <span class=\"hljs-comment\">\/\/ Get and print the entity's initial stats and state<\/span><br \/>\n    Entity::Stats stats = entity.<span class=\"hljs-built_in\">getStats<\/span>();<br \/>\n    std::cout &lt;&lt; <span class=\"hljs-string\">\"Entity stats: \"<\/span><br \/>\n              &lt;&lt; stats.strength &lt;&lt; <span class=\"hljs-string\">\" \"<\/span><br \/>\n              &lt;&lt; stats.dexterity &lt;&lt; <span class=\"hljs-string\">\" \"<\/span><br \/>\n              &lt;&lt; stats.constitution &lt;&lt; <span class=\"hljs-string\">\" \"<\/span><br \/>\n              &lt;&lt; stats.intelligence &lt;&lt; <span class=\"hljs-string\">\" \"<\/span><br \/>\n              &lt;&lt; stats.wisdom &lt;&lt; <span class=\"hljs-string\">\" \"<\/span><br \/>\n              &lt;&lt; stats.charisma &lt;&lt; std::endl;<br \/>\n    std::cout &lt;&lt; <span class=\"hljs-string\">\"Entity state: \"<\/span> &lt;&lt; <span class=\"hljs-built_in\">static_cast<\/span>&lt;<span class=\"hljs-type\">int<\/span>&gt;(entity.<span class=\"hljs-built_in\">getState<\/span>()) &lt;&lt; std::endl;<\/p>\n<p>    <span class=\"hljs-comment\">\/\/ Update the entity's position and state<\/span><br \/>\n    entity.<span class=\"hljs-built_in\">setPosition<\/span>(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">10<\/span>);<br \/>\n    entity.<span class=\"hljs-built_in\">setState<\/span>(Entity::State::MOVING);<\/p>\n<p>    <span class=\"hljs-comment\">\/\/ Get and print the entity's updated position and state<\/span><br \/>\n    std::cout &lt;&lt; <span class=\"hljs-string\">\"Entity position: (\"<\/span> &lt;&lt; entity.<span class=\"hljs-built_in\">getPositionX<\/span>() &lt;&lt; <span class=\"hljs-string\">\", \"<\/span> &lt;&lt; entity.<span class=\"hljs-built_in\">getPositionY<\/span>() &lt;&lt; <span class=\"hljs-string\">\")\"<\/span> &lt;&lt; std::endl;<br \/>\n    std::cout &lt;&lt; <span class=\"hljs-string\">\"Entity state: \"<\/span> &lt;&lt; <span class=\"hljs-built_in\">static_cast<\/span>&lt;<span class=\"hljs-type\">int<\/span>&gt;(entity.<span class=\"hljs-built_in\">getState<\/span>()) &lt;&lt; std::endl;<\/p>\n<p>    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">0<\/span>;<br \/>\n}<br \/>\n<\/code><\/div>\n<\/div>\n<p>In this example, we define a C++ class called <code>Entity<\/code> that has private member variables to store the entity&#8217;s d6 stats, position, state, speed, and direction. The <code>Stats<\/code> struct is nested inside the <code>Entity<\/code> class to make it more organized. The <code>State<\/code> enum class defines the possible states that an entity can be in (idle, moving, attacking, defending).<\/p>\n<p>In the constructor, we initialize the position, speed, and direction of the entity. We also initialize the d6 stats to default values<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s an example implementation of an entity class in C++ that stores RPG d6 stats, position, state, speed, and direction:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-development"],"_links":{"self":[{"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":0,"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.brigadiercomputers.com\/index.php\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}