Skip to content

Instantly share code, notes, and snippets.

@su8
Created March 30, 2025 10:49
Show Gist options
  • Save su8/36f577fc9533a94629552ff136e721cc to your computer and use it in GitHub Desktop.
Save su8/36f577fc9533a94629552ff136e721cc to your computer and use it in GitHub Desktop.
https://codereview.stackexchange.com/questions/27986/text-based-rpg-game-using-classes
<!DOCTYPE html>
<html itemscope itemtype="https://schema.org/QAPage" class="html__responsive " lang="en">
<head>
<title>c++ - Text-based RPG game using classes - Code Review Stack Exchange</title>
<link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/codereview/Img/favicon.ico?v=98c717f8afd1">
<link rel="apple-touch-icon" href="https://cdn.sstatic.net/Sites/codereview/Img/apple-touch-icon.png?v=0a72875519a4">
<link rel="image_src" href="https://cdn.sstatic.net/Sites/codereview/Img/apple-touch-icon.png?v=0a72875519a4">
<link rel="search" type="application/opensearchdescription+xml" title="Code Review Stack Exchange" href="/opensearch.xml">
<link rel="canonical" href="https://codereview.stackexchange.com/questions/27986/text-based-rpg-game-using-classes" />
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0">
<meta property="og:type" content= "website" />
<meta property="og:url" content="https://codereview.stackexchange.com/questions/27986/text-based-rpg-game-using-classes"/>
<meta property="og:site_name" content="Code Review Stack Exchange" />
<meta property="og:image" itemprop="image primaryImageOfPage" content="https://cdn.sstatic.net/Sites/codereview/Img/[email protected]?v=a4f1c838ba2c" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:domain" content="codereview.stackexchange.com"/>
<meta name="twitter:title" property="og:title" itemprop="name" content="Text-based RPG game using classes" />
<meta name="twitter:description" property="og:description" itemprop="description" content="I am studying for a degree in &quot;Bachelor of Engineering in Information and Communication Technologies.&quot; I am currently on vacation, just after we started learning C&#x2B;&#x2B; at the end of the semester. I ..." />
<script id="webpack-public-path" type="text/uri-list">https://cdn.sstatic.net/</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script defer src="https://cdn.sstatic.net/Js/third-party/npm/@stackoverflow/stacks/dist/js/stacks.min.js?v=90a447add688"></script>
<script src="https://cdn.sstatic.net/Js/stub.en.js?v=31c1a92afca8"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/stacks.css?v=d6a266655a25">
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codereview/primary.css?v=056f83af1eef">
<link rel="alternate" type="application/atom+xml" title="Feed for question &#x27;Text-based RPG game using classes&#x27;" href="/feeds/question/27986">
<script defer src="https://cdn.sstatic.net/Js/copy-transpiled.en.js?v=621e16cc71a9"></script><script type="application/json" data-role="module-args" data-module-name="misc/copy/copy.mod">{"sortType":4,"numberOfVisibleAnswers":4,"trackQuestions":true,"trackArticles":false,"userReputation":1,"userReputationBand":1,"sendPrizmEvent":false,"sendAEHEvent":true}</script> <script>
StackExchange.ready(function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.initSnippetRenderer();
});
StackExchange.using("postValidation", function () {
StackExchange.postValidation.initOnBlurAndSubmit($('#post-form'), 2, 'answer');
});
StackExchange.question.init({votesCast:[],autoShowCommentHelp:true,showAnswerHelp:true,totalCommentCount:3,shownCommentCount:3,enableTables:true,questionId:27986});
styleCode();
StackExchange.realtime.subscribeToQuestion('196', '27986');
StackExchange.using("gps", function () { StackExchange.gps.trackOutboundClicks('#content', '.js-post-body'); });
});
</script>
<link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Shared/Channels/channels.css?v=5981bb1a5bd7">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
"HTML-CSS": {
preferredFont: "TeX",
availableFonts: ["STIX", "TeX"],
linebreaks: { automatic: true },
EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
},
tex2jax: {
inlineMath: [["\\$", "\\$"]],
displayMath: [["$$", "$$"], ["\\[", "\\]"]],
processEscapes: true,
ignoreClass: "tex2jax_ignore|dno"
},
TeX: {
extensions: ["begingroup.js"],
noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } },
Macros: { href: "{}" }
},
messageStyle: "none",
styles: { ".MathJax_Display, .MathJax_Preview, .MathJax_Preview > *": { "background": "inherit" } },
SEEditor: "mathjaxEditing"
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_HTML-full"></script>
<script>
StackExchange.ready(function () {
StackExchange.realtime.init('wss://qa.sockets.stackexchange.com');
StackExchange.realtime.subscribeToReputationNotifications('196');
StackExchange.realtime.subscribeToTopBarNotifications('196');
});
</script>
<script type="application/json" data-role="module-args" data-module-name="Shared/options.mod">{"options":{"locale":"en","serverTime":1743331693,"routeName":"Questions/Show","stackAuthUrl":"https://stackauth.com","networkMetaHostname":"meta.stackexchange.com","site":{"name":"Code Review Stack Exchange","description":"Q\u0026A for peer programmer code reviews","isNoticesTabEnabled":true,"enableNewTagCreationWarning":false,"insertSpaceAfterNameTabCompletion":false,"id":196,"cookieDomain":".stackexchange.com","childUrl":"https://codereview.meta.stackexchange.com","negativeVoteScoreFloor":null,"enableSocialMediaInSharePopup":true,"protocol":"https"},"user":{"fkey":"1bdb2a6f769206fb1bc17489607dec3bc94f3d71366944559446c3c6061a5f99","tid":"f30baf9e-7dfe-455c-b0c9-f6d77770e0ef","rep":1,"isRegistered":true,"userType":3,"userId":289986,"accountId":41080829,"gravatar":"\u003cdiv class=\u0022gravatar-wrapper-32\u0022\u003e\u003cimg src=\u0022https://www.gravatar.com/avatar/36a7dac282035037e728f06424d47f96?s=32\u0026amp;d=identicon\u0026amp;r=PG\u0026amp;f=y\u0026amp;so-version=2\u0022 alt=\u0022john sean\u0026#39;s user avatar\u0022 width=\u002232\u0022 height=\u002232\u0022 class=\u0022bar-sm\u0022\u003e\u003c/div\u003e","profileUrl":"https://codereview.stackexchange.com/users/289986/john-sean","canSeeDeletedPosts":false},"realtime":{"newest":true,"active":true,"tagged":true,"staleDisconnectIntervalInHours":0},"events":{"postType":{"question":1},"postEditionSection":{"title":1,"body":2,"tags":3}}}}</script>
<script type="application/json" data-role="module-args" data-module-name="Shared/settings.mod">{"settings":{"questions":{"enableSavesFeature":true,"maxTitleSize":150,"enableQuestionTitleLengthLiveWarning":true,"questionTitleLengthStartLiveWarningChars":50},"paths":{"jQueryUIJSPath":"https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js","jQueryUICSSPath":"https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/themes/smoothness/jquery-ui.css"},"legal":{"oneTrustTCFConfigId":"cb0f3c87-b769-4e66-bbaa-377f9194216d","useCustomConsent":false},"flags":{"allowRetractingFlags":true,"allowRetractingCommentFlags":true},"search":{},"mentions":{"maxNumUsersInDropdown":50},"intercom":{"appId":"inf0secd"},"site":{"allowImageUploads":true,"styleCode":true,"stacksEditorPreviewEnabled":true,"forceHttpsImages":true,"enableUserHovercards":true,"enableImageHttps":true},"questionLinkTitleReplacement":{"maxNumberOfSitesProcessed":10,"maxReplacementsPerSite":20},"snippets":{"snippetsEnabled":true,"renderDomain":"stacksnippets.net"},"elections":{"opaVoteResultsBaseUrl":"https://www.opavote.com/results/"},"userMessaging":{"showNewFeatureNotice":true},"subscriptions":{"defaultFreemiumMaxTrueUpSeats":50,"defaultMaxTrueUpSeats":1000,"defaultBasicMaxTrueUpSeats":250},"image":{"maxImageUploadSizeInBytesAnimatedGif":2097152,"maxImageUploadSizeInBytes":10485760},"markdown":{"enableTables":true},"auth":{"oauthInPopup":true},"tags":{},"accounts":{"currentPasswordRequiredForChangingStackIdPassword":true},"comments":{}}}</script>
<script>StackExchange.init();</script>
<script>
StackExchange.using.setCacheBreakers({"Js/adops.en.js":"6da43f5e0a84","Js/ask.en.js":"","Js/begin-edit-event.en.js":"20edbaccceae","Js/copy-transpiled.en.js":"621e16cc71a9","Js/events.en.js":"","Js/explore-qlist.en.js":"ee2a4f8c3992","Js/full-anon.en.js":"c893ac586e11","Js/full.en.js":"8a98ae1f98ba","Js/highlightjs-loader.en.js":"a3e36fe85053","Js/inline-tag-editing.en.js":"8517756a2cb6","Js/keyboard-shortcuts.en.js":"c255a5a5979b","Js/markdown-it-loader.en.js":"781aa77e9602","Js/mentions-transpiled.en.js":"bcadb48d3570","Js/moderator.en.js":"60e8c0e0f76f","Js/postCollections-transpiled.en.js":"9f7a87e8cf0d","Js/post-validation.en.js":"44d59ccfc490","Js/question-editor.en.js":"","Js/review-v2-transpiled.en.js":"c9e05881f8ab","Js/revisions.en.js":"9dd135bb585f","Js/stacks-editor.en.js":"1139e46a5d9a","Js/tageditor.en.js":"5b8f289d02ef","Js/tageditornew.en.js":"ca426894aed0","Js/tagsuggestions.en.js":"762b96a1ae1f","Js/unlimited-transpiled.en.js":"8713a979101d","Js/wmd.en.js":"ef631802355e","Js/mathjax-editing.v3.en.js":"4f38b81017dc","Js/mathjax-editing.en.js":"2581d730d948","Js/snippet-javascript-codemirror.en.js":"0f42dbb990fa"});
StackExchange.using("gps", function() {
StackExchange.gps.init(false);
});
</script>
<noscript id="noscript-css"><style>body,.s-topbar{margin-top:1.9em}</style></noscript>
</head>
<body class="question-page unified-theme">
<div id="notify-container"></div>
<div id="custom-header"></div>
<header class="s-topbar ps-fixed t0 l0 js-top-bar">
<a href="#content" class="s-topbar--skip-link">Skip to main content</a>
<div class="s-topbar--container">
<a href="#" class="s-topbar--menu-btn js-left-sidebar-toggle" role="menuitem" aria-haspopup="true" aria-controls="left-sidebar" aria-expanded="false"><span></span></a>
<div class="topbar-dialog leftnav-dialog js-leftnav-dialog dno">
<div class="left-sidebar js-unpinned-left-sidebar" data-can-be="left-sidebar" data-is-here-when="sm"></div>
</div>
<a href="#" class="s-topbar--logo network-logo js-gps-track js-network-logo"
data-gps-track="stack_exchange_popup.show" role="menuitem" aria-haspopup="true" aria-controls="topbar-network-logo-dialog" aria-expanded="false">
<svg aria-hidden="true" class="native mtn1 svg-icon iconSEAlternativeSm" width="107" height="15" viewBox="0 0 107 15"><path fill="#FEFEFE" d="m48.41 11.93-1.96-3.2-1.04 1.16v2.04h-1.42V2.18h1.42v6.01L48.14 5h1.72l-2.44 2.7 2.74 4.22zm-7.06.08c-1.59 0-3.14-.96-3.14-3.56s1.55-3.54 3.14-3.54c.97 0 1.65.27 2.31.97l-.97.93c-.44-.48-.79-.66-1.34-.66q-.84.01-1.3.62c-.31.38-.42.87-.42 1.68s.1 1.32.41 1.7c.3.4.76.62 1.3.62.56 0 .9-.18 1.35-.66l.97.92c-.66.7-1.34.98-2.31.98m-5.66-3.15h-1.65c-.83 0-1.26.37-1.26 1s.4.99 1.3.99c.53 0 .93-.04 1.3-.4q.32-.29.31-1.03zm.03 3.07v-.63c-.51.5-1 .71-1.87.71s-1.46-.2-1.89-.63a2 2 0 0 1-.55-1.49c0-1.16.82-2 2.42-2h1.86v-.5c0-.87-.44-1.3-1.54-1.3-.77 0-1.15.18-1.54.68l-.92-.86c.66-.77 1.35-1 2.52-1q2.9 0 2.9 2.38v4.64zm-5.9 0c-1.32 0-1.93-.93-1.93-1.93V6.18h-.8V5.1h.8V3h1.41v2.1h1.36v1.07H29.3v3.75c0 .5.25.81.78.81h.58v1.2zm-6.33.08c-1.48 0-2.55-.34-3.49-1.28l1-.98c.72.72 1.51.94 2.52.94 1.3 0 2.04-.55 2.04-1.5q0-.65-.39-1.01c-.25-.23-.5-.33-1.08-.41l-1.16-.17a3.4 3.4 0 0 1-1.88-.78 2.4 2.4 0 0 1-.72-1.86c0-1.7 1.25-2.86 3.3-2.86 1.3 0 2.22.33 3.07 1.1l-.96.94a3 3 0 0 0-2.15-.75c-1.16 0-1.8.65-1.8 1.52q-.02.54.37.9c.25.22.65.38 1.11.45l1.13.17c.91.13 1.42.35 1.84.72.54.47.8 1.17.8 2 0 1.8-1.48 2.86-3.55 2.86"/><path fill="#2F96E8" d="M104.16 7.09c-.2-.42-.6-.74-1.2-.74s-.99.32-1.18.74c-.1.25-.15.44-.16.75h2.7a2 2 0 0 0-.16-.75m-2.54 1.96c0 .9.56 1.57 1.55 1.57.78 0 1.16-.21 1.61-.66l1.08 1.04a3.4 3.4 0 0 1-2.7 1.11c-1.68 0-3.29-.76-3.29-3.62 0-2.3 1.26-3.6 3.1-3.6 1.97 0 3.1 1.44 3.1 3.37v.79zm-5.48-2.57C95.1 6.48 95 7.37 95 8.3s.1 1.85 1.15 1.85 1.18-.91 1.18-1.85c0-.93-.13-1.82-1.18-1.82m-.17 8.22c-1.1 0-1.84-.21-2.58-.92l1.1-1.11c.4.38.8.54 1.4.54 1.06 0 1.43-.74 1.43-1.46v-.72c-.47.51-1 .7-1.7.7-.69 0-1.29-.23-1.68-.62-.67-.66-.73-1.57-.73-2.8 0-1.24.06-2.13.73-2.8.4-.39 1-.62 1.7-.62.75 0 1.24.2 1.73.75v-.67h1.72v6.8c0 1.7-1.21 2.93-3.12 2.93m-5.76-2.67V7.76c0-.96-.61-1.28-1.17-1.28s-1.18.32-1.18 1.28v4.27h-1.78V4.97h1.73v.65a2.4 2.4 0 0 1 1.78-.73q1.07.02 1.67.62c.58.57.73 1.24.73 2v4.52zm-7.1-2.98h-1.4c-.64 0-1 .3-1 .8 0 .49.33.81 1.02.81.5 0 .8-.04 1.12-.34q.28-.25.26-.89zm.04 2.98v-.6c-.48.47-.93.67-1.74.67q-1.2 0-1.82-.62c-.38-.4-.58-.97-.58-1.59 0-1.12.77-2.05 2.42-2.05h1.68V7.5c0-.77-.38-1.11-1.32-1.11-.68 0-1 .16-1.37.58l-1.13-1.1c.7-.75 1.38-.97 2.57-.97q3 0 3.02 2.5v4.64zm-6.93 0v-4.3c0-.94-.6-1.25-1.15-1.25-.56 0-1.15.32-1.15 1.24v4.31h-1.77V2.38h1.77v3.24a2.4 2.4 0 0 1 1.7-.73c1.56 0 2.38 1.08 2.38 2.57v4.57zm-6.96.08c-1.42 0-3.18-.76-3.18-3.62 0-2.85 1.76-3.6 3.18-3.6.98 0 1.72.3 2.34.95l-1.2 1.2c-.36-.4-.68-.56-1.14-.56q-.62-.01-1.01.46c-.27.33-.4.8-.4 1.55s.13 1.24.4 1.58q.39.46 1 .46c.47 0 .79-.16 1.15-.56l1.2 1.18c-.62.65-1.36.96-2.34.96m-5.53-.08-1.3-2.11-1.3 2.11H59l2.45-3.6-2.35-3.46h2.12L62.42 7l1.21-2.02h2.13L63.4 8.43l2.46 3.6zm-11.75 0V2.06h6.6V3.8h-4.65v2.33h3.96v1.74h-3.96v2.42h4.65v1.74z"/><path fill="#8FD8F7" d="M0 3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2z"/><path fill="#155397" d="M12 10H0c0 1.1.9 2 2 2h5v3l3-3a2 2 0 0 0 2-2"/><path fill="#46A2D9" d="M0 4h12v2H0z"/><path fill="#2D6DB5" d="M0 7h12v2H0z"/></svg>
</a>
<div class="topbar-dialog network-logo-dialog js-network-logo-dialog dno" id="topbar-network-logo-dialog" role="dialog" aria-labelledby="topbar-network-logo-dialog-title" aria-describedby="topbar-network-logo-dialog-body">
<div class="dialog-content">
<h4 class="bold" id="topbar-network-logo-dialog-title">Stack Exchange Network</h4>
<p id="topbar-network-logo-dialog-body">
Stack Exchange network consists of 183 Q&amp;A communities including <a href="https://stackoverflow.com">Stack Overflow</a>, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
</p>
<a class="s-btn s-btn__filled" href="https://stackexchange.com"
data-gps-track="stack_exchange_popup.click">Visit Stack Exchange</a>
<button class="s-btn s-btn__muted p0 ps-absolute t16 r16 js-close-button" aria-label="Close"><svg aria-hidden="true" class="svg-icon iconClear" width="18" height="18" viewBox="0 0 18 18"><path d="M15 4.41 13.59 3 9 7.59 4.41 3 3 4.41 7.59 9 3 13.59 4.41 15 9 10.41 13.59 15 15 13.59 10.41 9z"/></svg></button>
</div>
</div>
<form id="search" role="search" action=/search class="s-topbar--searchbar js-searchbar " autocomplete="off">
<div class="s-topbar--searchbar--input-group">
<input name="q"
type="text"
role="combobox"
placeholder="Search on Code Review&#x2026;"
value=""
autocomplete="off"
maxlength="240"
class="s-input s-input__search js-search-field wmn1 "
aria-label="Search"
aria-controls="top-search"
data-controller="s-popover"
data-action="focus->s-popover#show"
data-s-popover-placement="bottom-start" />
<svg aria-hidden="true" class="s-input-icon s-input-icon__search svg-icon iconSearch" width="18" height="18" viewBox="0 0 18 18"><path d="m18 16.5-5.14-5.18h-.35a7 7 0 1 0-1.19 1.19v.35L16.5 18zM12 7A5 5 0 1 1 2 7a5 5 0 0 1 10 0"/></svg>
<div class="s-popover p0 wmx100 wmn4 sm:wmn-initial js-top-search-popover" id="top-search" role="menu">
<div class="s-popover--arrow"></div>
<div class="s-popover--content">
<div class="js-spinner p24 d-flex ai-center jc-center d-none">
<div class="s-spinner s-spinner__sm fc-orange-400">
<div class="v-visible-sr">Loading&#x2026;</div>
</div>
</div>
<span class="v-visible-sr js-screen-reader-info"></span>
<div class="js-ac-results overflow-y-auto hmx3 d-none"></div>
<div class="js-search-hints" aria-describedby="Tips for searching"></div>
</div>
</div>
</div>
</form>
<nav class="h100 ml-auto overflow-x-auto pr12" aria-label="Topbar">
<ol class="s-topbar--content" role="menubar">
<li role="none"><button class="s-topbar--item s-btn s-btn__icon s-btn__muted d-none sm:d-inline-flex js-searchbar-trigger" role="menuitem" aria-label="Search" aria-haspopup="true" aria-controls="search" title="Click to show search"><svg aria-hidden="true" class="svg-icon iconSearch" width="18" height="18" viewBox="0 0 18 18"><path d="m18 16.5-5.14-5.18h-.35a7 7 0 1 0-1.19 1.19v.35L16.5 18zM12 7A5 5 0 1 1 2 7a5 5 0 0 1 10 0"/></svg></button></li>
<li role="none">
<a href="/users/289986/john-sean" id="user-profile-button" class="s-topbar--item s-user-card s-user-card__small m0 px12 js-gps-track" role="menuitem" data-gps-track="profile_summary.click()">
<div class="s-avatar s-avatar__24 s-user-card--avatar sm:m0" title="john sean"><img src="https://www.gravatar.com/avatar/36a7dac282035037e728f06424d47f96?s=48&amp;d=identicon&amp;r=PG&amp;f=y&amp;so-version=2" alt="john sean&#39;s user avatar" width="24" height="24" class="bar-sm s-avatar--image js-avatar-me"></div> <span class="v-visible-sr">john sean</span>
<div class="s-user-card--info sm:d-none">
<ul class="s-user-card--awards">
<li class="s-user-card--rep js-header-rep" title="your reputation: 1" aria-hidden="true">
1
<span class="v-visible-sr">, 1 reputation</span>
</li>
<li class="-badges mr0">
</li>
</ul>
</div>
</a>
</li>
<li role="none">
<a href="https://stackexchange.com/users/41080829?tab=inbox" class="s-topbar--item js-inbox-button" aria-label="Inbox (1 unread message)"
role="menuitem" title="You have unread inbox messages" aria-haspopup="true" aria-expanded="false" data-unread-count="1">
<svg aria-hidden="true" class="svg-icon iconInbox" width="20" height="18" viewBox="0 0 20 18"><path d="M4.63 1h10.56a2 2 0 0 1 1.94 1.35L20 10.79V15a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-4.21l2.78-8.44c.25-.8 1-1.36 1.85-1.35m8.28 12 2-2h2.95l-2.44-7.32a1 1 0 0 0-.95-.68H5.35a1 1 0 0 0-.95.68L1.96 11h2.95l2 2z"/></svg>
<span class="s-activity-indicator s-activity-indicator__danger js-unread-count">1</span>
</a>
</li>
<li role="none">
<a href="https://stackexchange.com/users/41080829?tab=reputation" class="s-topbar--item js-achievements-button" data-unread-class="fc-success"
aria-label="Achievements" role="menuitem" title="Recent achievements: reputation, badges, and privileges earned" aria-haspopup="true" aria-expanded="false" data-unread-count="0" data-lit-up="false">
<svg aria-hidden="true" class="svg-icon iconAchievements" width="18" height="18" viewBox="0 0 18 18"><path d="M15 2V1H3v1H0v4c0 1.6 1.4 3 3 3v1c.4 1.5 3 2.6 5 3v2H5s-1 1.5-1 2h10c0-.4-1-2-1-2h-3v-2c2-.4 4.6-1.5 5-3V9c1.6-.2 3-1.4 3-3V2zM3 7c-.5 0-1-.5-1-1V4h1zm8.4 2.5L9 8 6.6 9.4l1-2.7L5 5h3l1-2.7L10 5h2.8l-2.3 1.8 1 2.7zM16 6c0 .5-.5 1-1 1V4h1z"/></svg>
<span class="s-activity-indicator s-activity-indicator__success js-unread-count d-none">+0</span>
</a>
</li>
<li role="none">
<a href="/help" class="s-topbar--item js-help-button" role="menuitem" title="Help Center and other resources" aria-haspopup="true" aria-controls="topbar-help-dialog"
data-ga="[&quot;top navigation&quot;,&quot;help menu click&quot;,null,null,null]"><svg aria-hidden="true" class="svg-icon iconHelp" width="18" height="18" viewBox="0 0 18 18"><path d="M9 1C4.64 1 1 4.64 1 9s3.64 8 8 8 8-3.64 8-8-3.64-8-8-8m.81 12.13c-.02.71-.55 1.15-1.24 1.13-.66-.02-1.17-.49-1.15-1.2.02-.72.56-1.18 1.22-1.16.7.03 1.2.51 1.17 1.23M11.77 8c-.59.66-1.78 1.09-2.05 1.97a4 4 0 0 0-.09.75c0 .05-.03.16-.18.16H7.88c-.16 0-.18-.1-.18-.15.06-1.35.66-2.2 1.83-2.88.39-.29.7-.75.7-1.24.01-1.24-1.64-1.82-2.35-.72-.21.33-.18.73-.18 1.1H5.75c0-1.97 1.03-3.26 3.03-3.26 1.75 0 3.47.87 3.47 2.83 0 .57-.2 1.05-.48 1.44"/></svg></a>
</li>
<div class="topbar-dialog help-dialog js-help-dialog dno" id="topbar-help-dialog" role="menu">
<div class="modal-content">
<ul>
<li>
<a href="/tour" class="js-gps-track s-block-link" data-gps-track="help_popup.click({ item_type:1 })"
data-ga="[&quot;top navigation&quot;,&quot;tour submenu click&quot;,null,null,null]">
Tour
<span class="item-summary">
Start here for a quick overview of the site
</span>
</a>
</li>
<li>
<a href="/help" class="js-gps-track s-block-link"
data-gps-track="help_popup.click({ item_type:4 })"
data-ga="[&quot;top navigation&quot;,&quot;help center&quot;,null,null,null]">
Help Center
<span class="item-summary">
Detailed answers to any questions you might have
</span>
</a>
</li>
<li>
<a href="https://codereview.meta.stackexchange.com" class="js-gps-track s-block-link" data-gps-track="help_popup.click({ item_type:2 })"
data-ga="[&quot;top navigation&quot;,&quot;meta submenu click&quot;,null,null,null]">
Meta
<span class="item-summary">
Discuss the workings and policies of this site
</span>
</a>
</li>
<li>
<a href="https://stackoverflow.co/" class="js-gps-track s-block-link" data-gps-track="help_popup.click({ item_type:6 })"
data-ga="[&quot;top navigation&quot;,&quot;about us submenu click&quot;,null,null,null]">
About Us
<span class="item-summary">
Learn more about Stack Overflow the company, and our products
</span>
</a>
</li>
</ul>
</div>
</div>
<li role="none">
<a href="https://stackexchange.com" class="s-topbar--item js-site-switcher-button js-gps-track" data-gps-track="site_switcher.show"
aria-label="Site switcher"
role="menuitem"
title="A list of all 183 Stack Exchange sites"
aria-haspopup="true" aria-expanded="false"
data-ga="[&quot;top navigation&quot;,&quot;stack exchange click&quot;,null,null,null]">
<svg aria-hidden="true" class="svg-icon iconStackExchange" width="18" height="18" viewBox="0 0 18 18"><path d="M15 1H3a2 2 0 0 0-2 2v2h16V3a2 2 0 0 0-2-2M1 13c0 1.1.9 2 2 2h8v3l3-3h1a2 2 0 0 0 2-2v-2H1zm16-7H1v4h16z"/></svg>
</a>
</li>
<li class="js-topbar-dialog-corral" role="presentation">
<div class="topbar-dialog siteSwitcher-dialog dno" role="menu">
<div class="header fw-wrap">
<h3 class="flex--item">
<a href="https://codereview.stackexchange.com">current community</a>
</h3>
<div class="flex--item fl1">
<div class="ai-center d-flex jc-end">
<button
class="js-close-button s-btn s-btn__muted p0 ml8 d-none sm:d-block"
type="button"
aria-label="Close"
>
<svg aria-hidden="true" class="svg-icon iconClear" width="18" height="18" viewBox="0 0 18 18"><path d="M15 4.41 13.59 3 9 7.59 4.41 3 3 4.41 7.59 9 3 13.59 4.41 15 9 10.41 13.59 15 15 13.59 10.41 9z"/></svg>
</button>
</div>
</div>
</div>
<div class="modal-content bg-blue-200 current-site-container">
<div class="d-none sm:d-block">
<div class="d-flex ai-end">
<div class="s-user-card flex--item fl1">
<a href="/users/289986/john-sean" class="s-avatar s-avatar__32 s-user-card--avatar">
<div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/36a7dac282035037e728f06424d47f96?s=32&amp;d=identicon&amp;r=PG&amp;f=y&amp;so-version=2" alt="john sean&#39;s user avatar" width="32" height="32" class="bar-sm avatar s-avatar--image"></div>
</a>
<div class="s-user-card--info">
<a href="/users/289986/john-sean" class="s-user-card--link">john sean</a>
<div class="s-user-card--awards lh-unset fc-black-500 fw-bold">
<span class="reputation-score" title="reputation score " dir="ltr">1</span>
</div>
</div>
</div>
<div class="related-links flex--item p8">
<a href="https://codereview.stackexchange.com/users/logout" data-gps-track="site_switcher.click({ item_type:8 })">log out</a>
</div>
</div>
</div>
<ul class="current-site">
<li class="d-flex">
<div class="fl1">
<a href="https://codereview.stackexchange.com"
class="current-site-link d-flex gx8 site-link js-gps-track"
data-id="196"
data-gps-track="site_switcher.click({ item_type:3 })">
<div class="favicon favicon-codereview site-icon flex--item" title="Code Review"></div>
<span class="flex--item fl1">
Code Review
</span>
</a>
</div>
<div class="related-links">
<a href="https://codereview.stackexchange.com/help" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:14 })">help</a>
<a href="https://chat.stackexchange.com?tab=site&amp;host=codereview.stackexchange.com" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:6 })">chat</a>
<a href="https://codereview.stackexchange.com/users/logout" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:8 })">log out</a>
</div>
</li>
<li class="related-site d-flex">
<div class="L-shaped-icon-container">
<span class="L-shaped-icon"></span>
</div>
<a href="https://codereview.meta.stackexchange.com"
class="s-block-link px16 d-flex gx8 site-link js-gps-track"
data-id="198"
data-gps-track="site.switch({ target_site:198, item_type:3 }),site_switcher.click({ item_type:4 })">
<div class="favicon favicon-codereviewmeta site-icon flex--item" title="Code Review Meta"></div>
<span class="flex--item fl1">
Code Review Meta
</span>
</a>
</li>
</ul>
</div>
<div class="header" id="your-communities-header">
<h3>
<a href="https://stackexchange.com/users/41080829/?tab=accounts">your communities</a>
</h3>
<a href="#" id="edit-pinned-sites">edit</a>
<a href="#" id="cancel-pinned-sites" style="display: none;">cancel</a>
</div>
<div class="modal-content" id="your-communities-section">
<ul class="my-sites">
<li class="p0">
<a href="https://codereview.stackexchange.com"
class="s-block-link px16 d-flex gx8 site-link js-gps-track"
data-id="196"
data-gps-track="site.switch({ target_site:196, item_type:3 }),site_switcher.click({ item_type:1 })">
<div class="favicon favicon-codereview site-icon flex--item" title="Code Review"></div>
<span class="flex--item fl1">
Code Review
</span>
<span class="rep-score flex--item">1</span>
</a>
</li>
</ul>
<div class="pinned-site-editor-container" style="display: none;">
<input type="hidden" name="fkey" value="1bdb2a6f769206fb1bc17489607dec3bc94f3d71366944559446c3c6061a5f99">
<div class="d-flex p12">
<div class="flex--item fl1 ps-relative">
<input id="js-site-search-txt"
type="text"
class="s-input s-input__sm w100 h100 site-filter-input"
value=""
placeholder="Add a Stack Exchange community"/>
<ul class="js-found-sites found-sites hmx1 l0 r0 ps-absolute overflow-y-auto"></ul>
</div>
<button class="ml8 s-btn s-btn__sm" type="submit" id="pin-site-btn" disabled="disabled">Add</button>
</div>
<ul class="pinned-site-list sortable" data-custom-list="False">
</ul>
<div class="d-flex p12 jc-end">
<a class="flex--item s-btn s-btn__sm js-reset-pinned-sites" href="#">Reset</a>
<button class="ml8 flex--item s-btn s-btn__filled s-btn__sm" type="submit" id="save-pinned-sites-btn" disabled="disabled">Save</button>
</div>
</div>
</div>
<div class="header">
<h3><a href="https://stackexchange.com/sites">more stack exchange communities</a>
</h3>
<a href="https://stackoverflow.blog" class="float-right">company blog</a>
</div>
<div class="modal-content">
<div class="child-content"></div>
</div>
</div>
</li>
</ol>
</nav>
</div>
</header>
<script>
StackExchange.ready(function () { StackExchange.topbar.init(); });
StackExchange.scrollPadding.setPaddingTop(50, 10);
</script>
<header class="site-header">
<div class="site-header--container jc-space-between sm:fd-column sm:pt8 sm:pb8">
<a class="site-header--link d-flex ai-center fs-headline1 fw-bold sm:mb8" href="https://codereview.stackexchange.com">
<img class="h-auto wmx100" src="https://cdn.sstatic.net/Sites/codereview/Img/logo.svg?v=0dfb1294dc6e" alt="Code Review">
</a>
<div class="d-flex ai-center gsx gs8">
<div class="js-zone-container zone-container-sidebar">
<div id="dfp-sspon" class="everyonelovesstackoverflow my4"></div>
</div>
</div>
</div>
</header>
<div class="container">
<div id="left-sidebar" data-is-here-when="md lg" class="left-sidebar js-pinned-left-sidebar ps-relative">
<div class="left-sidebar--sticky-container js-sticky-leftnav">
<nav aria-label="Primary">
<ol class="nav-links">
<li>
<ol class="nav-links">
<li class="ps-relative" aria-current="false">
<a
href="/"
class="s-block-link pl8 js-gps-track nav-links--link -link__with-icon"
data-gps-track="top_nav.click({is_current: false, location:2, destination:8, has_activity_notification:False});home_nav.click({location:2})"
aria-controls=""
data-controller=" "
data-s-popover-placement="right"
aria-current="false"
data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never"
>
<div class="d-flex ai-center">
<svg aria-hidden="true" class="svg-icon iconHome" width="18" height="18" viewBox="0 0 18 18"><path d="M15 10v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-5H0l9-9 9 9zm-8 1v6h4v-6z"/></svg> <span class="-link--channel-name pl8">Home</span>
</div>
</a>
</li>
<li class="ps-relative youarehere" aria-current="true">
<a id="nav-questions"
href="/questions"
class="s-block-link pl8 js-gps-track nav-links--link -link__with-icon"
data-gps-track="top_nav.click({is_current: true, location:2, destination:1, has_activity_notification:False})"
aria-controls=""
data-controller=" "
data-s-popover-placement="right"
aria-current="false"
data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never"
>
<div class="d-flex ai-center">
<svg aria-hidden="true" class="svg-icon iconQuestion" width="18" height="18" viewBox="0 0 18 18"><path d="m4 15-3 3V4c0-1.1.9-2 2-2h12c1.09 0 2 .91 2 2v9c0 1.09-.91 2-2 2zm7.75-3.97c.72-.83.98-1.86.98-2.94 0-1.65-.7-3.22-2.3-3.83a4.4 4.4 0 0 0-3.02 0 3.8 3.8 0 0 0-2.32 3.83q0 1.93 1.03 3a3.8 3.8 0 0 0 2.85 1.07q.94 0 1.71-.34.97.66 1.06.7.34.2.7.3l.59-1.13a5 5 0 0 1-1.28-.66m-1.27-.9a5 5 0 0 0-1.5-.8l-.45.9q.5.18.98.5-.3.1-.65.11-.92 0-1.52-.68c-.86-1-.86-3.12 0-4.11.8-.9 2.35-.9 3.15 0 .9 1.01.86 3.03-.01 4.08"/></svg> <span class="-link--channel-name pl8">Questions</span>
</div>
</a>
</li>
<li class="ps-relative" aria-current="false">
<a id="nav-unanswered"
href="/unanswered"
class="s-block-link pl8 js-gps-track nav-links--link -link__with-icon"
data-gps-track="top_nav.click({is_current: false, location:2, destination:5, has_activity_notification:False})"
aria-controls=""
data-controller=" "
data-s-popover-placement="right"
aria-current="false"
data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never"
>
<div class="d-flex ai-center">
<svg aria-hidden="true" class="svg-icon iconAnswer" width="18" height="18" viewBox="0 0 18 18"><path d="M14 15H3c-1.09 0-2-.91-2-2V4c0-1.1.9-2 2-2h12c1.09 0 2 .91 2 2v14zm-1.02-3L9.82 4H8.14l-3.06 8h1.68l.65-1.79h3.15l.69 1.79zm-2.93-3.12H7.9l1.06-2.92z"/></svg> <span class="-link--channel-name pl8">Unanswered</span>
</div>
</a>
</li>
<li class="ps-relative" aria-current="false">
<a
href="/tags"
class="s-block-link pl8 js-gps-track nav-links--link -link__with-icon"
data-gps-track="top_nav.click({is_current: false, location:2, destination:2, has_activity_notification:False})"
aria-controls=""
data-controller=" "
data-s-popover-placement="right"
aria-current="false"
data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never"
>
<div class="d-flex ai-center">
<svg aria-hidden="true" class="svg-icon iconTags" width="18" height="18" viewBox="0 0 18 18"><path d="M9.24 1a3 3 0 0 0-2.12.88l-5.7 5.7a2 2 0 0 0-.38 2.31 3 3 0 0 1 .67-1.01l6-6A3 3 0 0 1 9.83 2H14a3 3 0 0 1 .79.1A2 2 0 0 0 13 1z" opacity=".4"/><path d="M9.83 3a2 2 0 0 0-1.42.59l-6 6a2 2 0 0 0 0 2.82L6.6 16.6a2 2 0 0 0 2.82 0l6-6A2 2 0 0 0 16 9.17V5a2 2 0 0 0-2-2zM12 9a2 2 0 1 1 0-4 2 2 0 0 1 0 4"/></svg> <span class="-link--channel-name pl8">Tags</span>
</div>
</a>
</li>
<li class="ps-relative" aria-current="false">
<a
href="/users/saves/289986/all"
class="s-block-link pl8 js-gps-track nav-links--link -link__with-icon"
data-gps-track="top_nav.click({is_current: false, location:2, destination:8, has_activity_notification:False});home_nav.click({location:2})"
aria-controls=""
data-controller=" "
data-s-popover-placement="right"
aria-current="false"
data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never"
>
<div class="d-flex ai-center">
<svg aria-hidden="true" class="svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg> <span class="-link--channel-name pl8">Saves</span>
</div>
</a>
</li>
<li class="pb24"></li>
<li class="ps-relative" aria-current="false">
<a id="nav-chat"
href="https://chat.stackexchange.com/rooms/8595/the-2nd-monitor"
class="s-block-link pl8 js-disable-chat-new-link js-gps-track nav-links--link -link__with-icon"
data-gps-track="top_nav.click({is_current: false, location:2, destination:31, has_activity_notification:False});chat.click({is_registered:True, rep_bucket:&#x27;1&#x27;, origin:&#x27;Code Review Stack Exchange&#x27;})"
aria-controls=""
data-controller=" "
data-s-popover-placement="right"
aria-current="false"
data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never"
>
<div class="d-flex ai-center">
<div class="d-flex ai-center mln8 mrn8 myn8 bg-purple-400 baw3 bas-solid bc-purple-200 bar-circle fc-white p4"><svg aria-hidden="true" class="fc-white bg-transparent svg-icon iconChatTest" width="18" height="18" viewBox="0 0 18 16"><path d="M17 3C17 1.89543 16.1046 1 15 1H7C5.89543 1 5 1.89543 5 3V5C5 6.10457 5.89543 7 7 7H15C16.1046 7 17 6.10457 17 5V3ZM7 3H15V5H7V3Z" /><path d="M17 10C17 8.89543 16.1046 8 15 8H7C5.89543 8 5 8.89543 5 10V14C5 15.1046 5.89543 16 7 16H15C16.1046 16 17 15.1046 17 14V10ZM7 10H15V14H7V10Z" /><path d="M1 9C1 8.44771 1.44772 8 2 8H3C3.55228 8 4 8.44772 4 9V10C4 10.5523 3.55228 11 3 11H2C1.44772 11 1 10.5523 1 10V9Z" /><path d="M2 1C1.44772 1 1 1.44772 1 2V3C1 3.55228 1.44772 4 2 4H3C3.55228 4 4 3.55228 4 3V2C4 1.44772 3.55228 1 3 1H2Z" /></svg></div> <span class="-link--channel-name pl8">Chat</span>
</div>
</a>
</li>
<script>
$('.js-disable-chat-new-link').on("click", function(e) {
StackExchange.helpers.toggleAccountPreferenceFlags(262144, true);
return true;
});
</script>
<li class="ps-relative" aria-current="false">
<a id="nav-users"
href="/users"
class="s-block-link pl8 js-gps-track nav-links--link -link__with-icon"
data-gps-track="top_nav.click({is_current: false, location:2, destination:3, has_activity_notification:False})"
aria-controls=""
data-controller=" "
data-s-popover-placement="right"
aria-current="false"
data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never"
>
<div class="d-flex ai-center">
<svg aria-hidden="true" class="svg-icon iconPeople" width="18" height="18" viewBox="0 0 18 18"><path d="M17 14c0 .44-.45 1-1 1H9a1 1 0 0 1-1-1H2c-.54 0-1-.56-1-1 0-2.63 3-4 3-4s.23-.4 0-1c-.84-.62-1.06-.59-1-3s1.37-3 2.5-3 2.44.58 2.5 3-.16 2.38-1 3c-.23.59 0 1 0 1s1.55.71 2.42 2.09c.78-.72 1.58-1.1 1.58-1.1s.23-.4 0-1c-.84-.61-1.06-.58-1-3s1.37-3 2.5-3 2.44.59 2.5 3c.05 2.42-.16 2.39-1 3-.23.6 0 1 0 1s3 1.38 3 4"/></svg> <span class="-link--channel-name pl8">Users</span>
</div>
</a>
</li>
<li class="pb24"></li>
<li class="ps-relative" aria-current="false">
<a id="nav-companies"
href="https://stackoverflow.com/jobs/companies?so_medium=codereview&amp;so_source=SiteNav"
class="s-block-link pl8 js-gps-track nav-links--link -link__with-icon"
data-gps-track="top_nav.click({is_current: false, location:2, destination:12, has_activity_notification:False})"
aria-controls=""
data-controller=" "
data-s-popover-placement="right"
aria-current="false"
data-s-popover-auto-show="true" data-s-popover-hide-on-outside-click="never"
>
<div class="d-flex ai-center">
<svg aria-hidden="true" class="svg-icon iconIndustry" width="18" height="18" viewBox="0 0 18 18"><path d="M10 16v-4H8v4H2V4c0-1.1.9-2 2-2h6c1.09 0 2 .91 2 2v2h2c1.09 0 2 .91 2 2v8zM4 4v2h2V4zm0 4v2h2V8zm4-4v2h2V4zm0 4v2h2V8zm-4 4v2h2v-2zm8 0v2h2v-2zm0-4v2h2V8z"/></svg> <span class="-link--channel-name pl8">Companies</span>
</div>
</a>
</li>
</ol>
</li>
<li class="js-freemium-cta ps-relative mt32 mb8">
<button type="button" aria-label="Dismiss this promotion" class="js-freemium-cta-dismiss ps-absolute tn8 r0 mr4 s-btn s-btn__muted s-btn__xs">
<svg aria-hidden="true" class="svg-icon iconClearSm" width="14" height="14" viewBox="0 0 14 14"><path d="M12 3.41 10.59 2 7 5.59 3.41 2 2 3.41 5.59 7 2 10.59 3.41 12 7 8.41 10.59 12 12 10.59 8.41 7z"/></svg>
</button>
<div class="fs-fine tt-uppercase fc-black-600 fw-bold ml8 mt16 mb8">Teams</div>
<div class="px12 pt12 pb4 mb12 fc-medium overflow-hidden">
<img class="wmx100 mx-auto mb12 h-auto d-block" width="151" height="24" src="https://cdn.sstatic.net/Img/teams/teams-promo.svg?v=e507948b81bf" alt="">
<p class="fs-fine">
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
</p>
<a href="https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=codereview-community&utm_campaign=side-bar&utm_content=explore-teams"
class="w100 s-btn s-btn__filled s-btn__xs bg-orange-400 h:bg-orange-500 js-gps-track pt8 pr7 pb6 pl7"
data-gps-track="teams.create.left-sidenav.click({ Action: 6 })"
data-ga="[&quot;teams left navigation&quot;,&quot;left nav free cta&quot;,&quot;stackoverflow.com/teams/create/free&quot;,null,null]">Try Teams for free</a>
<a href="https://stackoverflow.co/teams/?utm_medium=referral&utm_source=codereview-community&utm_campaign=side-bar&utm_content=explore-teams"
class="w100 s-btn s-btn__muted s-btn__xs mt1 js-gps-track"
data-gps-track="teams.create.left-sidenav.click({ Action: 5 })"
data-ga="[&quot;teams left navigation&quot;,&quot;left nav free cta&quot;,&quot;stackoverflow.com/teams&quot;,null,null]">Explore Teams</a>
</div>
</li>
<script>
$('.js-freemium-cta-dismiss').on("click", function (e) {
e.preventDefault();
StackExchange.helpers.toggleAccountPreferenceFlags(32, true);
$('.js-freemium-cta').addClass('d-none');
$('.js-create-team-cta').removeClass('d-none');
return false;
});
</script>
<li class="d-flex ai-center jc-space-between ml8 mt32 mb8 js-create-team-cta d-none">
<a href="javascript:void(0)"
class="s-link d-flex fl-grow1 fc-black-400 h:fc-black-600 fs-fine js-gps-track"
role="button"
aria-controls="popover-teams-create-cta"
data-controller="s-popover"
data-action="s-popover#toggle"
data-s-popover-placement="bottom-start"
data-s-popover-toggle-class="is-selected"
data-gps-track="teams.create.left-sidenav.click({ Action: ShowInfo })"
data-ga="[&quot;teams left navigation&quot;,&quot;left nav show teams info&quot;,null,null,null]"
>
<div class="flex--item fl-grow1 fc-black-600 fw-bold tt-uppercase">Teams</div>
<div class="flex--item px12">
<svg aria-hidden="true" class="svg-icon iconPlusSm" width="14" height="14" viewBox="0 0 14 14"><path d="M8 2H6v4H2v2h4v4h2V8h4V6H8z"/></svg>
</div>
</a>
</li>
<li class="ps-relative js-create-team-cta d-none">
<p class="fs-fine pr8 pl8 pb4 fc-black-400">
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
<a href="https://stackoverflow.co/teams/?utm_medium=referral&utm_source=codereview-community&utm_campaign=side-bar&utm_content=explore-teams-compact" class="s-link s-link__grayscale s-link__underlined fw-bold">Explore Teams</a>
</p>
</li>
<li class="mt8 px8">
<p class="w100 px0 fs-fine fc-medium">
Looking for
<button
aria-label="Teams were moved popover"
aria-controls="teams-were-moved-popover"
aria-expanded="false"
data-controller="s-popover"
data-action="s-popover#toggle"
data-s-popover-placement="bottom-start"
data-gps-track="teams.sot_migration_notification_teams_moved.click()"
class="s-link s-link__grayscale s-link__underlined fw-bold js-gps-track">your Teams?</button>
</p>
</li>
</ol>
</nav>
</div>
<div class="s-popover mt4 ws3"
id="teams-were-moved-popover"
role="menu">
<div class="s-popover--arrow"></div>
<p>Stack Overflow for Teams has its own domain!</p>
<p>You can now access your Teams at <a href="https://stackoverflowteams.com" class="s-link fs-italic">stackoverflowteams.com</a>. Teams no longer appear in the left sidebar on <span class="fs-italic">stackoverflow.com</span>. Check your email to learn more about these changes.</p>
</div>
<div class="s-popover ws2"
id="popover-teams-create-cta"
role="menu"
aria-hidden="true">
<div class="s-popover--arrow"></div>
<div class="ps-relative overflow-hidden">
<p class="mb2"><strong>Teams</strong></p>
<p class="mb12 fs-caption fc-black-400">Q&amp;A for work</p>
<p class="mb12 fs-caption fc-black-500">Connect and share knowledge within a single location that is structured and easy to search.</p>
<a href="https://stackoverflow.co/teams/"
class="js-gps-track s-btn s-btn__filled s-btn__xs"
data-gps-track="teams.create.left-sidenav.click({ Action: CtaClick })"
data-ga="[&quot;teams left navigation&quot;,&quot;left nav cta&quot;,&quot;stackoverflow.com/teams&quot;,null,null]">
Learn more about Teams
</a>
</div>
<div class="ps-absolute t8 r8">
<svg aria-hidden="true" class="fc-orange-400 svg-spot spotPeople" width="48" height="48" viewBox="0 0 48 48"><path d="M13.5 28a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9M7 30a1 1 0 0 1 1-1h11a1 1 0 0 1 1 1v5h11v-5a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v10a2 2 0 0 1-2 2H33v5a1 1 0 0 1-1 1H20a1 1 0 0 1-1-1v-5H8a1 1 0 0 1-1-1zm25-6.5a4.5 4.5 0 1 0 9 0 4.5 4.5 0 0 0-9 0M24.5 34a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9" opacity=".2"/><path d="M16.4 26.08A6 6 0 1 0 7.53 26C5.64 26.06 4 27.52 4 29.45V40a1 1 0 0 0 1 1h9a1 1 0 1 0 0-2h-4v-7a1 1 0 1 0-2 0v7H6v-9.55c0-.73.67-1.45 1.64-1.45H16a1 1 0 0 0 .4-1.92M12 18a4 4 0 1 1 0 8 4 4 0 0 1 0-8m16.47 14a6 6 0 1 0-8.94 0A3.6 3.6 0 0 0 16 35.5V46a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1V35.5c0-1.94-1.64-3.42-3.53-3.5M20 28a4 4 0 1 1 8 0 4 4 0 0 1-8 0m-.3 6h8.6c1 0 1.7.75 1.7 1.5V45h-2v-7a1 1 0 1 0-2 0v7h-4v-7a1 1 0 1 0-2 0v7h-2v-9.5c0-.75.7-1.5 1.7-1.5M42 22c0 1.54-.58 2.94-1.53 4A3.5 3.5 0 0 1 44 29.45V40a1 1 0 0 1-1 1h-9a1 1 0 1 1 0-2h4v-7a1 1 0 1 1 2 0v7h2v-9.55A1.5 1.5 0 0 0 40.48 28H32a1 1 0 0 1-.4-1.92A6 6 0 1 1 42 22m-2 0a4 4 0 1 0-8 0 4 4 0 0 0 8 0"/><g opacity=".35"><path d="M17 10a1 1 0 011-1h12a1 1 0 110 2H18a1 1 0 01-1-1m1-5a1 1 0 100 2h12a1 1 0 100-2zM14 1a1 1 0 00-1 1v12a1 1 0 001 1h5.09l4.2 4.2a1 1 0 001.46-.04l3.7-4.16H34a1 1 0 001-1V2a1 1 0 00-1-1zm1 12V3h18v10h-5a1 1 0 00-.75.34l-3.3 3.7-3.74-3.75a1 1 0 00-.71-.29z"/></g></svg>
</div>
</div>
</div>
<div id="content" class="snippet-hidden">
<div itemprop="mainEntity" itemscope itemtype="https://schema.org/Question">
<link itemprop="image" href="https://cdn.sstatic.net/Sites/codereview/Img/apple-touch-icon.png?v=0a72875519a4">
<div class="inner-content clearfix">
<div id="question-header" class="d-flex sm:fd-column">
<h1 itemprop="name" class="fs-headline1 ow-break-word mb8 flex--item fl1"><a href="/questions/27986/text-based-rpg-game-using-classes" class="question-hyperlink">Text-based RPG game using classes</a></h1>
<div class="ml12 aside-cta flex--item sm:ml0 sm:mb12 sm:order-first d-flex jc-end">
<div class="ml12 aside-cta flex--item print:d-none">
<a href="/questions/ask" class="ws-nowrap s-btn s-btn__filled">
Ask Question
</a>
</div>
</div>
</div>
<div class="d-flex fw-wrap pb8 mb16 bb bc-black-200">
<div class="flex--item ws-nowrap mr16 mb8" title="2013-07-01 10:46:25Z">
<span class="fc-black-400 mr2">Asked</span>
<time itemprop="dateCreated" datetime="2013-07-01 10:46:25Z">11 years, 9 months ago</time>
</div>
<div class="flex--item ws-nowrap mr16 mb8">
<span class="fc-black-400 mr2">Modified</span>
<a href="?lastactivity" class="s-link s-link__inherit" title="2014-10-07 06:38:01Z">10 years, 5 months ago</a>
</div>
<div class="flex--item ws-nowrap mb8" title="Viewed 52,137 times">
<span class="fc-black-400 mr2">Viewed</span>
52k times
</div>
</div>
<div id="mainbar" role="main" aria-label="question and answers">
<div class="question js-question" data-questionid="27986" data-position-on-page="0" data-score="13" data-author-reputation="355" id="question">
<style>
</style>
<div class="js-zone-container zone-container-main">
<div id="dfp-tlb" class="everyonelovesstackoverflow everyoneloves__top-leaderboard everyoneloves__leaderboard"></div>
<div class="js-report-ad-button-container " style="width: 728px"></div>
</div>
<div class="post-layout ">
<div class="votecell post-layout--left">
<div class="js-voting-container d-flex jc-center fd-column ai-center gs4 fc-black-300" data-post-id="27986" data-referrer="None">
<button class="js-vote-up-btn flex--item s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id="upvote-btn-27986"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
title="This question shows research effort; it is useful and clear"
aria-pressed="false"
aria-label="Up vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowUp" width="18" height="18" viewBox="0 0 18 18"><path d="M1 12h16L9 4z"/></svg>
</button>
<input type="hidden" id="voteUpHash" value="67:3:31e,16:970467699a76c302,10:1743331693,16:56343ed3d13e57a4,5:27986,fcb041816d21e983ff003f5a9343a6fe0c4b7e990e48bb33a87d3f4c9c0d95d4" />
<div class="js-vote-count flex--item d-flex fd-column ai-center fc-theme-body-font fw-bold fs-subheading py4"
itemprop="upvoteCount"
data-value="13">
13 </div>
<button
class="js-vote-down-btn js-vote-down-question flex--item mb8 s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id=downvote-btn-27986
title="This question does not show any research effort; it is unclear or not useful"
aria-pressed="false"
aria-label="Down vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowDown" width="18" height="18" viewBox="0 0 18 18"><path d="M1 6h16l-8 8z"/></svg>
</button>
<input type="hidden" id="voteDownHash" value="67:3:31e,16:3a6237897642ece4,10:1743331693,16:a09fc2298ee8b935,5:27986,c659df08c4a4b958a1d7a6976748aff1f4435fb30812c6823c5878916ccd3ddc" />
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
type="button"
id="saves-btn-27986"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
data-s-popover-placement=""
title="Save this question."
data-is-saved="false"
aria-label="Save"
data-post-id="27986"
data-post-type-id="1"
data-user-privilege-for-post-click="-1"
aria-controls=""
data-s-popover-auto-show="false"
>
<svg aria-hidden="true" class="fc-theme-primary-400 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
<svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26zM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
</button>
<a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/27986/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10z"/></svg></a>
</div>
</div>
<div class="postcell post-layout--right">
<span class="d-none">\$\begingroup\$</span>
<div class="s-prose js-post-body" itemprop="text">
<p>I am studying for a degree in "Bachelor of Engineering in Information and Communication Technologies." I am currently on vacation, just after we started learning C++ at the end of the semester. I wanted to be ahead of the next semester, so I decided to try to use these classes and to make a text-based game.</p>
<p>I would like to know what I could do better. Should I remove or add some class functions? Should I do something differently, maybe not even related to classes?</p>
<p><strong>Main.cpp</strong></p>
<pre><code>#include "MobClass.h"
#include "Player.h"
#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;windows.h&gt;
using namespace std;
player battle(player account);
player calcEXP(player account,classMob monster);
player levelUp(player account);
void death();
int main()
{
string name;
int option1;
cout &lt;&lt; "Welcome, please enter your name\n";
cin &gt;&gt; name;
string location[4] = {"in a hole","in a cave","in the mauntains","in a castle"};
player account(name,location[0],1,0);
cout &lt;&lt;"\nWelcome "&lt;&lt;account.getName() &lt;&lt; " you find your self " &lt;&lt; account.getArea() &lt;&lt; "\nand you are not sure how you ended up here\n";
while (1)
{
Sleep(500);
cout &lt;&lt;"write 1 to walk forward or 2 to walk left or 3 to walk right\n";
cin &gt;&gt; option1;
if (option1 &gt;=1 &amp;&amp; option1 &lt;=3)
{
Sleep(50*(option1));
srand(time(NULL));
if (rand() %3 == option1-1){
account = battle(account);
}
}
else{
cout &lt;&lt; "\n#@#Error#@# Please enter a number between 1 and 3\n\n";
cin.clear();
cin.ignore();
}
}
return 0;
}
player battle(player account)
{
string option;
string location[4] = {"in a hole","in a cave","in the mauntains","in a castle"};
string monsters[5][3] = {{"worm","lizard","snake"},{"rat","snake","trolls"},{"Dragon","Dragon","Dragon"},{"Evil knight","The mad king","Joffrey Baratheon"}};
Sleep(20);
srand(time(NULL));
int ranM = (rand() % 3); //random monster
int ranD = (rand() % 5)+1; //random diff
classMob monster(monsters[account.getLevel()-1][ranM],account.getLevel(),account.getArea(),ranD);
cout &lt;&lt;"Suddently you meet a "&lt;&lt; monster.getName() &lt;&lt;", be ready for battle" &lt;&lt; "\n";
Sleep(2000);
do
{
cout &lt;&lt; "\n\n\n ######################################\nHP:"&lt;&lt; account.getHealth() &lt;&lt; " "&lt;&lt; monster.getName()&lt;&lt;"HP:"&lt;&lt;monster.getHealth()&lt;&lt;" difficulty:"&lt;&lt;monster.getDifficulty() &lt;&lt; "\n";
cout &lt;&lt; "Write A for attack or R for retreat" &lt;&lt; "\n";
cin &gt;&gt; option;
srand(time(NULL));
if (option == "R" || option == "r")
{
if ((rand() % 2) == 1){
cout &lt;&lt; "retreat sucessfull" &lt;&lt; "\n";
monster.setHealth(0);
}
else{
cout &lt;&lt; "retreat failed, the monster get a free attack and you lose 5 health\n";
account.setHealth(account.getHealth()-5);
option ="A";
}
}
if (option == "A" || option == "a")
{
int attack =rand()%(account.getDamage());
srand(time(NULL));
int mobAttack = rand()%(monster.getDamage());
monster.setHealth(monster.getHealth()-attack);
account.setHealth(account.getHealth()-mobAttack);
cout &lt;&lt; "you attack the monster for " &lt;&lt; attack &lt;&lt; " damage\n";
Sleep(500);
cout &lt;&lt; "the monster counter attacks for " &lt;&lt; mobAttack &lt;&lt; " damage\n";
Sleep(500);
}
} while (monster.getHealth() &gt;0 &amp;&amp; account.getHealth() &gt; 0);
cout &lt;&lt; "\n\n\n ######################################\nHP:"&lt;&lt; account.getHealth() &lt;&lt; " "&lt;&lt; monster.getName()&lt;&lt;"HP:"&lt;&lt;monster.getHealth()&lt;&lt;" difficulty:"&lt;&lt;monster.getDifficulty() &lt;&lt; "\n";
if (account.getHealth() &lt;= 0)
{
death();
exit(0);
}
account = calcEXP(account,monster);
return account;
}
void death()
{
cout &lt;&lt; "Sorry you failed your epic quest\n";
}
player calcEXP(player account,classMob monster)
{
cout &lt;&lt; "#########\ncalculating EXP\n#########\n";
Sleep(500);
account.setEXP(account.getEXP() + monster.getEXP());
cout &lt;&lt; "EXP: " &lt;&lt;account.getEXP() &lt;&lt; "/" &lt;&lt; account.getEXPReq() &lt;&lt; "\n";
if (account.getEXP() &gt;= account.getEXPReq())
{
levelUp(account);
}
return account;
}
player levelUp(player account)
{
account.setLevel(account.getLevel()+1);
account.setEXPReq();
account.setMaxHealth();
account.setHealth(account.getMaxHealth());
cout &lt;&lt; "Level up! you are now level: " &lt;&lt; account.getLevel() &lt;&lt; "!\n";
return account;
}
</code></pre>
<p><strong>Player.h</strong></p>
<pre><code>#include &lt;string&gt;
class player
{
public:
player(std::string,std::string,int,int);
void setName(std::string);
void setArea(std::string);
void setLevel(int);
void setEXP(double);
void setHealth(double);
void setMaxHealth();
void setDamage();
std::string getName();
std::string getArea();
int getLevel();
double getHealth();
double getMaxHealth();
int getDamage();
int getEXP();
void setEXP(int);
int getEXPReq();
void setEXPReq();
private:
std::string playerName;
std::string playerArea;
int playerLevel;
double playerHealth;
double playerMaxHealth;
int playerDamage;
int EXP;
int EXPReq;
};
</code></pre>
<p><strong>player.cpp</strong></p>
<pre><code>#include &lt;string&gt;
#include "Player.h"
player::player(std::string name,std::string area,int level = 1,int EXP = 0)
{
setName(name);
setArea(area);
setLevel(level);
setEXP(EXP);
setMaxHealth();
setHealth(playerMaxHealth);
setDamage();
setEXPReq();
}
void player::setName(std::string name)
{
playerName = name;
}
void player::setArea(std::string area)
{
playerArea = area;
}
void player::setLevel(int level)
{
playerLevel = level;
}
void player::setHealth(double health)
{
playerHealth = health;
}
void player::setMaxHealth()
{
playerMaxHealth = (100 * getLevel());
}
void player::setDamage()
{
playerDamage = (30 * getLevel());
}
std::string player::getName()
{
return playerName;
}
std::string player::getArea()
{
return playerArea;
}
int player::getLevel()
{
return playerLevel;
}
double player::getHealth()
{
return playerHealth;
}
double player::getMaxHealth()
{
return playerMaxHealth;
}
int player::getDamage()
{
return playerDamage;
}
int player::getEXP()
{
return EXP;
}
void player::setEXP(int _EXP)
{
EXP = _EXP;
}
int player::getEXPReq()
{
return EXPReq;
}
void player::setEXPReq()
{
EXPReq = 70+((getLevel()*getLevel())*35);
}
</code></pre>
<p><strong>mobclass.h</strong></p>
<pre><code>#include &lt;string&gt;
class classMob
{
public:
classMob(std::string,int,std::string,int); // name,lvl,area,difficulty
void setName(std::string);
void setLevel(int);
void setArea(std::string);
void setDamage();
void setHealth(double);
void setMaxHealth();
void setDifficulty(int);
std::string getName();
int getLevel();
std::string getArea();
int getDamage();
double getHealth();
double getMaxHealth();
int getDifficulty();
int getEXP();
void setEXP();
private:
std::string mobName;
std::string mobArea;
int mobLevel;
int mobDamage;
double mobHealth;
double mobMaxHealth;
int mobDifficulty;
int EXP;
};
</code></pre>
<p><strong>mobclass.cpp</strong></p>
<pre><code>#include &lt;string&gt;
#include "MobClass.h"
classMob::classMob(std::string name,int lvl,std::string area,int difficulty)
{
setName(name);
setLevel(lvl);
setArea(area);
setDifficulty(difficulty);
setDamage();
setMaxHealth();
setHealth(mobMaxHealth);
setEXP();
}
void classMob::setName(std::string name)
{
mobName = name;
}
void classMob::setLevel(int level)
{
mobLevel = level;
}
void classMob::setArea(std::string area)
{
mobArea = area;
}
void classMob::setDifficulty(int difficulty)
{
mobDifficulty = difficulty;
}
void classMob::setDamage()
{
mobDamage = (3 *( getLevel())+((getDifficulty()*getLevel())/2));
}
void classMob::setHealth(double health)
{
mobHealth = health;
}
void classMob::setMaxHealth()
{
mobMaxHealth = (15 *(getDifficulty() + getLevel()));
}
std::string classMob::getName()
{
return mobName;
}
int classMob::getLevel()
{
return mobLevel;
}
std::string classMob::getArea()
{
return mobArea;
}
int classMob::getDifficulty()
{
return mobDifficulty;
}
int classMob::getDamage()
{
return mobDamage;
}
double classMob::getHealth()
{
return mobHealth;
}
double classMob::getMaxHealth()
{
return mobMaxHealth;
}
int classMob::getEXP()
{
return EXP;
}
void classMob::setEXP()
{
EXP = (getLevel() * 35);
}
</code></pre>
</div>
<div class="mt24 mb12">
<div class="post-taglist d-flex gs4 gsy fd-column">
<div class="d-flex ps-relative fw-wrap">
<ul class='ml0 list-ls-none js-post-tag-list-wrapper d-inline'><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/c%2b%2b" class="s-tag post-tag" title="show questions tagged &#39;c++&#39;" aria-label="show questions tagged &#39;c++&#39;" rel="tag" aria-labelledby="tag-c++-tooltip-container" data-tag-menu-origin="Unknown">c++</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/game" class="s-tag post-tag" title="show questions tagged &#39;game&#39;" aria-label="show questions tagged &#39;game&#39;" rel="tag" aria-labelledby="tag-game-tooltip-container" data-tag-menu-origin="Unknown">game</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/classes" class="s-tag post-tag" title="show questions tagged &#39;classes&#39;" aria-label="show questions tagged &#39;classes&#39;" rel="tag" aria-labelledby="tag-classes-tooltip-container" data-tag-menu-origin="Unknown">classes</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/adventure-game" class="s-tag post-tag" title="show questions tagged &#39;adventure-game&#39;" aria-label="show questions tagged &#39;adventure-game&#39;" rel="tag" aria-labelledby="tag-adventure-game-tooltip-container" data-tag-menu-origin="Unknown">adventure-game</a></li></ul>
</div>
</div>
</div>
<div class="mb0 ">
<div class="mt16 d-flex gs8 gsy fw-wrap jc-end ai-start pt4 mb16">
<div class="flex--item mr16 fl1 w96">
<div class="js-post-menu pt2" data-post-id="27986" data-post-type-id="1">
<div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">
<div class="flex--item">
<a href="/q/27986/289986"
rel="nofollow"
itemprop="url"
class="js-share-link js-gps-track"
title="Short permalink to this question"
data-gps-track="post.click({ item: 2, priv: -1, post_type: 1 })"
data-controller="se-share-sheet"
data-se-share-sheet-title="Share a link to this question"
data-se-share-sheet-subtitle="(Includes your user id)"
data-se-share-sheet-post-type="question"
data-se-share-sheet-social="facebook twitter "
data-se-share-sheet-location="1"
data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
data-se-share-sheet-license-name="CC BY-SA 3.0"
data-s-popover-placement="bottom-start">Share</a>
</div>
<div class="flex--item">
<a href="/posts/27986/edit" class="js-suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: -1, post_type: 1 })" title="Revise and improve this post">Edit</a>
</div>
<div class="flex--item">
<button type="button"
id="btnFollowPost-27986" class="s-btn s-btn__link js-follow-post js-follow-question js-gps-track"
data-gps-track="post.click({ item: 14, priv: -1, post_type: 1 })"
data-controller="s-tooltip s-popover" data-s-tooltip-placement="bottom"
data-s-popover-placement="bottom" aria-controls="divQuestionFollowFeaturePopover"
title="Follow this question to receive notifications">
Follow
<input type="hidden" id="voteFollowHash" value="67:3:31e,16:01163a93ec0a11e5,10:1743331693,16:cf91d9f331f1a913,5:27986,47bcff300c38794c47e72638bda05f476a246b69e6c0e4a51a386eac6e27f3d6" />
</button>
</div>
<div class="s-popover ws2 js-question-follow-feature-popover" id="divQuestionFollowFeaturePopover">
<div class="s-popover--arrow"></div>
<button type="button" class="s-popover--close s-btn s-btn__muted js-dismiss" aria-label="Dismiss">
<svg aria-hidden="true" class="svg-icon iconClearSm" width="14" height="14" viewBox="0 0 14 14"><path d="M12 3.41 10.59 2 7 5.59 3.41 2 2 3.41 5.59 7 2 10.59 3.41 12 7 8.41 10.59 12 12 10.59 8.41 7z"/></svg>
</button>
<div class="d-flex ai-center">
<div class="flex--item mr12">
<svg aria-hidden="true" class="fc-orange-400 svg-spot spotBell" width="48" height="48" viewBox="0 0 48 48"><path d="M11.81.8a1.38 1.38 0 0 0-2.5 1.16l1.91 4.09a1.37 1.37 0 1 0 2.5-1.16zm-8.7 3.98a1.4 1.4 0 0 1 1.94-.18l3.97 3.28A1.38 1.38 0 0 1 7.26 10L3.3 6.72a1.37 1.37 0 0 1-.19-1.94m34.91 23.57a21.3 21.3 0 0 0-.23-12.08 20 20 0 0 0-3-5.95 3.5 3.5 0 0 0-1.9-4.19 3.5 3.5 0 0 0-4.43 1.25c-2.2.13-4.4.71-6.44 1.58a21.7 21.7 0 0 0-9.3 7.6q-1.21 1.78-2.4 3.6l-.38.6c-2.34 3.6-3.55 5.07-4.87 5.64-1.08.47-2.3 1.1-2.82 2.22A3 3 0 0 0 3.7 32.6l27.82 12.98c1.96.91 4.33-.6 4.27-2.8a9 9 0 0 0-.39-2.24c-.41-1.36-.07-3.24 1.2-7.35.49-1.6 1-3.21 1.42-4.84M.27 14.11c.02-.76.66-1.35 1.42-1.33l4.75.16a1.38 1.38 0 0 1-.1 2.75l-4.74-.16a1.4 1.4 0 0 1-1.33-1.42m45.99 15.63a1.37 1.37 0 1 0 .73-2.65l-4.96-1.37a1.37 1.37 0 1 0-.74 2.65zm-2.74 6.53c-.5.57-1.37.64-1.94.14l-3.42-2.96a1.38 1.38 0 0 1 1.8-2.08l3.42 2.96c.57.5.64 1.36.14 1.94m3.22-15.37a1.38 1.38 0 0 0-1.05-2.54l-4.4 1.8a1.37 1.37 0 0 0 1.05 2.55z" opacity=".2"/><path d="M13.73 22.3a1 1 0 1 1-1.78-.92c3.61-7.07 8.02-10.8 13.34-11.26a1 1 0 0 1 .17 2c-4.53.39-8.4 3.66-11.73 10.17m22.33 3.56c1.13-4.3.95-8.36-.23-12.08a20 20 0 0 0-3.01-5.95 3.5 3.5 0 0 0-1.9-4.18 3.5 3.5 0 0 0-4.42 1.24c-2.21.13-4.4.71-6.44 1.58a21.7 21.7 0 0 0-9.3 7.6q-1.23 1.78-2.4 3.6l-.38.6c-2.34 3.6-3.55 5.07-4.87 5.64q-1.06.46-1.9 1.08a3 3 0 0 0 .52 5.12l27.83 12.98a3 3 0 0 0 4.26-2.8 9 9 0 0 0-.38-2.24c-.41-1.36-.07-3.24 1.19-7.34l.21-.7q.66-2.06 1.22-4.15m-4.23 14.48a1 1 0 0 1-1.43.94L2.58 28.29a1 1 0 0 1-.18-1.7q.65-.48 1.5-.86c1.84-.8 3.17-2.4 5.76-6.39l.39-.6q1.14-1.8 2.35-3.53a19.7 19.7 0 0 1 8.44-6.91 16 16 0 0 1 6.23-1.44 1 1 0 0 0 .92-.57c.42-.9 1.3-1.21 2.09-.84.8.37 1.11 1.24.7 2.13a1 1 0 0 0 .15 1.09 16 16 0 0 1 3 5.7 19.4 19.4 0 0 1 .2 10.97q-.56 2.04-1.2 4.06l-.21.7c-1.4 4.55-1.77 6.61-1.2 8.52q.3.92.3 1.71m-14.77-.72a1 1 0 1 1 1.78.9q-.26.52-.26 1.1a2.44 2.44 0 0 0 4.7.94 1 1 0 0 1 1.85.76 4.44 4.44 0 1 1-8.07-3.7"/></svg>
</div>
<div class="flex--item">
Get updates on questions and answers
</div>
</div>
</div>
</div>
<div class="js-menu-popup-container"></div>
</div>
</div>
<div class="post-signature flex--item">
<div class="user-info ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
<a href="/posts/27986/revisions" title="show all edits to this post"
class="js-gps-track"
data-gps-track="post.click({ item: 4, priv: -1, post_type: 1 })">edited <span title='2014-10-07 06:38:01Z' class='relativetime'>Oct 7, 2014 at 6:38</span></a>
</div>
</div>
<div class="user-gravatar32">
<a href="/users/22222/jamal"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/4b97c146bd7883eed4ea0df70a16a71b?s=64&amp;d=identicon&amp;r=PG&amp;f=y&amp;so-version=2" alt="Jamal&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
</div>
<div class="user-details">
<a href="/users/22222/jamal" dir="auto">Jamal</a>
<div class="-flair">
<span class="reputation-score" title="reputation score 34,984" dir="ltr">35k</span><span title="13 gold badges" aria-hidden="true"><span class="badge1"></span><span class="badgecount">13</span></span><span class="v-visible-sr">13 gold badges</span><span title="134 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">134</span></span><span class="v-visible-sr">134 silver badges</span><span title="237 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">237</span></span><span class="v-visible-sr">237 bronze badges</span>
</div>
</div>
</div>
</div>
<div class="post-signature owner flex--item">
<div class="user-info user-hover ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
asked <span title='2013-07-01 10:46:25Z' class='relativetime'>Jul 1, 2013 at 10:46</span>
</div>
</div>
<div class="user-gravatar32">
<a href="/users/26827/sumsar1812"><div class="gravatar-wrapper-32"><img src="https://i.sstatic.net/7zllW.jpg?s=64" alt="Sumsar1812&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
</div>
<div class="user-details" itemprop="author" itemscope itemtype="http://schema.org/Person">
<a href="/users/26827/sumsar1812" itemprop="url" dir="auto">Sumsar1812</a><span class="d-none" itemprop="name">Sumsar1812</span>
<div class="-flair">
<span class="reputation-score" title="reputation score " dir="ltr">355</span><span title="1 gold badge" aria-hidden="true"><span class="badge1"></span><span class="badgecount">1</span></span><span class="v-visible-sr">1 gold badge</span><span title="2 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">2</span></span><span class="v-visible-sr">2 silver badges</span><span title="11 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">11</span></span><span class="v-visible-sr">11 bronze badges</span>
</div>
</div>
</div>
</div>
</div>
</div>
<span class="d-none">\$\endgroup\$</span>
</div>
<span class="d-none" itemprop="commentCount">3</span>
<div class="post-layout--right js-post-comments-component">
<div id="comments-27986" class="comments js-comments-container bt bc-black-200 mt12 " data-post-id="27986" data-min-length="15">
<ul class="comments-list js-comments-list"
data-remaining-comments-count="0"
data-canpost="false"
data-cansee="true"
data-comments-unavailable="false"
data-addlink-disabled="true">
<li id="comment-43650" class="comment js-comment " data-comment-id="43650" data-comment-owner-id="24960" data-comment-score="1">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
<span title="number of &#x27;useful comment&#x27; votes received"
class="cool">1</span>
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">Without commenting the code (yet), the first paragraph would read more easily as &quot;I am studying for a degree of &quot;Bachelor of Engineering in Information and Communication Technologies&quot;, currently on vacation, just after we started learning C++ at the end of the semester. I wanted to be ahead of the next semester so I decided to try to use these classes and to made a text based game.&quot; (Yet SE does not let me perform this edit?)</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/24960/j-y-b-y"
title="193 reputation"
class="comment-user">J.y B.y</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 11:40:02Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 11:40</span>
</span>
</div>
</div>
</li>
<li id="comment-43655" class="comment js-comment " data-comment-id="43655" data-comment-owner-id="26827" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">Ok, yea it sounds better / properly is more correct that way. Changed it! :)</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/26827/sumsar1812"
title="355 reputation"
class="comment-user owner">Sumsar1812</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 14:49:05Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 14:49</span>
</span>
</div>
</div>
</li>
<li id="comment-43724" class="comment js-comment " data-comment-id="43724" data-comment-owner-id="507" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">Initializing srand(): <a href="http://stackoverflow.com/a/322995/14065">stackoverflow.com/a/322995/14065</a></span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/507/loki-astari"
title="97,129 reputation"
class="comment-user">Loki Astari</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-02 04:52:30Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 2, 2013 at 4:52</span>
</span>
</div>
</div>
</li>
</ul>
</div>
<div id="comments-link-27986" data-rep=50 data-reg=true>
<a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Avoid answering questions in comments." href="#" role="button">Add a comment</a>
<span class="js-link-separator dno">&nbsp;|&nbsp;</span>
<a class="js-show-link comments-link dno" title="Expand to show all comments on this post" href=# onclick="" role="button"></a>
</div>
</div>
<script defer src="https://cdn.sstatic.net/Js/webpack-chunks/svelte.en.js?v=e03f2e5e54e5"></script><script defer src="https://cdn.sstatic.net/Js/webpack-chunks/stacks-svelte.en.js?v=37a83d8975f0"></script><script defer src="https://cdn.sstatic.net/Js/webpack-chunks/2784.en.js?v=414ac3934ec2"></script><script defer src="https://cdn.sstatic.net/Js/islands/comment-popover.en.js?v=2f3fa10a5ced"></script> </div>
</div>
<div id="answers">
<a name="tab-top"></a>
<div id="answers-header">
<div class="answers-subheader d-flex ai-center mb8">
<div class="flex--item fl1">
<h2 class="mb0" data-answercount="4">
4 Answers
<span style="display:none;" itemprop="answerCount">4</span>
</h2>
</div>
<div class="flex--item">
<div class="d-flex g4 gsx ai-center sm:fd-column sm:ai-start">
<div class="d-flex fd-column ai-end sm:ai-start">
<label class="flex--item fs-caption" for="answer-sort-dropdown-select-menu">
Sorted by:
</label>
<a
class="js-sort-preference-change s-link flex--item fs-fine d-none"
data-value="ScoreDesc"
href="/questions/27986/text-based-rpg-game-using-classes?answertab=scoredesc#tab-top"
>
Reset to default
</a>
</div>
<div class="flex--item s-select">
<select id="answer-sort-dropdown-select-menu">
<option
value=scoredesc
selected=selected
>
Highest score (default)
</option>
<option
value=modifieddesc
>
Date modified (newest first)
</option>
<option
value=createdasc
>
Date created (oldest first)
</option>
</select>
</div>
</div>
</div>
</div>
</div>
<a name="28000"></a>
<div id="answer-28000" class="answer js-answer accepted-answer js-accepted-answer" data-answerid="28000" data-parentid="27986" data-score="16" data-position-on-page="1" data-highest-scored="1" data-question-has-accepted-highest-score="1" data-author-reputation="34984" itemprop="acceptedAnswer" itemscope itemtype="https://schema.org/Answer">
<div class="post-layout">
<div class="votecell post-layout--left">
<div class="js-voting-container d-flex jc-center fd-column ai-center gs4 fc-black-300" data-post-id="28000" data-referrer="None">
<button class="js-vote-up-btn flex--item s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id="upvote-btn-28000"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
title="This answer is useful"
aria-pressed="false"
aria-label="Up vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowUp" width="18" height="18" viewBox="0 0 18 18"><path d="M1 12h16L9 4z"/></svg>
</button>
<input type="hidden" id="voteUpHash" value="67:3:31e,16:973aa532c4524444,10:1743331693,16:3c86c32a1177cd76,5:28000,4eab992191315b0653a2cdd9b1cd3cbf2a047610d4e311b56bc60cf7b025cecd" />
<div class="js-vote-count flex--item d-flex fd-column ai-center fc-theme-body-font fw-bold fs-subheading py4"
itemprop="upvoteCount"
data-value="16">
16 </div>
<button
class="js-vote-down-btn flex--item mb8 s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id=downvote-btn-28000
title="This answer is not useful"
aria-pressed="false"
aria-label="Down vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowDown" width="18" height="18" viewBox="0 0 18 18"><path d="M1 6h16l-8 8z"/></svg>
</button>
<input type="hidden" id="voteDownHash" value="67:3:31e,16:1876cf957defa7bd,10:1743331693,16:824cfcd7454cb41a,5:28000,07d2144f34eac631002f6fad7abbe0aa1f3e0f09412922b50cbbf1fa2bc345bc" />
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
type="button"
id="saves-btn-28000"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
data-s-popover-placement=""
title="Save this answer."
data-is-saved="false"
aria-label="Save"
data-post-id="28000"
data-post-type-id="2"
data-user-privilege-for-post-click="-1"
aria-controls=""
data-s-popover-auto-show="false"
>
<svg aria-hidden="true" class="fc-theme-primary-400 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
<svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26zM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
</button>
<div class="js-accepted-answer-indicator flex--item fc-green-400 py6 mtn8" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
<div class="ta-center">
<svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8z"/></svg>
</div>
</div>
<a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/28000/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10z"/></svg></a>
</div>
</div>
<div class="answercell post-layout--right">
<span class="d-none">\$\begingroup\$</span>
<div class="s-prose js-post-body" itemprop="text">
<ul>
<li><p>Try not to get in the habit of using <code>using namespace std</code>. Read <a href="https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice">this</a> for more information.</p></li>
<li><p>For clarity, have your <code>#include</code>s organized. Read <a href="http://blog.knatten.org/2010/07/01/the-order-of-include-directives-matter/" rel="nofollow noreferrer">this blog post</a> or <a href="https://stackoverflow.com/questions/2762568/c-c-include-file-order-best-practices">this answer</a> for more information.</p></li>
<li><p>Add a newline between each section of code. For instance, separate all user input and loops. For variables, it's best to initialize them late as late as possible in case the function needs to terminate prematurely. Again, keep them with the corresponding code.</p></li>
<li><p><code>mobclass.h</code> already includes <code>&lt;string&gt;</code>, so you don't need to include it again in the .cpp file.</p></li>
<li><p>You have a lot of accessors and mutators. Since these are short one-line implementations, you can define them in the header like this:</p>
<pre><code>void setEXP() {EXP = (getlevel() * 35;}
int getEXP() const {return EXP;}
</code></pre>
<p>As such, you will no longer need to implement these in the .cpp file. When they're in the header, they'll automatically be <code>inline</code>. It should also make it easier if you ever need to implement newer functions. In the header, you could also keep the accessors and mutators together for clarity.</p></li>
<li><p>I like what @Kaivo Anastetiks said about <code>classMob</code>'s constructor, but I would like to add on that a bit. You have a few options for this:</p>
<ol>
<li>keep it in the .cpp file (with those changes)</li>
<li>put it in the header (with the <code>classMob::</code> part removed)</li>
<li>put it under the class declaration in the same file</li>
</ol></li>
<li><p>It's better to use <code>getline()</code> instead of <code>cin</code> for getting an <code>std::string</code> value from the user:</p>
<pre><code>getline(std::cin, name);
</code></pre></li>
<li><p><code>srand()</code> should ONLY be called ONCE in the program, preferably at the top of <code>main()</code>. If you keep it as is, <code>rand()</code> will be "not-so-random" because the seed will keep resetting to 0.</p></li>
<li><p>That really long output line in <code>battle()</code>'s do-while loop could be wrapped so that it doesn't extend out that far.</p></li>
<li><p>For <code>death()</code>: there's no need to have a function <em>just</em> output a message. Either have it do something else relevant, or just remove it.</p></li>
<li><p>For the player's death (in general): I would prefer the function to fall back to <code>main()</code> instead of explicitly exiting. This is because:</p>
<ol>
<li>it's clearer to let <code>main()</code> terminate the program whenever possible</li>
<li>it could be hard to tell where the player's death is determined</li>
</ol>
<p>You would then need to change <code>main()</code>'s loop to handle this. You could even have <code>battle()</code> return a <code>bool</code> to indicate the battle outcome (the player has won or has lost). Try this at the end:</p>
<pre><code>account = calcEXP(account, monster);
if (account.getHealth() &lt;= 0)
return false;
return true;
</code></pre>
<p>You could even create a <code>bool</code> member function for determining if the player's health was depleted:</p>
<pre><code>bool healthDepleted() const {return playerHealth &lt;= 0;}
</code></pre></li>
<li><p>If you're just mutating data members in <code>calcEXP()</code> and <code>levelUp()</code>, they don't need to return anything. Just make those functions <code>void</code>.</p></li>
<li><p>Your "saving" problem is due to your functions receiving the objects <em>by value</em>. It should be received <em>by reference</em> instead. You were only passing in a copy and modifying it, only to have those changes discarded each time those functions ended. This change will allow you to modify the original objects:</p>
<pre><code>bool battle(player &amp;account);
void calcEXP(player &amp;account, classMob &amp;monster);
</code></pre></li>
<li><p>After looking at <code>mobClass</code>'s definition, it appears that you may not need those mutators. You should consider a <code>mobClass</code> instance as an <em>individual</em> monster, just as a <code>player</code> is just <em>one</em> player. As such, you just need to construct each <code>mobClass</code> once with the default stats. The accessors are still okay.</p></li>
<li><p>Once again, I forgot about this: create a <code>Game</code> class. Since the human player doesn't need to know how the game's internal mechanisms work, you would no longer need those extra functions in the driver. Instead, <code>main()</code> will create a <code>Game</code> and the class will handle the rest. Here's (roughly) what <code>main()</code> could look like:</p>
<pre><code>int main()
{
std::srand(std::time(NULL));
Game game;
game.play();
}
</code></pre>
<p>That may be <em>too</em> little for <code>main()</code>, but the idea is that <code>Game</code> will handle everything. Every function in <code>Game</code>, except for <code>play()</code>, should be <code>private</code>. <code>Game</code> should contain a <code>player</code> as a data member and instantiated in <code>Game</code>'s constructor. If you end up implementing your map idea (or anything similar), that would be instantiated in the constructor as well. You may still keep those extra driver functions, but they should be called in <code>play()</code> instead.</p>
<p>As for <code>classMob</code>, you could create an <code>std::vector</code> of objects (you cannot predict how many monsters will "spawn" before the player dies). New monsters would be added and, when killed by the player, removed. If you maintain a counter, you could even track the number of monsters killed before defeat.</p></li>
</ul>
</div>
<div class="mt24">
<div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
<time itemprop="dateCreated" datetime="2013-07-01 17:21:26Z"></time>
<div class="flex--item mr16" style="flex: 1 1 100px;">
<div class="js-post-menu pt2" data-post-id="28000" data-post-type-id="2">
<div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">
<div class="flex--item">
<a href="/a/28000/289986"
rel="nofollow"
itemprop="url"
class="js-share-link js-gps-track"
title="Short permalink to this answer"
data-gps-track="post.click({ item: 2, priv: -1, post_type: 2 })"
data-controller="se-share-sheet"
data-se-share-sheet-title="Share a link to this answer"
data-se-share-sheet-subtitle="(Includes your user id)"
data-se-share-sheet-post-type="answer"
data-se-share-sheet-social="facebook twitter "
data-se-share-sheet-location="2"
data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
data-se-share-sheet-license-name="CC BY-SA 3.0"
data-s-popover-placement="bottom-start">Share</a>
</div>
<div class="flex--item">
<a href="/posts/28000/edit" class="js-suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: -1, post_type: 2 })" title="Revise and improve this post">Edit</a>
</div>
<div class="flex--item">
<button type="button"
id="btnFollowPost-28000" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
data-gps-track="post.click({ item: 14, priv: -1, post_type: 2 })"
data-controller="s-tooltip " data-s-tooltip-placement="bottom"
data-s-popover-placement="bottom" aria-controls=""
title="Follow this answer to receive notifications">
Follow
<input type="hidden" id="voteFollowHash" value="67:3:31e,16:c94f7503e0fcbee4,10:1743331693,16:dc79f749749f339a,5:28000,334e5ad5b431e138f3badff6798a58e4dc0099f230da7c4a8fd39a34051a94cc" />
</button>
</div>
</div>
<div class="js-menu-popup-container"></div>
</div>
</div>
<div class="post-signature flex--item fl0">
<div class="user-info user-hover ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
<a href="/posts/28000/revisions" title="show all edits to this post"
class="js-gps-track"
data-gps-track="post.click({ item: 4, priv: -1, post_type: 2 })">edited <span title='2017-05-23 12:41:07Z' class='relativetime'>May 23, 2017 at 12:41</span></a>
</div>
</div>
<div class="user-gravatar32">
<a href="/users/-1/community"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?s=64&amp;d=identicon&amp;r=PG" alt="Community&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
</div>
<div class="user-details">
<a href="/users/-1/community" dir="auto">Community</a><span class="flex--item s-badge ml2 s-badge__xs mtn2" title="Community Bot — not a real person. Replies to this bot are not monitored.">Bot</span>
<div class="-flair">
<span class="reputation-score" title="reputation score " dir="ltr">1</span>
</div>
</div>
</div>
</div>
<div class="post-signature flex--item fl0">
<div class="user-info ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
answered <span title='2013-07-01 17:21:26Z' class='relativetime'>Jul 1, 2013 at 17:21</span>
</div>
</div>
<div class="user-gravatar32">
<a href="/users/22222/jamal"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/4b97c146bd7883eed4ea0df70a16a71b?s=64&amp;d=identicon&amp;r=PG&amp;f=y&amp;so-version=2" alt="Jamal&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
</div>
<div class="user-details" itemprop="author" itemscope itemtype="http://schema.org/Person">
<a href="/users/22222/jamal" itemprop="url" dir="auto">Jamal</a><span class="d-none" itemprop="name">Jamal</span>
<div class="-flair">
<span class="reputation-score" title="reputation score 34,984" dir="ltr">35k</span><span title="13 gold badges" aria-hidden="true"><span class="badge1"></span><span class="badgecount">13</span></span><span class="v-visible-sr">13 gold badges</span><span title="134 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">134</span></span><span class="v-visible-sr">134 silver badges</span><span title="237 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">237</span></span><span class="v-visible-sr">237 bronze badges</span>
</div>
</div>
</div>
</div>
</div>
</div>
<span class="d-none">\$\endgroup\$</span>
</div>
<span class="d-none" itemprop="commentCount">22</span>
<div class="post-layout--right js-post-comments-component">
<div id="comments-28000" class="comments js-comments-container bt bc-black-200 mt12 " data-post-id="28000" data-min-length="15">
<ul class="comments-list js-comments-list"
data-remaining-comments-count="17"
data-canpost="false"
data-cansee="true"
data-comments-unavailable="false"
data-addlink-disabled="true">
<li id="comment-43669" class="comment js-comment " data-comment-id="43669" data-comment-owner-id="3928" data-comment-score="7">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
<span title="number of &#x27;useful comment&#x27; votes received"
class="warm">7</span>
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">&quot;[K]eep all variable initializations at the top of the function&quot; -- I disagree. Variables should be declared as late as possible. This avoids unnecessary instantiation in case of exceptions or <code>return</code>s, and keeps them closer to the relevant context.</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/3928/lstor"
title="2,698 reputation"
class="comment-user">Lstor</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 17:36:58Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 17:36</span>
</span>
</div>
</div>
</li>
<li id="comment-43670" class="comment js-comment " data-comment-id="43670" data-comment-owner-id="3928" data-comment-score="3">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
<span title="number of &#x27;useful comment&#x27; votes received"
class="cool">3</span>
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">Regarding <code>#include</code> order: The recommended order is <b>1.</b> Include yourself (i.e. corresponding <code>.hpp</code> file from a <code>.cpp</code> file). <b>2.</b> Include other headers you have created yourself. <b>3a.</b> Include other <code>&quot;&quot;</code>-style headers. <b>3b.</b> Include non-std-lib <code>&lt;&gt;</code>-headers. <b>4.</b> Include standard library headers. Each section should be in alphabetical order. See <a href="http://blog.knatten.org/2010/07/01/the-order-of-include-directives-matter/" rel="nofollow noreferrer">this blog post</a> for an explanation, or <a href="http://stackoverflow.com/questions/2762568/c-c-include-file-order-best-practices">this answer</a>.</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/3928/lstor"
title="2,698 reputation"
class="comment-user">Lstor</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 17:41:30Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 17:41</span>
</span>
<span title="this comment was edited 1 time">
<svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path fill="#F1B600" d="m2 10.12 6.37-6.43 1.88 1.88L3.88 12H2z"/><path fill="#E87C87" d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0"/></svg>
</span>
</div>
</div>
</li>
<li id="comment-43675" class="comment js-comment " data-comment-id="43675" data-comment-owner-id="3928" data-comment-score="1">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
<span title="number of &#x27;useful comment&#x27; votes received"
class="cool">1</span>
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">The rest looks good. I think you mean &quot;<code>srand()</code> should only be <b>called</b> once&quot;, by the way.</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/3928/lstor"
title="2,698 reputation"
class="comment-user">Lstor</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 17:56:29Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 17:56</span>
</span>
</div>
</div>
</li>
<li id="comment-43690" class="comment js-comment " data-comment-id="43690" data-comment-owner-id="22222" data-comment-score="1">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
<span title="number of &#x27;useful comment&#x27; votes received"
class="cool">1</span>
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">It would still need the <code>player</code> object as an argument. Speaking of which, I found your &quot;saving&quot; problem. I&#39;ll update this answer.</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/22222/jamal"
title="34,984 reputation"
class="comment-user">Jamal</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 19:00:14Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 19:00</span>
</span>
</div>
</div>
</li>
<li id="comment-43696" class="comment js-comment " data-comment-id="43696" data-comment-owner-id="22222" data-comment-score="1">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
<span title="number of &#x27;useful comment&#x27; votes received"
class="cool">1</span>
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">The name <code>player</code> for the <code>class</code> describes the properties of an <i>instance</i> of said class, which is your object. In this game, you only have one player. Yes, you could still say <code>account1</code>, but the naming really is up to you. I&#39;m just trying to relate this to an actual video game (like Zelda). :-)</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/22222/jamal"
title="34,984 reputation"
class="comment-user">Jamal</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 19:43:07Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 19:43</span>
</span>
</div>
</div>
</li>
</ul>
</div>
<div id="comments-link-28000" data-rep=50 data-reg=true>
<a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;." href="#" role="button"></a>
<span class="js-link-separator dno">&nbsp;|&nbsp;</span>
<a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>17</b> more comments</a>
</div>
</div>
</div>
</div>
<div class="js-zone-container zone-container-main">
<div id="dfp-mlb" class="everyonelovesstackoverflow everyoneloves__mid-leaderboard everyoneloves__leaderboard"></div>
<div class="js-report-ad-button-container " style="width: 728px"></div>
</div>
<a name="28025"></a>
<div id="answer-28025" class="answer js-answer" data-answerid="28025" data-parentid="27986" data-score="8" data-position-on-page="2" data-highest-scored="0" data-question-has-accepted-highest-score="1" data-author-reputation="97129" itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
<div class="post-layout">
<div class="votecell post-layout--left">
<div class="js-voting-container d-flex jc-center fd-column ai-center gs4 fc-black-300" data-post-id="28025" data-referrer="None">
<button class="js-vote-up-btn flex--item s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id="upvote-btn-28025"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
title="This answer is useful"
aria-pressed="false"
aria-label="Up vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowUp" width="18" height="18" viewBox="0 0 18 18"><path d="M1 12h16L9 4z"/></svg>
</button>
<input type="hidden" id="voteUpHash" value="67:3:31e,16:e47149298cfa1973,10:1743331693,16:4a6aef4baf7bc606,5:28025,fffae595ba95ad5785a84cde4f46118180c327fa16aee0c2cab6ba4665c31866" />
<div class="js-vote-count flex--item d-flex fd-column ai-center fc-theme-body-font fw-bold fs-subheading py4"
itemprop="upvoteCount"
data-value="8">
8 </div>
<button
class="js-vote-down-btn flex--item mb8 s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id=downvote-btn-28025
title="This answer is not useful"
aria-pressed="false"
aria-label="Down vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowDown" width="18" height="18" viewBox="0 0 18 18"><path d="M1 6h16l-8 8z"/></svg>
</button>
<input type="hidden" id="voteDownHash" value="67:3:31e,16:31e702220c8a90d9,10:1743331693,16:41c540df206209c7,5:28025,2dbceeb693a0b3f5fbe112753890b836e7e24caa9e4d02aa1d34fc3ad8b32bcc" />
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
type="button"
id="saves-btn-28025"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
data-s-popover-placement=""
title="Save this answer."
data-is-saved="false"
aria-label="Save"
data-post-id="28025"
data-post-type-id="2"
data-user-privilege-for-post-click="-1"
aria-controls=""
data-s-popover-auto-show="false"
>
<svg aria-hidden="true" class="fc-theme-primary-400 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
<svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26zM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
</button>
<div class="js-accepted-answer-indicator flex--item fc-green-400 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
<div class="ta-center">
<svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8z"/></svg>
</div>
</div>
<a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/28025/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10z"/></svg></a>
</div>
</div>
<div class="answercell post-layout--right">
<span class="d-none">\$\begingroup\$</span>
<div class="s-prose js-post-body" itemprop="text">
<p>Your classes are designed badly:</p>
<pre><code>class player
{
public:
player(std::string,std::string,int,int);
void setName(std::string);
void setArea(std::string);
void setLevel(int);
void setEXP(double);
void setHealth(double);
void setMaxHealth();
void setDamage();
std::string getName();
std::string getArea();
int getLevel();
double getHealth();
double getMaxHealth();
int getDamage();
int getEXP();
void setEXP(int);
int getEXPReq();
void setEXPReq();
private:
std::string playerName;
std::string playerArea;
int playerLevel;
double playerHealth;
double playerMaxHealth;
int playerDamage;
int EXP;
int EXPReq;
};
</code></pre>
<p>You are exposing all the internal members (they just happen to be behind shallow get/set functions). But you are tightly coupling your class to the actual types you use for storage. This tight coupling makes your code very brittle; any change is going to ripple through your code requiring any code that uses your class to also change.</p>
<p>Your class methods should be &quot;VERBS&quot; that describe actions that happen on your obeject (thus not exposing the internal types).</p>
<p>Example Leveling up:<br />
The only reason you have a bunch of these getters is so that an external function can get update then update the value.</p>
<pre><code>player levelUp(player account)
{
account.setLevel(account.getLevel()+1);
account.setEXPReq();
account.setMaxHealth();
account.setHealth(account.getMaxHealth());
cout &lt;&lt; &quot;Level up! you are now level: &quot; &lt;&lt; account.getLevel() &lt;&lt; &quot;!\n&quot;;
return account;
}
</code></pre>
<p>The problem here is that you loose control of leveling up. With this technique anybody can write an alternative way of leveling up. Then if things change you need to find and modify all the techniques when you change how leveling up is done.</p>
<p>This should all be part of the player class that way leveling up is controlled as part of the player. It is done in one place (and only one place):</p>
<pre><code>player Player::levelUp()
{
playerLevel++;
EXPReq = 70 + (playerLevel * playerLevel) * 35;
playerMaxHealth = 100 * playerLevel;
playerHealth = playerMaxHealth;
cout &lt;&lt; &quot;Level up! you are now level: &quot; &lt;&lt; account.getLevel() &lt;&lt; &quot;!\n&quot;;
}
</code></pre>
<p>You can basically remove all the getter/setter methods and put in methods that actual manipulate the object.</p>
<h3>Edit Based on Comment:</h3>
<blockquote>
<p>hm I am getting one problem though, so in the function calcEXP I am using monster.getEXP(); and i know that in the function battle I use some of the get functions to get information about the classMob class. How can i acess this without the use of get functions ?</p>
</blockquote>
<p>Couple of ways. But I think the simplest is to make a common base class that handles this stuff:</p>
<pre><code> class LifeForm
{
// Traits that are common to both players and monsters.
int EXP;
int EXPReq;
void levelUp() {}
public:
void hasKilled(LifeForm const&amp; deadLifeForm)
{
// Absorb the experience of the foe.
EXP += deadLifeForm.EXP;
if (EXP &gt;= EXPReq)
{
levelUp();
}
}
};
class Person: public LifeForm
{
};
class Monster: public LifeForm
{
};
</code></pre>
<p>The <code>LifeForm</code> class understands the concept of experience (maybe other stuff) and handles the interaction between two lifeforms. Since an object has access to the private members of other objects of the same class it works fine.</p>
</div>
<div class="mt24">
<div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
<time itemprop="dateCreated" datetime="2013-07-02 05:29:48Z"></time>
<div class="flex--item mr16" style="flex: 1 1 100px;">
<div class="js-post-menu pt2" data-post-id="28025" data-post-type-id="2">
<div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">
<div class="flex--item">
<a href="/a/28025/289986"
rel="nofollow"
itemprop="url"
class="js-share-link js-gps-track"
title="Short permalink to this answer"
data-gps-track="post.click({ item: 2, priv: -1, post_type: 2 })"
data-controller="se-share-sheet"
data-se-share-sheet-title="Share a link to this answer"
data-se-share-sheet-subtitle="(Includes your user id)"
data-se-share-sheet-post-type="answer"
data-se-share-sheet-social="facebook twitter "
data-se-share-sheet-location="2"
data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
data-se-share-sheet-license-name="CC BY-SA 3.0"
data-s-popover-placement="bottom-start">Share</a>
</div>
<div class="flex--item">
<a href="/posts/28025/edit" class="js-suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: -1, post_type: 2 })" title="Revise and improve this post">Edit</a>
</div>
<div class="flex--item">
<button type="button"
id="btnFollowPost-28025" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
data-gps-track="post.click({ item: 14, priv: -1, post_type: 2 })"
data-controller="s-tooltip " data-s-tooltip-placement="bottom"
data-s-popover-placement="bottom" aria-controls=""
title="Follow this answer to receive notifications">
Follow
<input type="hidden" id="voteFollowHash" value="67:3:31e,16:77448b8e62662e2a,10:1743331693,16:6253614d5ea59bc0,5:28025,4cb0cb8de9ce2e67e6a375065651fcb81a21b2877e2e09433522668a1ad253f8" />
</button>
</div>
</div>
<div class="js-menu-popup-container"></div>
</div>
</div>
<div class="post-signature flex--item fl0">
<div class="user-info user-hover ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
<a href="/posts/28025/revisions" title="show all edits to this post"
class="js-gps-track"
data-gps-track="post.click({ item: 4, priv: -1, post_type: 2 })">edited <span title='2020-06-10 13:24:26Z' class='relativetime'>Jun 10, 2020 at 13:24</span></a>
</div>
</div>
<div class="user-gravatar32">
<a href="/users/-1/community"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?s=64&amp;d=identicon&amp;r=PG" alt="Community&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
</div>
<div class="user-details">
<a href="/users/-1/community" dir="auto">Community</a><span class="flex--item s-badge ml2 s-badge__xs mtn2" title="Community Bot — not a real person. Replies to this bot are not monitored.">Bot</span>
<div class="-flair">
<span class="reputation-score" title="reputation score " dir="ltr">1</span>
</div>
</div>
</div>
</div>
<div class="post-signature flex--item fl0">
<div class="user-info ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
answered <span title='2013-07-02 05:29:48Z' class='relativetime'>Jul 2, 2013 at 5:29</span>
</div>
</div>
<div class="user-gravatar32">
<a href="/users/507/loki-astari"><div class="gravatar-wrapper-32"><img src="https://i.sstatic.net/QTZlD.png?s=64" alt="Loki Astari&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
</div>
<div class="user-details" itemprop="author" itemscope itemtype="http://schema.org/Person">
<a href="/users/507/loki-astari" itemprop="url" dir="auto">Loki Astari</a><span class="d-none" itemprop="name">Loki Astari</span>
<div class="-flair">
<span class="reputation-score" title="reputation score 97,129" dir="ltr">97.1k</span><span title="5 gold badges" aria-hidden="true"><span class="badge1"></span><span class="badgecount">5</span></span><span class="v-visible-sr">5 gold badges</span><span title="126 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">126</span></span><span class="v-visible-sr">126 silver badges</span><span title="340 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">340</span></span><span class="v-visible-sr">340 bronze badges</span>
</div>
</div>
</div>
</div>
</div>
</div>
<span class="d-none">\$\endgroup\$</span>
</div>
<span class="d-none" itemprop="commentCount">14</span>
<div class="post-layout--right js-post-comments-component">
<div id="comments-28025" class="comments js-comments-container bt bc-black-200 mt12 " data-post-id="28025" data-min-length="15">
<ul class="comments-list js-comments-list"
data-remaining-comments-count="9"
data-canpost="false"
data-cansee="true"
data-comments-unavailable="false"
data-addlink-disabled="true">
<li id="comment-43731" class="comment js-comment " data-comment-id="43731" data-comment-owner-id="26827" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">Ah I see, I will start changing this. Thanks!</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/26827/sumsar1812"
title="355 reputation"
class="comment-user owner">Sumsar1812</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-02 10:53:37Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 2, 2013 at 10:53</span>
</span>
</div>
</div>
</li>
<li id="comment-43732" class="comment js-comment " data-comment-id="43732" data-comment-owner-id="26827" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">ehm I am getting one problem though, so in the function calcEXP I am using monster.getEXP(); and i know that in the function battle I use some of the get functions to get information about the classMob class. How can i acess this without the use of get functions ?</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/26827/sumsar1812"
title="355 reputation"
class="comment-user owner">Sumsar1812</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-02 11:12:52Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 2, 2013 at 11:12</span>
</span>
</div>
</div>
</li>
<li id="comment-43741" class="comment js-comment " data-comment-id="43741" data-comment-owner-id="507" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">@Sumsar1812: See update</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/507/loki-astari"
title="97,129 reputation"
class="comment-user">Loki Astari</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-02 15:25:42Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 2, 2013 at 15:25</span>
</span>
</div>
</div>
</li>
<li id="comment-43742" class="comment js-comment " data-comment-id="43742" data-comment-owner-id="22222" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">@LokiAstari: Thank you for posting this update before I had the slightest idea of mentioning <code>friend</code>. I really need to learn how to use inheritance in my own code.</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/22222/jamal"
title="34,984 reputation"
class="comment-user">Jamal</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-02 15:30:36Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 2, 2013 at 15:30</span>
</span>
</div>
</div>
</li>
<li id="comment-43749" class="comment js-comment " data-comment-id="43749" data-comment-owner-id="507" data-comment-score="1">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
<span title="number of &#x27;useful comment&#x27; votes received"
class="cool">1</span>
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">@Jamal: If used incorrectly any functionality is bad. But used correctly <code>friend</code> increases (ie is good for) encapsulation (at the cost of tight coupling). See <a href="http://programmers.stackexchange.com/a/99595/12917">programmers.stackexchange.com/a/99595/12917</a></span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/507/loki-astari"
title="97,129 reputation"
class="comment-user">Loki Astari</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-02 18:32:14Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 2, 2013 at 18:32</span>
</span>
</div>
</div>
</li>
</ul>
</div>
<div id="comments-link-28025" data-rep=50 data-reg=true>
<a class="js-add-link comments-link dno" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;." href="#" role="button"></a>
<span class="js-link-separator dno">&nbsp;|&nbsp;</span>
<a class="js-show-link comments-link " title="Expand to show all comments on this post" href=# onclick="" role="button">Show <b>9</b> more comments</a>
</div>
</div>
</div>
</div>
<a name="28065"></a>
<div id="answer-28065" class="answer js-answer" data-answerid="28065" data-parentid="27986" data-score="7" data-position-on-page="3" data-highest-scored="0" data-question-has-accepted-highest-score="1" data-author-reputation="3152" itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
<div class="post-layout">
<div class="votecell post-layout--left">
<div class="js-voting-container d-flex jc-center fd-column ai-center gs4 fc-black-300" data-post-id="28065" data-referrer="None">
<button class="js-vote-up-btn flex--item s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id="upvote-btn-28065"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
title="This answer is useful"
aria-pressed="false"
aria-label="Up vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowUp" width="18" height="18" viewBox="0 0 18 18"><path d="M1 12h16L9 4z"/></svg>
</button>
<input type="hidden" id="voteUpHash" value="67:3:31e,16:957920d7f18555c6,10:1743331693,16:0195b22c9de98d56,5:28065,8e4f1962b2774519855f1d7e604585b9f62729b66a574abf493727d2433d5bb1" />
<div class="js-vote-count flex--item d-flex fd-column ai-center fc-theme-body-font fw-bold fs-subheading py4"
itemprop="upvoteCount"
data-value="7">
7 </div>
<button
class="js-vote-down-btn flex--item mb8 s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id=downvote-btn-28065
title="This answer is not useful"
aria-pressed="false"
aria-label="Down vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowDown" width="18" height="18" viewBox="0 0 18 18"><path d="M1 6h16l-8 8z"/></svg>
</button>
<input type="hidden" id="voteDownHash" value="67:3:31e,16:65c32aa2a287cd20,10:1743331693,16:2a04348aa0724049,5:28065,25e9a0dea6080223cbd471cb1da7fd4134c020a45c8abd1de2d12a695980a143" />
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
type="button"
id="saves-btn-28065"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
data-s-popover-placement=""
title="Save this answer."
data-is-saved="false"
aria-label="Save"
data-post-id="28065"
data-post-type-id="2"
data-user-privilege-for-post-click="-1"
aria-controls=""
data-s-popover-auto-show="false"
>
<svg aria-hidden="true" class="fc-theme-primary-400 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
<svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26zM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
</button>
<div class="js-accepted-answer-indicator flex--item fc-green-400 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
<div class="ta-center">
<svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8z"/></svg>
</div>
</div>
<a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/28065/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10z"/></svg></a>
</div>
</div>
<div class="answercell post-layout--right">
<span class="d-none">\$\begingroup\$</span>
<div class="s-prose js-post-body" itemprop="text">
<p>First off, decide whether, and to what degree, you want object orientedness.</p>
<p>If you want to keep the current design, you may want to use structs rather than classes. At the moment this isn't very object-oriented at all, and getting rid of the need for getters and setters for everyfreakingthing would reduce the amount of code by like 2/3. Making something private and adding a getter and setter that just blindly set the variable...that's not encapsulation. That's busywork. You're not really protecting anything, you end up having to declare and define the getter/setter, and you turn <code>player.health -= 10;</code> into <code>player.setHealth(player.getHealth() - 10);</code>, which is harder to read. :P</p>
<p>If you want to be more object-oriented about all this, the first thing to do is let the classes take more responsibility for their own internal state. As many as possible of the actions that involve modifying player attributes, should be in the <code>player</code> class. Same with monster attributes and <code>classMob</code>, of course.</p>
<p>Consider your current fight logic:</p>
<pre><code>player battle(player account) {
...
do {
...
if (option == "A" || option == "a")
{
int attack =rand()%(account.getDamage());
srand(time(NULL));
int mobAttack = rand()%(monster.getDamage());
monster.setHealth(monster.getHealth()-attack);
account.setHealth(account.getHealth()-mobAttack);
cout &lt;&lt; "you attack the monster for " &lt;&lt; attack &lt;&lt; " damage\n";
Sleep(500);
cout &lt;&lt; "the monster counter attacks for " &lt;&lt; mobAttack &lt;&lt; " damage\n";
Sleep(500);
}
} while (monster.getHealth() &gt;0 &amp;&amp; account.getHealth() &gt; 0);
...
if (account.getHealth() &lt;= 0)
{
death();
exit(0);
}
...
return account;
}
</code></pre>
<p>A huge amount of this is stuff that <code>classMob</code> and <code>player</code> could be handling. You could easily have something like </p>
<pre><code>int player::attack(classMob&amp; mob) {
int attack = rand() % damage;
mob.takeDamage(attack);
return attack;
}
void player::takeDamage(int damage) {
health -= damage;
if (health &lt; 0) health = 0;
}
bool player::isAlive() { return health &gt; 0; }
int classMob::attack(player&amp; p) {
int attack = rand() % damage;
p.takeDamage(attack);
return attack;
}
void classMob::takeDamage(int damage) {
health -= damage;
if (health &lt; 0) { health = 0; }
}
bool classMob::isAlive() { return health &gt; 0; }
</code></pre>
<p>Now your player and mob can attack each other, and the above main-manages-the-attack code turns into</p>
<pre><code>player battle(player account) {
...
do {
...
if (option == "A" || option == "a")
{
int attack = account.attack(monster);
cout &lt;&lt; "you attack the monster for " &lt;&lt; attack &lt;&lt; " damage\n";
Sleep(500);
int mobAttack = monster.attack(account);
cout &lt;&lt; "the monster counter attacks for " &lt;&lt; mobAttack &lt;&lt; " damage\n";
Sleep(500);
}
} while (monster.isAlive() &amp;&amp; account.isAlive());
... show status lines again ...
if ( !account.isAlive() )
{
death();
exit(0);
}
...
}
</code></pre>
<p>(By the way, if we take a look, we will see that monsters and players attack each other in the same way. In fact, they share a whole lot of the same attributes. It's starting to look like <code>classMob</code> and <code>player</code> should have a common ancestor, at least.)</p>
<p>It might not look that much better, and as of yet, it's still not great. But you gain a few things by giving players and mobs some autonomy:</p>
<ul>
<li><p>Clarity. When you want a mob to attack, you don't have to set the player's health to some lower amount determined by the mob's damage. You just <em>tell it to attack</em>. The resulting code is much more self-descriptive, which makes it much easier to follow.</p></li>
<li><p>Scalability. Eventually, you're going to want to add features -- like, say, health potions. Or spiffy weapons that increase the damage dealt. Or debuffs that occasionally make you or the mob miss a turn. If you leave the classes dumb and keep <code>main</code> doing all the manipulation, there will be a point where it's too painful to add more stuff.</p>
<p>With OOP done right, on the other hand, you get stuff done by telling an object to do something -- which often causes it to give orders to another object, which causes that other object to send messages to a bunch of others, and so on. The work's spread out, much more granular, and thanks to polymorphism, hot-swappable -- you can change the program's behavior on the fly by simply replacing some object with a compatible one that does things the way you want it to.</p></li>
</ul>
<hr>
<p>As far as the game goes, you might want to change how fleeing works. Right now, if i run away from a fight, the monster dies? And i get as much EXP as if i had stayed and killed it? Something's not right about that.</p>
</div>
<div class="mt24">
<div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
<time itemprop="dateCreated" datetime="2013-07-03 01:16:03Z"></time>
<div class="flex--item mr16" style="flex: 1 1 100px;">
<div class="js-post-menu pt2" data-post-id="28065" data-post-type-id="2">
<div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">
<div class="flex--item">
<a href="/a/28065/289986"
rel="nofollow"
itemprop="url"
class="js-share-link js-gps-track"
title="Short permalink to this answer"
data-gps-track="post.click({ item: 2, priv: -1, post_type: 2 })"
data-controller="se-share-sheet"
data-se-share-sheet-title="Share a link to this answer"
data-se-share-sheet-subtitle="(Includes your user id)"
data-se-share-sheet-post-type="answer"
data-se-share-sheet-social="facebook twitter "
data-se-share-sheet-location="2"
data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
data-se-share-sheet-license-name="CC BY-SA 3.0"
data-s-popover-placement="bottom-start">Share</a>
</div>
<div class="flex--item">
<a href="/posts/28065/edit" class="js-suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: -1, post_type: 2 })" title="Revise and improve this post">Edit</a>
</div>
<div class="flex--item">
<button type="button"
id="btnFollowPost-28065" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
data-gps-track="post.click({ item: 14, priv: -1, post_type: 2 })"
data-controller="s-tooltip " data-s-tooltip-placement="bottom"
data-s-popover-placement="bottom" aria-controls=""
title="Follow this answer to receive notifications">
Follow
<input type="hidden" id="voteFollowHash" value="67:3:31e,16:3b94d503fa5d3100,10:1743331693,16:8819230a0ce3dab8,5:28065,522f33ff61ecdad1af3afd1a7dd651bbfd0b4271432bd99a352bf6948f45e762" />
</button>
</div>
</div>
<div class="js-menu-popup-container"></div>
</div>
</div>
<div class="post-signature flex--item fl0">
<div class="user-info ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
<a href="/posts/28065/revisions" title="show all edits to this post"
class="js-gps-track"
data-gps-track="post.click({ item: 4, priv: -1, post_type: 2 })">edited <span title='2014-07-02 23:03:51Z' class='relativetime'>Jul 2, 2014 at 23:03</span></a>
</div>
</div>
<div class="user-gravatar32">
</div>
<div class="user-details">
<div class="-flair">
</div>
</div>
</div>
</div>
<div class="post-signature flex--item fl0">
<div class="user-info user-hover ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
answered <span title='2013-07-03 01:16:03Z' class='relativetime'>Jul 3, 2013 at 1:16</span>
</div>
</div>
<div class="user-gravatar32">
<a href="/users/1478/chao"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/e92a9af9e53cc8e5af575c4b18b34c21?s=64&amp;d=identicon&amp;r=PG" alt="cHao&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
</div>
<div class="user-details" itemprop="author" itemscope itemtype="http://schema.org/Person">
<a href="/users/1478/chao" itemprop="url" dir="auto">cHao</a><span class="d-none" itemprop="name">cHao</span>
<div class="-flair">
<span class="reputation-score" title="reputation score " dir="ltr">3,152</span><span title="18 silver badges" aria-hidden="true"><span class="badge2"></span><span class="badgecount">18</span></span><span class="v-visible-sr">18 silver badges</span><span title="21 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">21</span></span><span class="v-visible-sr">21 bronze badges</span>
</div>
</div>
</div>
</div>
</div>
</div>
<span class="d-none">\$\endgroup\$</span>
</div>
<span class="d-none" itemprop="commentCount"></span>
<div class="post-layout--right js-post-comments-component">
<div id="comments-28065" class="comments js-comments-container bt bc-black-200 mt12 dno" data-post-id="28065" data-min-length="15">
<ul class="comments-list js-comments-list"
data-remaining-comments-count="0"
data-canpost="false"
data-cansee="true"
data-comments-unavailable="false"
data-addlink-disabled="true">
</ul>
</div>
<div id="comments-link-28065" data-rep=50 data-reg=true>
<a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;." href="#" role="button">Add a comment</a>
<span class="js-link-separator dno">&nbsp;|&nbsp;</span>
<a class="js-show-link comments-link dno" title="Expand to show all comments on this post" href=# onclick="" role="button"></a>
</div>
</div>
</div>
</div>
<div class="js-zone-container zone-container-main">
<div id="dfp-smlb" class="everyonelovesstackoverflow everyoneloves__mid-second-leaderboard everyoneloves__leaderboard"></div>
<div class="js-report-ad-button-container " style="width: 728px"></div>
</div>
<a name="27996"></a>
<div id="answer-27996" class="answer js-answer" data-answerid="27996" data-parentid="27986" data-score="3" data-position-on-page="4" data-highest-scored="0" data-question-has-accepted-highest-score="1" data-author-reputation="143" itemprop="suggestedAnswer" itemscope itemtype="https://schema.org/Answer">
<div class="post-layout">
<div class="votecell post-layout--left">
<div class="js-voting-container d-flex jc-center fd-column ai-center gs4 fc-black-300" data-post-id="27996" data-referrer="None">
<button class="js-vote-up-btn flex--item s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id="upvote-btn-27996"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
title="This answer is useful"
aria-pressed="false"
aria-label="Up vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowUp" width="18" height="18" viewBox="0 0 18 18"><path d="M1 12h16L9 4z"/></svg>
</button>
<input type="hidden" id="voteUpHash" value="67:3:31e,16:dee9532167e34d65,10:1743331693,16:a178b7f35733a580,5:27996,d3e3b79c3aea05ee12dfedbd8ac6df041aaa592df105505a90c656be0ad8ae58" />
<div class="js-vote-count flex--item d-flex fd-column ai-center fc-theme-body-font fw-bold fs-subheading py4"
itemprop="upvoteCount"
data-value="3">
3 </div>
<button
class="js-vote-down-btn flex--item mb8 s-btn s-btn__muted s-btn__outlined bar-pill bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200"
id=downvote-btn-27996
title="This answer is not useful"
aria-pressed="false"
aria-label="Down vote"
data-selected-classes="fc-theme-primary-100 bc-theme-primary-500 bg-theme-primary-500"
data-unselected-classes="bc-black-225 f:bc-theme-secondary-400 f:bg-theme-secondary-400 f:fc-black-050 h:bg-theme-primary-200">
<svg aria-hidden="true" class="svg-icon iconArrowDown" width="18" height="18" viewBox="0 0 18 18"><path d="M1 6h16l-8 8z"/></svg>
</button>
<input type="hidden" id="voteDownHash" value="67:3:31e,16:9eb386b19ab37859,10:1743331693,16:df19bdf760469be8,5:27996,d90d42f0996f2abae501512246d8bac08372dc1e689909b2141f0c63489e9456" />
<button class="js-saves-btn s-btn s-btn__unset c-pointer py4"
type="button"
id="saves-btn-27996"
data-controller="s-tooltip"
data-s-tooltip-placement="right"
data-s-popover-placement=""
title="Save this answer."
data-is-saved="false"
aria-label="Save"
data-post-id="27996"
data-post-type-id="2"
data-user-privilege-for-post-click="-1"
aria-controls=""
data-s-popover-auto-show="false"
>
<svg aria-hidden="true" class="fc-theme-primary-400 js-saves-btn-selected d-none svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
<svg aria-hidden="true" class="js-saves-btn-unselected svg-icon iconBookmarkAlt" width="18" height="18" viewBox="0 0 18 18"><path d="m9 10.6 4 2.66V3H5v10.26zM3 17V3c0-1.1.9-2 2-2h8a2 2 0 0 1 2 2v14l-6-4z"/></svg>
</button>
<div class="js-accepted-answer-indicator flex--item fc-green-400 py6 mtn8 d-none" data-s-tooltip-placement="right" title="Loading when this answer was accepted&#x2026;" tabindex="0" role="note" aria-label="Accepted">
<div class="ta-center">
<svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8z"/></svg>
</div>
</div>
<a class="js-post-issue flex--item s-btn s-btn__unset c-pointer py6 mx-auto" href="/posts/27996/timeline" data-shortcut="T" data-ks-title="timeline" data-controller="s-tooltip" data-s-tooltip-placement="right" title="Show activity on this post." aria-label="Timeline"><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" width="19" height="18" viewBox="0 0 19 18"><path d="M3 9a8 8 0 1 1 3.73 6.77L8.2 14.3A6 6 0 1 0 5 9l3.01-.01-4 4-4-4zm7-4h1.01L11 9.36l3.22 2.1-.6.93L10 10z"/></svg></a>
</div>
</div>
<div class="answercell post-layout--right">
<span class="d-none">\$\begingroup\$</span>
<div class="s-prose js-post-body" itemprop="text">
<p>For the classes, the get functions could have a const keyword in their prototype since they aren't supposed to change any value. That will just make it impossible for them to do so and will make it possible to use them in other const functions.</p>
<p>In the .h</p>
<pre><code>int getDamage() const;
</code></pre>
<p>In the .cpp</p>
<pre><code>int player::getDamage() const {...}
</code></pre>
<p>Also, the get and maybe even set functions could be declared inline, placed at the end of the .h file, to avoid function calls. Inline functions are not compiled as functions. Instead, the body of the function kind of replaces the function call when compiled, similar to Macros. This way, on runtime, there's no actual function call. It's perfect when returning values.</p>
<p>In the class declaration:</p>
<pre><code>class player
{
public:
int getDamage() const;
}
</code></pre>
<p>In the .h after the class declaration:</p>
<pre><code>inline int player::getDamage() const {return damage;}
</code></pre>
<p>For the constructor, instead of calling the set functions, you could add the values before the function body:</p>
<pre><code>classMob::classMob(std::string name,int lvl,std::string area,int difficulty)
: mobName(name), mobLevel(lvl), mobArea(area), mobDifficulty(difficulty)
{
// ...
}
</code></pre>
</div>
<div class="mt24">
<div class="d-flex fw-wrap ai-start jc-end gs8 gsy">
<time itemprop="dateCreated" datetime="2013-07-01 13:42:26Z"></time>
<div class="flex--item mr16" style="flex: 1 1 100px;">
<div class="js-post-menu pt2" data-post-id="27996" data-post-type-id="2">
<div class="d-flex gs8 s-anchors s-anchors__muted fw-wrap">
<div class="flex--item">
<a href="/a/27996/289986"
rel="nofollow"
itemprop="url"
class="js-share-link js-gps-track"
title="Short permalink to this answer"
data-gps-track="post.click({ item: 2, priv: -1, post_type: 2 })"
data-controller="se-share-sheet"
data-se-share-sheet-title="Share a link to this answer"
data-se-share-sheet-subtitle="(Includes your user id)"
data-se-share-sheet-post-type="answer"
data-se-share-sheet-social="facebook twitter "
data-se-share-sheet-location="2"
data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f"
data-se-share-sheet-license-name="CC BY-SA 3.0"
data-s-popover-placement="bottom-start">Share</a>
</div>
<div class="flex--item">
<a href="/posts/27996/edit" class="js-suggest-edit-post js-gps-track" data-gps-track="post.click({ item: 6, priv: -1, post_type: 2 })" title="Revise and improve this post">Edit</a>
</div>
<div class="flex--item">
<button type="button"
id="btnFollowPost-27996" class="s-btn s-btn__link js-follow-post js-follow-answer js-gps-track"
data-gps-track="post.click({ item: 14, priv: -1, post_type: 2 })"
data-controller="s-tooltip " data-s-tooltip-placement="bottom"
data-s-popover-placement="bottom" aria-controls=""
title="Follow this answer to receive notifications">
Follow
<input type="hidden" id="voteFollowHash" value="67:3:31e,16:cbaf0677ecc3c393,10:1743331693,16:15cc4a6689a63dc1,5:27996,68c7a9670420ec187cf58a46c99707ba8f8a8e336b240df8f5b82d74a99ca80b" />
</button>
</div>
</div>
<div class="js-menu-popup-container"></div>
</div>
</div>
<div class="post-signature flex--item fl0">
<div class="user-info ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
<a href="/posts/27996/revisions" title="show all edits to this post"
class="js-gps-track"
data-gps-track="post.click({ item: 4, priv: -1, post_type: 2 })">edited <span title='2013-07-01 16:07:38Z' class='relativetime'>Jul 1, 2013 at 16:07</span></a>
</div>
</div>
<div class="user-gravatar32">
</div>
<div class="user-details">
<div class="-flair">
</div>
</div>
</div>
</div>
<div class="post-signature flex--item fl0">
<div class="user-info ">
<div class="d-flex ">
<div class="user-action-time fl-grow1">
answered <span title='2013-07-01 13:42:26Z' class='relativetime'>Jul 1, 2013 at 13:42</span>
</div>
</div>
<div class="user-gravatar32">
<a href="/users/24666/guillaume-rochat"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/9e330de1aaf23c9ba02b6a987461ea8b?s=64&amp;d=identicon&amp;r=PG" alt="Guillaume Rochat&#39;s user avatar" width="32" height="32" class="bar-sm"></div></a>
</div>
<div class="user-details" itemprop="author" itemscope itemtype="http://schema.org/Person">
<a href="/users/24666/guillaume-rochat" itemprop="url" dir="auto">Guillaume Rochat</a><span class="d-none" itemprop="name">Guillaume Rochat</span>
<div class="-flair">
<span class="reputation-score" title="reputation score " dir="ltr">143</span><span title="1 silver badge" aria-hidden="true"><span class="badge2"></span><span class="badgecount">1</span></span><span class="v-visible-sr">1 silver badge</span><span title="8 bronze badges" aria-hidden="true"><span class="badge3"></span><span class="badgecount">8</span></span><span class="v-visible-sr">8 bronze badges</span>
</div>
</div>
</div>
</div>
</div>
</div>
<span class="d-none">\$\endgroup\$</span>
</div>
<span class="d-none" itemprop="commentCount">3</span>
<div class="post-layout--right js-post-comments-component">
<div id="comments-27996" class="comments js-comments-container bt bc-black-200 mt12 " data-post-id="27996" data-min-length="15">
<ul class="comments-list js-comments-list"
data-remaining-comments-count="0"
data-canpost="false"
data-cansee="true"
data-comments-unavailable="false"
data-addlink-disabled="true">
<li id="comment-43657" class="comment js-comment " data-comment-id="43657" data-comment-owner-id="26827" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">Ok I changed the get functions to have a const keyword in their prototype. I changed the get and set functions to be declared inline, witch results in I can clear almost all of my player.cpp file and my Mobclass.cpp file. I just want to be sure I am doing it the right way: void setEXP(){EXP = (getLevel() * 35);}; and const int getLevel(){return mobLevel;}; So was it like that you ment? Finaly I changed the constructors and I didnt know you could do that, but i didn&#39;t change all of it as i still needed some of the functions(setDamage,setMaxHealth,etc) as those doesnt take a parameter right?</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/26827/sumsar1812"
title="355 reputation"
class="comment-user owner">Sumsar1812</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 14:59:21Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 14:59</span>
</span>
<span title="this comment was edited 1 time">
<svg aria-hidden="true" class="va-text-bottom o50 svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path fill="#F1B600" d="m2 10.12 6.37-6.43 1.88 1.88L3.88 12H2z"/><path fill="#E87C87" d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0"/></svg>
</span>
</div>
</div>
</li>
<li id="comment-43658" class="comment js-comment " data-comment-id="43658" data-comment-owner-id="26827" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">also thank you so much for the feedback! :)</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/26827/sumsar1812"
title="355 reputation"
class="comment-user owner">Sumsar1812</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 15:01:41Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 15:01</span>
</span>
</div>
</div>
</li>
<li id="comment-43665" class="comment js-comment " data-comment-id="43665" data-comment-owner-id="24666" data-comment-score="0">
<div class="js-comment-actions comment-actions">
<div class="comment-score js-comment-score js-comment-edit-hide">
</div>
</div>
<div class="comment-text js-comment-text-and-form">
<div class="comment-body js-comment-edit-hide">
<span class="d-none">\$\begingroup\$</span>
<span class="comment-copy">The const keyword has to go at the end of the prototype to declare a function as const, otherwise you declare that the return type will be a const. As for the inline, it&#39;s like a function with the inline keyword at the beginning of the prototype, but instead of being placed in the .cpp, it&#39;s placed in the .h, outside of the class scope. Finally, I said you could almost even put the set functions inline because I think some of them have only a single operation. If you have getLevel() * 35, you have more than one operation in the line.</span>
<span class="d-none">\$\endgroup\$</span>
<div class="d-inline-flex ai-center">
&ndash;&nbsp;<a href="/users/24666/guillaume-rochat"
title="143 reputation"
class="comment-user">Guillaume Rochat</a>
</div>
<span class="comment-date" dir="ltr">
<span class="v-visible-sr">Commented</span>
<span title='2013-07-01 16:02:18Z, License: CC BY-SA 3.0' class='relativetime-clean'>Jul 1, 2013 at 16:02</span>
</span>
</div>
</div>
</li>
</ul>
</div>
<div id="comments-link-27996" data-rep=50 data-reg=true>
<a class="js-add-link comments-link disabled-link" title="Use comments to ask for more information or suggest improvements. Avoid comments like &#x201C;&#x2B;1&#x201D; or &#x201C;thanks&#x201D;." href="#" role="button">Add a comment</a>
<span class="js-link-separator dno">&nbsp;|&nbsp;</span>
<a class="js-show-link comments-link dno" title="Expand to show all comments on this post" href=# onclick="" role="button"></a>
</div>
</div>
</div>
</div>
<a name='new-answer'></a>
<form id="post-form" action="/questions/27986/answer/submit" method="post" class="js-add-answer-component post-form">
<input type="hidden" id="post-id" value="27986" />
<input type="hidden" id="qualityBanWarningShown" name="qualityBanWarningShown" value="false" />
<input type="hidden" name="referrer" value="" />
<h2 class="space" id="your-answer-header">
Your Answer
</h2>
<script>
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
</script>
<script>
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
useStacksEditor: false,
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploadEnabled: true,
imageUploader: {
brandingHtml: "",
contentPolicyHtml: "User contributions licensed under \u003ca href=\"https://stackoverflow.com/help/licensing\"\u003eCC BY-SA\u003c/a\u003e \u003ca href=\"https://stackoverflow.com/legal/acceptable-use-policy\"\u003e(content policy)\u003c/a\u003e",
allowUrls: true,
},
onDemand: false,
discardSelector: ".discard-answer",
enableTables: true,
isStacksEditorPreviewEnabled: false
,immediatelyShowMarkdownHelp:true,userId:289986,enableTables:true,enableSnippets:true
});
}
});
</script>
<div id="post-editor" class="post-editor js-post-editor d-flex fd-column g4">
<input type="hidden" name="stacksEditorEnabled" value="False" />
<div class="ps-relative">
<div class="wmd-container mb8">
<div id="wmd-button-bar" class="wmd-button-bar btr-sm"></div>
<div class="js-stacks-validation">
<div class="ps-relative">
<textarea id="wmd-input"
name="post-text"
class="wmd-input s-input bar0 js-post-body-field"
data-editor-type="wmd"
data-post-type-id="2"
cols="92" rows="15"
aria-labelledby="your-answer-header"
tabindex="101"
data-min-length=""></textarea>
</div>
<div class="s-input-message mt4 d-none js-stacks-validation-message"></div>
</div>
</div>
</div>
<aside class="d-flex ai-start jc-space-between js-answer-help s-notice s-notice__warning pb0 pr4 pt4 mb8 d-none" role="status" aria-hidden="true">
<div class="flex--item pt8">
<p>Thanks for contributing an answer to Code Review Stack Exchange!</p><ul><li>Please be sure to <em>answer the question</em>. Provide details and share your research!</li></ul><p>But <em>avoid</em></p><ul><li>Asking for help, clarification, or responding to other answers.</li><li>Making statements based on opinion; back them up with references or personal experience.</li></ul><p>Use MathJax to format equations. <a href="https://legacy-www.math.harvard.edu/texman/">MathJax reference</a>.</p><p>To learn more, see our <a href="/help/how-to-answer">tips on writing great answers</a>.</p>
</div>
<button class="flex--item js-answer-help-close-btn s-btn s-btn__muted fc-black-600">
<svg aria-hidden="true" class="svg-icon iconClear" width="18" height="18" viewBox="0 0 18 18"><path d="M15 4.41 13.59 3 9 7.59 4.41 3 3 4.41 7.59 9 3 13.59 4.41 15 9 10.41 13.59 15 15 13.59 10.41 9z"/></svg>
</button>
</aside>
<aside class="d-flex ai-start jc-space-between js-answer-ban s-notice s-notice__danger pb0 pr4 pt4 mb8 d-none" role="status" aria-hidden="true">
<div class="flex--item pt8">
<p>Some of your past answers have not been well-received, and you're in danger of being <a href="/help/answer-bans">blocked from answering</a>.</p><p>Please pay close attention to the following guidance:</p><ul><li>Please be sure to <em>answer the question</em>. Provide details and share your research!</li></ul><p>But <em>avoid</em></p><ul><li>Asking for help, clarification, or responding to other answers.</li><li>Making statements based on opinion; back them up with references or personal experience.</li></ul><p>To learn more, see our <a href="/help/how-to-answer">tips on writing great answers</a>.</p>
</div>
<button class="flex--item js-answer-ban-close-btn s-btn s-btn__muted fc-black-600">
<svg aria-hidden="true" class="svg-icon iconClear" width="18" height="18" viewBox="0 0 18 18"><path d="M15 4.41 13.59 3 9 7.59 4.41 3 3 4.41 7.59 9 3 13.59 4.41 15 9 10.41 13.59 15 15 13.59 10.41 9z"/></svg>
</button>
</aside>
<div>
<div id="draft-saved" class="fc-success h24" style="display:none;">Draft saved</div>
<div id="draft-discarded" class="fc-error h24" style="display:none;">Draft discarded</div>
</div>
<div id="wmd-preview" class="s-prose mb16 wmd-preview js-wmd-preview"></div>
<div></div>
<div class="edit-block">
<input id="fkey" name="fkey" type="hidden" value="1bdb2a6f769206fb1bc17489607dec3bc94f3d71366944559446c3c6061a5f99">
<input id="author" name="author" type="text">
</div>
</div>
<div class="ps-relative">
</div>
<div class="form-submit clear-both d-flex sm:fd-column sm:jc-stretch gs4 ai-center mb24">
<button id="submit-button" class="flex--item fl-shrink0 s-btn s-btn__filled sm:w100" type="submit" tabindex="120" autocomplete="off">
Post Your Answer
</button>
<button class="flex--item s-btn s-btn__danger fl-shrink0 sm:w100 discard-answer d-none">
Discard
</button>
</div>
<div class="js-general-error general-error clear-both d-none" aria-live="polite"></div>
</form>
<div class="js-bottom-notice d-flex w100 md:mb12 md:fd-column ac-stretch" data-loc="1">
<div class="flex--item ba bc-black-200 bar-md p24 md:p16 mr12 md:mb12 md:mr0 w50 md:w100">
<div class="d-flex fd-column">
<p class="flex--item fs-body2 fw-bold fc-black-500 mb8">Start asking to get answers</p>
<p class="flex--item fs-body1 fc-black-400 mb16">Find the answer to your question by asking.</p>
<a class="flex--item s-btn s-btn__outlined as-start px32 md:px16" href="/questions/ask" >Ask question</a>
</div>
</div>
<div class="flex--item ba bc-black-200 bar-md p24 md:p16 w50 md:w100">
<div class="d-flex fd-column gsy g16">
<p class="flex--item fs-body2 fw-bold fc-black-500 mb0">Explore related questions</p>
<div class="flex--item mb0"><ul class='ml0 list-ls-none js-post-tag-list-wrapper d-inline'><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/c%2b%2b" class="s-tag post-tag" title="show questions tagged &#39;c++&#39;" aria-label="show questions tagged &#39;c++&#39;" rel="tag" aria-labelledby="tag-c++-tooltip-container" data-tag-menu-origin="Unknown">c++</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/game" class="s-tag post-tag" title="show questions tagged &#39;game&#39;" aria-label="show questions tagged &#39;game&#39;" rel="tag" aria-labelledby="tag-game-tooltip-container" data-tag-menu-origin="Unknown">game</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/classes" class="s-tag post-tag" title="show questions tagged &#39;classes&#39;" aria-label="show questions tagged &#39;classes&#39;" rel="tag" aria-labelledby="tag-classes-tooltip-container" data-tag-menu-origin="Unknown">classes</a></li><li class='d-inline mr4 js-post-tag-list-item'><a href="/questions/tagged/adventure-game" class="s-tag post-tag" title="show questions tagged &#39;adventure-game&#39;" aria-label="show questions tagged &#39;adventure-game&#39;" rel="tag" aria-labelledby="tag-adventure-game-tooltip-container" data-tag-menu-origin="Unknown">adventure-game</a></li></ul></div>
<p class="flex--item fs-body1 fc-black-400 mb0">See similar questions with these tags.</p>
</div>
</div>
</div>
</div>
</div>
<div id="sidebar" class="show-votes" role="complementary" aria-label="sidebar">
<div class="s-sidebarwidget s-sidebarwidget__yellow mb16 js-sidebar-new-user-box">
<div class="s-sidebarwidget--header">
Welcome!
</div>
<div class="s-sidebarwidget--content d-block s-prose s-prose__sm">
This is a collaboratively edited question and answer site for <b>programmers interested in sharing code for peer review</b>. It's 100% free, no registration required.
</div>
<div class="s-sidebarwidget--content jc-space-between">
<a href="/tour?mnu=1">About</a>
<a href="/help?mnu=1">Help</a>
<a href="https://codereview.meta.stackexchange.com">Meta</a>
</div>
</div>
<div class="s-sidebarwidget s-sidebarwidget__yellow s-anchors s-anchors__grayscale mb16" data-tracker="cb=1">
<ul class="s-sidebarwidget--content s-sidebarwidget__items p0">
<li class="s-sidebarwidget--header">
The Overflow Blog
</li>
<li class="s-sidebarwidget--item d-flex px16">
<div class="flex--item1 fl-shrink0">
<svg aria-hidden="true" class="va-text-top svg-icon iconPencilSm" width="14" height="14" viewBox="0 0 14 14"><path fill="#F1B600" d="m2 10.12 6.37-6.43 1.88 1.88L3.88 12H2z"/><path fill="#E87C87" d="m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0"/></svg> </div>
<div class="flex--item wmn0 ow-break-word">
<a href="https://stackoverflow.blog/2025/03/28/are-ai-agents-ready-for-the-enterprise/" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;The Overflow Blog&quot;,&quot;https://stackoverflow.blog/2025/03/28/are-ai-agents-ready-for-the-enterprise/&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 1, position: 0, location: questionpage })">“Are AI agents ready for the enterprise?”</a>
</div>
</li>
<li class="s-sidebarwidget--header">
Featured on Meta
</li>
<li class="s-sidebarwidget--item d-flex px16">
<div class="flex--item1 fl-shrink0">
<div class="favicon favicon-stackexchangemeta" title="Meta Stack Exchange"></div> </div>
<div class="flex--item wmn0 ow-break-word">
<a href="https://meta.stackexchange.com/questions/407321/community-asks-sprint-announcement-march-2025" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackexchange.com/questions/407321/community-asks-sprint-announcement-march-2025&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 3, position: 1, location: questionpage })">Community Asks Sprint Announcement - March 2025</a>
</div>
</li>
<li class="s-sidebarwidget--item d-flex px16">
<div class="flex--item1 fl-shrink0">
<div class="favicon favicon-stackexchangemeta" title="Meta Stack Exchange"></div> </div>
<div class="flex--item wmn0 ow-break-word">
<a href="https://meta.stackexchange.com/questions/407547/experimenting-with-a-new-experiment-opt-out-option" class="js-gps-track" data-ga="[&quot;community bulletin board&quot;,&quot;Featured on Meta&quot;,&quot;https://meta.stackexchange.com/questions/407547/experimenting-with-a-new-experiment-opt-out-option&quot;,null,null]" data-gps-track="communitybulletin.click({ priority: 3, position: 2, location: questionpage })">Experimenting with a new experiment opt-out option</a>
</div>
</li>
</ul>
</div>
<div class="js-zone-container zone-container-sidebar">
<div id="dfp-tsb" class="everyonelovesstackoverflow everyoneloves__top-sidebar"></div>
<div class="js-report-ad-button-container " style="width: 300px"></div>
</div>
<div class="js-zone-container zone-container-sidebar">
<div id="dfp-msb" class="everyonelovesstackoverflow everyoneloves__mid-sidebar"></div>
<div class="js-report-ad-button-container " style="width: 300px"></div>
</div>
<div id="hireme"></div> <div class="module sidebar-linked">
<h4 id="h-linked">Linked</h4>
<div class="linked" data-tracker="lq=1">
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 27986, target_question_id: 57013, position: 0 })">
<a href="/q/57013" title="Question score (upvotes - downvotes)">
<div class="answer-votes answered-accepted default">15</div>
</a>
<a href="/questions/57013/encapsulated-text-based-rpg-using-a-randomized-combat-system?noredirect=1" class="question-hyperlink">Encapsulated text-based RPG using a randomized combat system</a>
</div>
<div class="spacer js-gps-track" data-gps-track="linkedquestion.click({ source_post_id: 27986, target_question_id: 38544, position: 1 })">
<a href="/q/38544" title="Question score (upvotes - downvotes)">
<div class="answer-votes default">7</div>
</a>
<a href="/questions/38544/battle-system-in-c?noredirect=1" class="question-hyperlink">Battle system in C++</a>
</div>
</div>
</div>
<div class="module sidebar-related">
<h4 id="h-related">Related</h4>
<div class="related js-gps-related-questions" data-tracker="rq=1">
<div class="spacer" data-question-id="62100">
<a href="/q/62100" title="Question score (upvotes - downvotes)" >
<div class="answer-votes default">9</div>
</a>
<a href="/questions/62100/rpg-game-shop-system" class="question-hyperlink">RPG game shop system</a>
</div>
<div class="spacer" data-question-id="70249">
<a href="/q/70249" title="Question score (upvotes - downvotes)" >
<div class="answer-votes answered-accepted default">13</div>
</a>
<a href="/questions/70249/text-based-rpg-game" class="question-hyperlink">Text-based RPG game</a>
</div>
<div class="spacer" data-question-id="103740">
<a href="/q/103740" title="Question score (upvotes - downvotes)" >
<div class="answer-votes default">3</div>
</a>
<a href="/questions/103740/text-based-rpg-game-in-c" class="question-hyperlink">Text-based RPG game in C++</a>
</div>
<div class="spacer" data-question-id="106951">
<a href="/q/106951" title="Question score (upvotes - downvotes)" >
<div class="answer-votes answered-accepted default">6</div>
</a>
<a href="/questions/106951/the-mysts-of-altair-text-based-adventure-game" class="question-hyperlink">The Mysts of Altair - text-based adventure game</a>
</div>
<div class="spacer" data-question-id="107108">
<a href="/q/107108" title="Question score (upvotes - downvotes)" >
<div class="answer-votes default">1</div>
</a>
<a href="/questions/107108/text-based-adventure-survival-horror-game" class="question-hyperlink">Text-based adventure survival horror game</a>
</div>
<div class="spacer" data-question-id="148599">
<a href="/q/148599" title="Question score (upvotes - downvotes)" >
<div class="answer-votes answered-accepted default">8</div>
</a>
<a href="/questions/148599/text-based-adventure-game-using-classes-and-xml" class="question-hyperlink">Text-based adventure game using classes and XML</a>
</div>
<div class="spacer" data-question-id="160327">
<a href="/q/160327" title="Question score (upvotes - downvotes)" >
<div class="answer-votes default">1</div>
</a>
<a href="/questions/160327/beginning-of-text-based-rpg" class="question-hyperlink">Beginning of text-based RPG</a>
</div>
<div class="spacer" data-question-id="166332">
<a href="/q/166332" title="Question score (upvotes - downvotes)" >
<div class="answer-votes answered-accepted default">4</div>
</a>
<a href="/questions/166332/text-based-survival-game" class="question-hyperlink">Text based survival game</a>
</div>
<div class="spacer" data-question-id="198399">
<a href="/q/198399" title="Question score (upvotes - downvotes)" >
<div class="answer-votes default">7</div>
</a>
<a href="/questions/198399/rpg-text-game-wip" class="question-hyperlink">RPG text game WIP</a>
</div>
<div class="spacer" data-question-id="215542">
<a href="/q/215542" title="Question score (upvotes - downvotes)" >
<div class="answer-votes default">13</div>
</a>
<a href="/questions/215542/adventure-game-text-based-in-c" class="question-hyperlink">Adventure Game (text based) in C++</a>
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
$(".js-gps-related-questions .spacer").on("click", function () {
fireRelatedEvent($(this).index() + 1, $(this).data('question-id'));
});
function fireRelatedEvent(position, questionId) {
StackExchange.using("gps", function() {
StackExchange.gps.track('related_questions.click',
{
position: position,
originQuestionId: 27986,
relatedQuestionId: +questionId,
location: 'sidebar',
source: 'Baseline'
});
});
}
});
</script>
<div id="hot-network-questions" class="module tex2jax_ignore">
<h4>
<a href="https://stackexchange.com/questions?tab=hot"
class="js-gps-track s-link s-link__inherit"
data-gps-track="posts_hot_network.click({ item_type:1, location:11 })">
Hot Network Questions
</a>
</h4>
<ul>
<li >
<div class="favicon favicon-hsm" title="History of Science and Mathematics Stack Exchange"></div><a href="https://hsm.stackexchange.com/questions/18433/riemanns-letter-to-gauss" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:587 }); posts_hot_network.click({ item_type:2, location:11 })">
Riemann&#x27;s letter to Gauss
</a>
</li>
<li >
<div class="favicon favicon-askubuntu" title="Ask Ubuntu"></div><a href="https://askubuntu.com/questions/1544759/app-center-gone-snap-store-doesnt-work-24-04-2" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:89 }); posts_hot_network.click({ item_type:2, location:11 })">
App Center gone, Snap Store doesn&#x27;t work (24.04.2)
</a>
</li>
<li >
<div class="favicon favicon-aviation" title="Aviation Stack Exchange"></div><a href="https://aviation.stackexchange.com/questions/108295/what-model-is-this-kollsman-altimeter" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:528 }); posts_hot_network.click({ item_type:2, location:11 })">
What model is this Kollsman altimeter?
</a>
</li>
<li >
<div class="favicon favicon-judaism" title="Mi Yodeya"></div><a href="https://judaism.stackexchange.com/questions/148524/arugas-habosem-and-the-man-with-the-challah" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:248 }); posts_hot_network.click({ item_type:2, location:11 })">
Arugas HaBosem and the man with the challah
</a>
</li>
<li >
<div class="favicon favicon-academia" title="Academia Stack Exchange"></div><a href="https://academia.stackexchange.com/questions/217620/how-can-i-improve-indexing-for-my-small-university-journal" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:415 }); posts_hot_network.click({ item_type:2, location:11 })">
How can I improve indexing for my small university journal?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-physics" title="Physics Stack Exchange"></div><a href="https://physics.stackexchange.com/questions/846306/finding-electric-field-from-finite-object-using-gauss-law" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:151 }); posts_hot_network.click({ item_type:2, location:11 })">
Finding electric field from finite object using Gauss law
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-mathoverflow" title="MathOverflow"></div><a href="https://mathoverflow.net/questions/490171/can-a-smooth-function-hide-a-point-from-the-origin" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:504 }); posts_hot_network.click({ item_type:2, location:11 })">
Can a smooth function hide a point from the origin?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-superuser" title="Super User"></div><a href="https://superuser.com/questions/1888670/how-can-i-color-the-columns-of-a-csv-file-differently-in-notepad" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:3 }); posts_hot_network.click({ item_type:2, location:11 })">
How can I color the columns of a CSV file differently in Notepad&#x2B;&#x2B;?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-scifi" title="Science Fiction &amp; Fantasy Stack Exchange"></div><a href="https://scifi.stackexchange.com/questions/295737/movie-in-which-criminals-are-sent-back-in-time-to-preserve-an-authoritarian-gove" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:186 }); posts_hot_network.click({ item_type:2, location:11 })">
Movie in which criminals are sent back in time to preserve an authoritarian government
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-electronics" title="Electrical Engineering Stack Exchange"></div><a href="https://electronics.stackexchange.com/questions/742606/identifying-etkb14c9a-a3-logo-chip-used-in-usb-audio-modules" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:135 }); posts_hot_network.click({ item_type:2, location:11 })">
Identifying ETKB14C9A (A3 Logo) Chip Used in USB Audio Modules
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-history" title="History Stack Exchange"></div><a href="https://history.stackexchange.com/questions/77604/why-was-henry-viiis-marriage-to-anne-of-cleves-diplomatically-valuable" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:324 }); posts_hot_network.click({ item_type:2, location:11 })">
Why was Henry VIII&#x27;s marriage to Anne of Cleves diplomatically valuable?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-datascience" title="Data Science Stack Exchange"></div><a href="https://datascience.stackexchange.com/questions/131652/how-do-model-assumptions-impact-the-interpretation-of-results-in-machine-learnin" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:557 }); posts_hot_network.click({ item_type:2, location:11 })">
How do model assumptions impact the interpretation of results in machine learning?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-academia" title="Academia Stack Exchange"></div><a href="https://academia.stackexchange.com/questions/217595/help-identifying-the-full-name-of-the-journal-bull-soc-roumaine-phys" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:415 }); posts_hot_network.click({ item_type:2, location:11 })">
Help identifying the full name of the journal &quot;Bull. soc. roumaine phys.&quot;
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-aviation" title="Aviation Stack Exchange"></div><a href="https://aviation.stackexchange.com/questions/108285/can-an-airliner-fly-with-only-1-out-of-4-engines-operating" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:528 }); posts_hot_network.click({ item_type:2, location:11 })">
Can an airliner fly with only 1 out of 4 engines operating?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-mathematica" title="Mathematica Stack Exchange"></div><a href="https://mathematica.stackexchange.com/questions/311870/create-a-fantasy-map" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:387 }); posts_hot_network.click({ item_type:2, location:11 })">
Create a fantasy map
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-retrocomputing" title="Retrocomputing Stack Exchange"></div><a href="https://retrocomputing.stackexchange.com/questions/31478/was-there-ever-a-c-compiler-written-in-pascal" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:648 }); posts_hot_network.click({ item_type:2, location:11 })">
Was there ever a C compiler written in Pascal?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-mathoverflow" title="MathOverflow"></div><a href="https://mathoverflow.net/questions/490247/non-trivial-deformations-of-a-blowup-of-a-calabi-yau-threefold" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:504 }); posts_hot_network.click({ item_type:2, location:11 })">
Non-trivial deformations of a blowup of a Calabi-Yau threefold
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-hermeneutics" title="Biblical Hermeneutics Stack Exchange"></div><a href="https://hermeneutics.stackexchange.com/questions/102723/what-is-the-best-translation-of-galatians-27" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:320 }); posts_hot_network.click({ item_type:2, location:11 })">
What is the best translation of Galatians 2:7?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-crypto" title="Cryptography Stack Exchange"></div><a href="https://crypto.stackexchange.com/questions/114682/why-cpa-secure-implies-with-overwhelming-probability-there-will-be-no-repeated" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:281 }); posts_hot_network.click({ item_type:2, location:11 })">
Why CPA-secure implies with overwhelming probability, there will be no repeated ciphertext?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-mathematica" title="Mathematica Stack Exchange"></div><a href="https://mathematica.stackexchange.com/questions/311879/removing-large-spikes-in-a-dataset" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:387 }); posts_hot_network.click({ item_type:2, location:11 })">
Removing large spikes in a dataset
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-math" title="Mathematics Stack Exchange"></div><a href="https://math.stackexchange.com/questions/5051094/solving-the-functional-equation-using-some-more-rigorous-method" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:69 }); posts_hot_network.click({ item_type:2, location:11 })">
Solving the functional equation using some more rigorous method
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-superuser" title="Super User"></div><a href="https://superuser.com/questions/1889099/we-have-starlink-and-our-location-shows-chicago-but-we-live-in-missouri-starlin" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:3 }); posts_hot_network.click({ item_type:2, location:11 })">
We have Starlink and our location shows Chicago but we live in Missouri. Starlink says they cannot update it. What Wi-Fi extender would show location?
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-mathematica" title="Mathematica Stack Exchange"></div><a href="https://mathematica.stackexchange.com/questions/311848/plot-xy-data-from-a-list-of-xyz-values-with-z-value-determining-the-colour" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:387 }); posts_hot_network.click({ item_type:2, location:11 })">
Plot XY data from a list of XYZ values with Z value determining the colour
</a>
</li>
<li class="dno js-hidden">
<div class="favicon favicon-philosophy" title="Philosophy Stack Exchange"></div><a href="https://philosophy.stackexchange.com/questions/123787/if-the-death-penalty-is-wrong-because-what-if-the-convicted-was-innocent-then" class="js-gps-track question-hyperlink mb0" data-gps-track="site.switch({ item_type:11, target_site:265 }); posts_hot_network.click({ item_type:2, location:11 })">
If the death penalty is wrong because &quot;what if the convicted was innocent&quot;, then isn&#x27;t any punishment wrong?
</a>
</li>
</ul>
<a href="#"
class="show-more js-show-more js-gps-track"
data-gps-track="posts_hot_network.click({ item_type:3, location:11 })">
more hot questions
</a>
</div>
<div id="feed-link" class="js-feed-link">
<a href="/feeds/question/27986" title="Feed of this question and its answers">
<svg aria-hidden="true" class="fc-orange-400 svg-icon iconRss" width="18" height="18" viewBox="0 0 18 18"><path d="M3 1a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm0 1.5c6.9 0 12.5 5.6 12.5 12.5H13C13 9.55 8.45 5 3 5zm0 5c4.09 0 7.5 3.41 7.5 7.5H8c0-2.72-2.28-5-5-5zm0 5c1.36 0 2.5 1.14 2.5 2.5H3z"/></svg>
Question feed
</a>
</div>
<aside class="s-modal js-feed-link-modal" tabindex="-1" role="dialog" aria-labelledby="feed-modal-title" aria-describedby="feed-modal-description" aria-hidden="true">
<div class="s-modal--dialog js-modal-dialog wmx4" role="document" data-controller="se-draggable">
<h1 class="s-modal--header fw-bold js-first-tabbable" id="feed-modal-title" data-se-draggable-target="handle" tabindex="0">
Subscribe to RSS
</h1>
<div class="d-flex gs4 gsy fd-column">
<div class="flex--item">
<label class="d-block s-label c-default" for="feed-url">
Question feed
<p class="s-description mt2" id="feed-modal-description">To subscribe to this RSS feed, copy and paste this URL into your RSS reader.</p>
</label>
</div>
<div class="d-flex ps-relative">
<input class="s-input" type="text" name="feed-url" id="feed-url" readonly="readonly" value="https://codereview.stackexchange.com/feeds/question/27986" />
<svg aria-hidden="true" class="s-input-icon fc-orange-400 svg-icon iconRss" width="18" height="18" viewBox="0 0 18 18"><path d="M3 1a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm0 1.5c6.9 0 12.5 5.6 12.5 12.5H13C13 9.55 8.45 5 3 5zm0 5c4.09 0 7.5 3.41 7.5 7.5H8c0-2.72-2.28-5-5-5zm0 5c1.36 0 2.5 1.14 2.5 2.5H3z"/></svg>
</div>
</div>
<a class="s-modal--close s-btn s-btn__muted js-modal-close js-last-tabbable" href="#" aria-label="Close">
<svg aria-hidden="true" class="svg-icon iconClearSm" width="14" height="14" viewBox="0 0 14 14"><path d="M12 3.41 10.59 2 7 5.59 3.41 2 2 3.41 5.59 7 2 10.59 3.41 12 7 8.41 10.59 12 12 10.59 8.41 7z"/></svg>
</a>
</div>
</aside>
</div>
</div>
<script>StackExchange.ready(function(){$.get('/posts/27986/ivc/97f1?prg=8b89fffe-e4e2-46a9-b938-cf7f2b66ca95');});</script>
<noscript><div><img src="/posts/27986/ivc/97f1?prg=8b89fffe-e4e2-46a9-b938-cf7f2b66ca95" class="dno" alt="" width="0" height="0"></div></noscript><div style="display:none" id="js-codeblock-lang">lang-cpp</div></div>
<script>
$('#wmd-input').one("keypress", function () {
$.ajax({
url: '/accounts/email-settings-form',
cache: false,
success: function (data) {
$('#submit-button').parent().prepend(data);
}
});
});
</script>
<script defer src="https://cdn.sstatic.net/Js/questions/show.en.js?v=2ee07399922e"></script>
<script type="application/json" data-role="module-args" data-module-name="entry-points/questions/show.mod">{"doMarkObsolete":false,"doTimeOnPage":false,"sendAnswerEditorEventsToAEH":false,"sendAnswerEditorEventsToPrizm":false,"questionId":27986,"sendAuthQuestionVisitToAEH":true,"sendAuthQuestionVisitToPrizm":true}</script>
</div>
</div>
<script type="text/javascript">
var cam = cam || { opt: {} };
var clcGamLoaderOptions = cam || { opt: {} };
var opt = clcGamLoaderOptions.opt;
opt.omni = 'BwoLCMadgvPM4Pc9EAUQ_a_LExjS2gEgEygCMAM6IXxjKyt8Z2FtZXxjbGFzc2VzfGFkdmVudHVyZS1nYW1lfEAASABaEgmerwvz_n1cRRGwyfbXd3Dg7zHT6Dut3eYxcEY';
opt.refresh = !1;
opt.refreshInterval = 0;
opt.sf = !1;
opt.hb = !1;
opt.ll = !0;
opt.tlb_position = 0;
opt.personalization_consent = !1;
opt.targeting_consent = !1;
opt.performance_consent = !1;
opt.targeting = {Registered:['true'],Reputation:['1'],'ron-tag':['c_plus_plus','game','classes','adventure-game'],NumberOfAnswers:['4'],cf_bot_score:'91 - 99'};
opt.adReportEnabled = !0;
opt.adReportUrl = '/ads/report-ad';
opt.adReportText = 'Report this ad';
opt.adReportFileTypeErrorMessage = 'Please select a PNG or JPG file.';
opt.adReportFileSizeErrorMessage = 'The file must be under 2 MiB.';
opt.adReportErrorText = 'Error uploading ad report.';
opt.adReportThanksText = 'Thanks for your feedback. We’ll review this against our code of conduct and take action if necessary.';
opt.adReportLoginExpiredMessage = 'Your login session has expired, please login and try again.';
opt.adReportLoginErrorMessage = 'An error occurred when loading the report form - please try again';
opt.adReportModalClass = 'js-ad-report';
opt.countryCode = 'BG';
opt.qualtricsSurveyData = '{"isRegistered":"True","repBucket":"1","referrer":"https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f27986%2ftext-based-rpg-game-using-classes%3fnewreg%3d2d9d7a9364204d349aa63aff7ca745a7","accountAge":"0"}';
opt.perRequestGuid = '8b89fffe-e4e2-46a9-b938-cf7f2b66ca95';
opt.responseHash = 'gNHbU2mqFbbBBFlLDGmMHGYgomLC97kCzL7CgPFj0/A=';
opt.targeting.TargetingConsent = ['False_Active'];
opt.allowAccountTargetingForThisRequest = !1;
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('dfptestads')) {
const dfptestads = urlParams.get('dfptestads');
opt.targeting.DfpTestAds = dfptestads;
}
</script>
<script>;(()=>{"use strict";var __webpack_modules__={23:(e,t,s)=>{s.d(t,{Z7:()=>c,eq:()=>l,kG:()=>d});const n="248424177",o=(a=location.pathname,/^\/tags\//.test(a)||/^\/questions\/tagged\//.test(a)?"tag-pages":/^\/discussions\//.test(a)||/^\/beta\/discussions/.test(a)?"discussions":/^\/$/.test(a)||/^\/home/.test(a)?"home-page":/^\/jobs$/.test(a)||/^\/jobs\//.test(a)?"jobs":"question-pages");var a;let i=location.hostname;const r={slots:{lb:[[728,90]],mlb:[[728,90]],smlb:[[728,90]],bmlb:[[728,90]],sb:e=>"dfp-tsb"===e?[[300,250],[300,600]]:[[300,250]],"tag-sponsorship":[[730,135]],"mobile-below-question":[[320,50],[300,250]],msb:[[300,250],[300,600]],"talent-conversion-tracking":[[1,1]],"site-sponsorship":[[230,60]]},ids:{"dfp-tlb":"lb","dfp-mlb":"mlb","dfp-smlb":"smlb","dfp-bmlb":"bmlb","dfp-tsb":"sb","dfp-isb":"sb","dfp-tag":"tag-sponsorship","dfp-msb":"msb","dfp-sspon":"site-sponsorship","dfp-m-aq":"mobile-below-question"},idsToExcludeFromAdReports:["dfp-sspon"]};function d(){return Object.keys(r.ids)}function l(e){return r.idsToExcludeFromAdReports.indexOf(e)<0}function c(e,t){var s=e.split("_")[0];const a=r.ids[s];let d=r.slots[a];return"function"==typeof d&&(d=d(s)),{path:`/${n}/${t||i}/${a}/${o}`,sizes:d,zone:a}}},865:(e,t,s)=>{function n(e){return"string"==typeof e?document.getElementById(e):e}function o(e){return!!(e=n(e))&&"none"===getComputedStyle(e).display}function a(e){return!o(e)}function i(e){return!!e}function r(e){return/^\s*$/.test(n(e).innerHTML)}function d(e){const{style:t}=e;t.height=t.maxHeight=t.minHeight="auto",t.display="none"}function l(e){const{style:t}=e;t.height=t.maxHeight=t.minHeight="auto",t.display="none",[].forEach.call(e.children,l)}function c(e){const{style:t}=e;t.height=t.maxHeight=t.minHeight="auto",t.removeProperty("display")}function g(e){const t=document.createElement("script");t.src=e,document.body.appendChild(t)}function p(e){return s=e,(t=[]).push=function(e){return s(),delete this.push,this.push(e)},t;var t,s}function h(e){let t="function"==typeof HTMLTemplateElement;var s=document.createElement(t?"template":"div");return e=e.trim(),s.innerHTML=e,t?s.content.firstChild:s.firstChild}s.d(t,{$Z:()=>c,Bv:()=>h,Gx:()=>g,Nj:()=>n,QZ:()=>p,cf:()=>d,pn:()=>a,wo:()=>l,xb:()=>r,xj:()=>o,yb:()=>i})},763:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{__webpack_require__.d(__webpack_exports__,{t:()=>AdReports});var _common_helper__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(865),_console__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(276),_ad_units__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(23);class AdReports{constructor(e,t){if(this.googletag=e,this.cam=t,this.allowedFileTypes=["image/png","image/jpg","image/jpeg"],this.ignoreValidation=!1,_console__WEBPACK_IMPORTED_MODULE_1__.cM("Ad reporting init"),this.cam=t,this.callOnButtonClick=e=>this.onButtonClick(e),this.googletag.pubads().addEventListener("slotRenderEnded",e=>this.handleSlotRendered(e)),Array.isArray(t.slotsRenderedEvents)){_console__WEBPACK_IMPORTED_MODULE_1__.cM("Adding report button to "+t.slotsRenderedEvents.length+" events that have transpired");for(var s=0;s<t.slotsRenderedEvents.length;s++)this.handleSlotRendered(t.slotsRenderedEvents[s])}}handleSlotRendered(e){if(e&&e.slot&&!e.isEmpty&&(e.creativeId||e.lineItemId||!e.isEmpty)){var t=e.slot.getSlotElementId();if(t){var s=document.getElementById(t);if(s)if((0,_ad_units__WEBPACK_IMPORTED_MODULE_0__.eq)(t)){var n=s?.closest(".js-zone-container")?.querySelector(".js-report-ad-button-container");n?(n.innerHTML="",n.append(this.createButton(e)),n.style.height="24px",_console__WEBPACK_IMPORTED_MODULE_1__.cM("Added report button to the bottom of "+t)):_console__WEBPACK_IMPORTED_MODULE_1__.cM("Ad report button not found, may be intentional, element: "+t)}else _console__WEBPACK_IMPORTED_MODULE_1__.cM("Not adding report button to the bottom of "+t+": shouldHaveReportButton = false");else _console__WEBPACK_IMPORTED_MODULE_1__.cM("Not adding report button to the bottom of "+t+": resolved invalid adUnit element")}else _console__WEBPACK_IMPORTED_MODULE_1__.cM("Not adding report button to the bottom of element: invalid adUnitElementId")}else _console__WEBPACK_IMPORTED_MODULE_1__.cM("Not adding report button to the bottom of element: invalid SlotRenderEndedEvent")}async onButtonClick(e){e.preventDefault();let t=e.target;const s=t.dataset.modalUrl,n=t.dataset.googleEventData;return await this.loadModal(s,t,n),!1}createButton(e){let t=document.createElement("button");var s=JSON.stringify(e);return t.dataset.googleEventData=s,t.dataset.modalUrl=this.cam.opt.adReportUrl,t.dataset.adUnit=e.slot.getSlotElementId(),t.classList.add("js-report-ad","s-btn","s-btn__link","fs-fine","mt2","float-right"),t.append(document.createTextNode(this.cam.opt.adReportText)),t.removeEventListener("click",this.callOnButtonClick),t.addEventListener("click",this.callOnButtonClick),t}async loadModal(url,$link,googleEventData){try{await window.StackExchange.helpers.loadModal(url,{returnElements:window.$($link)}),this.initForm(googleEventData)}catch(e){var message="",response=e.responseText?eval(`(${e.responseText})`):null;message=response&&response.isLoggedOut?this.cam.opt.adReportLoginExpiredMessage:this.cam.opt.adReportLoginErrorMessage,window.StackExchange.helpers.showToast(message,{type:"danger"})}}removeModal(){window.StackExchange.helpers.closePopups(document.querySelectorAll("."+this.cam.opt.adReportModalClass),"dismiss")}initForm(e,t=!1){this.ignoreValidation=t,this.$form=document.querySelector(".js-ad-report-form"),this.$googleEventData=this.$form.querySelector(".js-json-data"),this.$adReportReasons=this.$form.querySelectorAll(".js-ad-report-reason"),this.$adReportReasonOther=this.$form.querySelector(".js-ad-report-reason-other"),this.$fileUploaderInput=this.$form.querySelector(".js-file-uploader-input"),this.$imageUploader=this.$form.querySelector(".js-image-uploader"),this.$clearImageUpload=this.$form.querySelector(".js-clear-image-upload"),this.$imageUploaderText=this.$form.querySelector(".js-image-uploader-text"),this.$imageUploaderPreview=this.$form.querySelector(".js-image-uploader-preview"),this.$fileErrorMessage=this.$form.querySelector(".js-file-error");const s=this.$form.querySelector(".js-drag-drop-enabled"),n=this.$form.querySelector(".js-drag-drop-disabled");this.$googleEventData.value=e,this.$adReportReasons.forEach((e,t)=>e.addEventListener("change",e=>{this.$adReportReasonOther.classList.toggle("d-none","3"!==e.target.value)})),this.$fileUploaderInput.addEventListener("change",()=>{this.validateFileInput()&&this.updateImagePreview(this.$fileUploaderInput.files)}),this.$clearImageUpload.addEventListener("click",e=>{e.preventDefault(),this.clearImageUpload()});try{this.$fileUploaderInput[0].value="",this.$imageUploader.addEventListener("dragenter dragover dragleave drop",this.preventDefaults),this.$imageUploader.addEventListener("dragenter dragover",this.handleDragStart),this.$imageUploader.addEventListener("dragleave drop",this.handleDragEnd),this.$imageUploader.addEventListener("drop",this.handleDrop)}catch(e){s.classList.add("d-none"),n.classList.remove("d-none")}this.$form.removeEventListener("",this.handleDragEnd),this.$form.addEventListener("submit",async e=>(e.preventDefault(),this.submitForm(),!1))}clearImageUpload(){this.$fileUploaderInput.value="",this.$imageUploaderPreview.setAttribute("src",""),this.$imageUploaderPreview.classList.add("d-none"),this.$clearImageUpload.classList.add("d-none"),this.$imageUploaderText.classList.remove("d-none"),this.$imageUploader.classList.add("p16","ba","bas-dashed","bc-black-100")}preventDefaults(e){e.preventDefault(),e.stopPropagation()}handleDragStart(e){this.$imageUploader.classList.remove("bas-dashed"),this.$imageUploader.classList.add("bas-solid","bc-black-100")}handleDragEnd(e){this.$imageUploader.classList.remove("bas-solid","bc-black-100"),this.$imageUploader.classList.add("bas-dashed")}handleDrop(e){var t=e.originalEvent.dataTransfer.files;FileReader&&t&&1===t.length&&(this.$fileUploaderInput.files=t,this.validateFileInput()&&this.updateImagePreview(t))}setError(e){this.$fileErrorMessage.parentElement.classList.toggle("has-error",e)}updateImagePreview(e){this.$imageUploader.classList.remove("p16","ba","bas-dashed","bc-black-100"),this.$clearImageUpload.classList.remove("d-none"),this.$imageUploaderText.classList.add("d-none");var t=new FileReader;t.onload=e=>{null!=e.target&&(this.$imageUploaderPreview.setAttribute("src",e.target.result),this.$imageUploaderPreview.classList.remove("d-none"))},t.readAsDataURL(e[0])}validateFileInput(){if(this.ignoreValidation)return!0;const e=this.cam.opt.adReportFileTypeErrorMessage,t=this.cam.opt.adReportFileSizeErrorMessage;if(null==this.$fileUploaderInput.files)return!1;var s=this.$fileUploaderInput.files[0];return null==s?(this.setError(!0),!1):this.allowedFileTypes.indexOf(s.type)<0?(this.$fileErrorMessage.textContent=e,this.$fileErrorMessage.classList.remove("d-none"),this.setError(!0),!1):s.size>2097152?(this.$fileErrorMessage.textContent=t,this.$fileErrorMessage.classList.remove("d-none"),this.setError(!0),!1):(this.$fileErrorMessage.classList.add("d-none"),this.setError(!1),!0)}async gatherDiagnosticInfo(){return{BrowserVersion:await this.getBrowserVersion()}}getElementSource(e){return e.outerHTML}getNestedIFrameElement(e){var t=e.querySelector("iframe");return t.contentDocument?t.contentDocument.documentElement:t.contentWindow.document.documentElement}async getBrowserVersion(){return await navigator.userAgentData.getHighEntropyValues(["fullVersionList"]).then(e=>JSON.stringify(e.fullVersionList))}async submitForm(){if(!this.validateFileInput())return!1;this.$form.querySelector("[type=submit]").setAttribute("disabled","true");var e=JSON.parse(this.$googleEventData.value||"{}");e.Reason=parseInt(this.$form.querySelector(".js-ad-report-reason:checked").value,10),e.Description=this.$adReportReasonOther.value,this.$googleEventData.value=JSON.stringify(e);var t=new FormData(this.$form);if("1"===t.get("shareDiagnosticInfo")){var s=await this.gatherDiagnosticInfo();Object.keys(s).forEach(e=>t.append(e,s[e]))}try{const e=await window.fetch(this.$form.getAttribute("action"),{method:this.$form.getAttribute("method"),body:t,cache:"no-cache"}),s=e.headers.get("content-type")||"",o=await e.text();if(!e.ok)throw new Error("response not valid");if(0===s.indexOf("text/html")){var n=(0,_common_helper__WEBPACK_IMPORTED_MODULE_2__.Bv)(o);const e=n?n.querySelector(".js-modal-content"):null;if(_console__WEBPACK_IMPORTED_MODULE_1__.cM("$popupContent"),_console__WEBPACK_IMPORTED_MODULE_1__.cM(e),!e)throw new Error(`Could not find .js-modal-content in response from ${this.$form.getAttribute("action")}`);document.querySelector(".js-modal-content").replaceWith(e)}else window.StackExchange.helpers.showToast(this.cam.opt.adReportThanksText,{type:"success"}),this.removeModal()}catch(e){window.StackExchange.helpers.showToast(this.cam.opt.adReportErrorText,{type:"danger"})}finally{let e=this.$form.querySelector("[type=submit]");e&&e.removeAttribute("disabled")}}}},276:(e,t,s)=>{function n(...e){}function o(...e){}s.d(t,{cM:()=>n,vU:()=>o})}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var s=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](s,s.exports,__webpack_require__),s.exports}__webpack_require__.d=(e,t)=>{for(var s in t)__webpack_require__.o(t,s)&&!__webpack_require__.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var __webpack_exports__={};(()=>{var e=__webpack_require__(276),t=(e=>(e[e.Above=0]="Above",e[e.Below=1]="Below",e))(t||{});const s=Object.assign({},{"lib":"https://clc.stackoverflow.com/Content/bundles/js/gam_loader_script.bundle.741.5deb8dc1a671bfb1646b.js?v=7178a92a336c","style":null,"u":null,"wa":true,"kt":2000,"tto":true,"h":"clc.stackoverflow.com","allowed":"^(((talent\\.)?stackoverflow)|(blog\\.codinghorror)|(serverfault|askubuntu)|([^\\.]+\\.stackexchange))\\.com$","wv":true,"al":false,"abd":true,"cpa_liid":[5882654614],"cpa_cid":[138377597667],"dp":false,"tgt_to":1000,"tgt_u":"https://clc.stackoverflow.com/get-user-acct-tgt","tgt_e":true,"tgt_p":100,"dv_enabled":false,"upo":""});var n=__webpack_require__(23),o=__webpack_require__(865),a=__webpack_require__(763);class i{constructor(t,s){this.googletag=t,this.interval=s,e.cM("Ad refresh init. interval: "+s),this.googletag.pubads().addEventListener("impressionViewable",e=>this.onImpressionViewable(e)),e.cM("done enabling ad refresh")}onImpressionViewable(t){var s=t.slot;e.cM("ad refresh - slot "+s.getSlotElementId()+" is viewable, initializing refresh"),this.scheduleRefresh(s)}scheduleRefresh(e){setTimeout(()=>this.refreshAdSlot(e),1e3*this.interval)}static refreshMyAd(t,s){let n=t.pubads().getSlots().find(e=>e.getSlotElementId()===s);n&&(e.cM("refreshMyAd - refreshing ad slot "+s),t.pubads().refresh([n]))}static removeMyAd(t,s){let n=t.pubads().getSlots().find(e=>e.getSlotElementId()===s);n&&(e.cM("removeMyAd - destroying ad slot "+s),t.destroySlots([n]))}refreshAdSlot(t){var s=t.getSlotElementId();this.isElementVisibleInBrowser(s)?(e.cM("refreshing ad slot "+s),googletag.pubads().refresh([t])):(e.cM("refresh skipped this time; ad slot not viewable:"+s),this.scheduleRefresh(t))}isElementVisibleInBrowser(e){var t=document.getElementById(e);if(null!==t){var s=t.getBoundingClientRect();if(s.top>=0&&s.left>=0&&s.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&s.right<=(window.innerWidth||document.documentElement.clientWidth))return!0}return!1}}var r=(e=>(e.Off="Off",e.PreSurvey="PreSurvey",e.Collect="Collect",e.PostSurvey="PostSurvey",e))(r||{});class d{constructor(e,t){this.lineItemImpressions=[],this.surveysIdsCompleted=[],this.lineItemImpressions=e,this.surveysIdsCompleted=t}addImpression(e,t){let s={brandId:e,lineItemId:t,timestamp:new Date};this.lineItemImpressions.push(s)}addBrandSurveyCompleted(e){-1===this.surveysIdsCompleted.indexOf(e)&&this.surveysIdsCompleted.push(e)}getTotalBrandImpressions(){let e=new Map;for(let t of this.lineItemImpressions)if(e.has(t.brandId)){let s=e.get(t.brandId);e.set(t.brandId,s+1)}else e.set(t.brandId,1);return e}getBrandLineItemImpressions(e){let t={};for(let s of this.lineItemImpressions)if(s.brandId==e)if(void 0!==t[s.lineItemId]){let e=t[s.lineItemId];t[s.lineItemId]=e+1}else t[s.lineItemId]=1;return t}}class l{constructor(){this.surveyEngagementLocalStorageKey="clc-survey-engagement"}getBrandSurveyEngagement(){let e=localStorage.getItem(this.surveyEngagementLocalStorageKey);if(null===e)return new d([],[]);let t=JSON.parse(e);return new d(t.lineItemImpressions,t.surveysIdsCompleted)}saveBrandSurveyEngagement(e){let t=JSON.stringify(e);localStorage.setItem(this.surveyEngagementLocalStorageKey,t)}}class c{constructor(){this.surveyRepository=new l}getBrandSurveyEngagement(){return this.surveyRepository.getBrandSurveyEngagement()}recordImpression(e,t){let s=this.getBrandSurveyEngagement();s.addImpression(e,t),this.surveyRepository.saveBrandSurveyEngagement(s)}recordBrandSurveyCompleted(e){let t=this.getBrandSurveyEngagement();t.addBrandSurveyCompleted(e),this.surveyRepository.saveBrandSurveyEngagement(t)}}class g{constructor(t,s){this.googletag=t,this.brandSettings=s,this.brandSlotMap=new Map,this.brandSurveyEngagementService=new c,e.cM("Brand Survey init: "+JSON.stringify(s)),void 0!==s?(this.googletag.pubads().addEventListener("slotRenderEnded",e=>this.handleSlotRendered(e)),this.googletag.pubads().addEventListener("impressionViewable",e=>this.onImpressionViewable(e)),e.cM("done enabling Brand Survey")):e.cM("Brand Survey init: brandSettings is undefined, not initializing")}handleSlotRendered(t){e.cM("Brand Survey - slot rendered - slot:"+JSON.stringify(t.slot.getSlotElementId())+" lineItem: "+t.lineItemId);let s=this.findItemWithId(t.lineItemId);if(null===s||s.mode!==r.Collect)this.brandSlotMap.delete(t.slot.getSlotElementId());else{let e={brandId:s.brandId,lineItemId:t.lineItemId};this.brandSlotMap.set(t.slot.getSlotElementId(),e)}}onImpressionViewable(t){let s=t.slot;if(e.cM("ad - Brand Survey - impression viewable. Details: "+JSON.stringify(s.getSlotElementId())),e.cM("ad - Brand Survey - slot "+s.getSlotElementId()+" is viewable"),this.brandSlotMap.has(s.getSlotElementId())){let t=this.brandSlotMap.get(s.getSlotElementId());e.cM("Brand Survey - brand "+t.brandId+" is viewable"),this.recordImpression(this.brandSlotMap.get(s.getSlotElementId()))}}recordImpression(t){e.cM("ad - Brand Survey - recording impression for brand "+t.brandId),this.brandSurveyEngagementService.recordImpression(t.brandId,t.lineItemId)}findItemWithId(t){return e.cM("brand settings: "+JSON.stringify(this.brandSettings)),this.brandSettings.find(e=>e.lineItemIds.includes(t))||null}}const p="response-brand-survey-submit|",h="request-brand-survey-metadata|",m="record-metric-on-server|",u="request-dsp-tags",f="response-dsp-tags|";class _{static refreshAdIfBrandSurveyIsDuplicated(e,t,s){if(this.alreadyCompletedThisBrandSurvey(t)){var n=document.getElementById(s).closest(".js-zone-container");i.removeMyAd(e,s),n&&n.remove()}}static alreadyCompletedThisBrandSurvey(e){return(new c).getBrandSurveyEngagement().surveysIdsCompleted.includes(e)}}window.cam=new class{constructor(t=null){if(this.gptImported=!1,this.slotsRenderedEvents=[],this.collapsed={},e.cM("constructor"),this.clc_options=s,window.clcGamLoaderOptions)Object.assign(this,window.clcGamLoaderOptions);else if(void 0===this.opt){let e=window.opt;e&&(this.opt=e)}}init(){if(e.cM("init"),void 0===this.opt)throw new Error("opt not set, required by GAM Loader");e.cM("init brand survey service"),this.getUserMetaPromise=this.getUserMeta(),e.cM("setup message handler"),window.addEventListener("message",e=>{this.onmessage(e)})}handleSlotRenderedNoAdReport(){if(googletag.pubads().addEventListener("slotRenderEnded",e=>this.applyExtraMarginBottom(e)),Array.isArray(this.slotsRenderedEvents))for(var e=0;e<this.slotsRenderedEvents.length;e++)this.applyExtraMarginBottom(this.slotsRenderedEvents[e])}onmessage(t){let s="omni";if(t.data&&("string"==typeof t.data||t.data instanceof String))if(0===t.data.indexOf("get-omni-")){e.cM("Recevied get-omni message, sending back omni");var n=t.source,a=this.opt.omni,i="string"==typeof a?a:"";n.postMessage([s,i,this.opt.perRequestGuid].join("|"),"*")}else if(0===t.data.indexOf("collapse-")){e.cM("Recevied collapse message, collapse ad iframe"),e.cM(t);for(var r=t.source.window,d=document.getElementsByTagName("IFRAME"),l=0;l<d.length;l++){var g=d[l];if(g.contentWindow==r)return void(0,o.wo)(g.parentElement.parentElement.parentElement)}}else if(0===t.data.indexOf("resize|")){e.cM("Recevied resize message, resize ad iframe"),e.cM(t);let s=this._getFrameByEvent(t),n=t.data.indexOf("|")+1,o=t.data.slice(n),a=parseFloat(o)+.5;e.cM("New iframe height "+a),s.height=a.toString(),s.parentElement.style.height=a.toString()+"px"}else if(0===t.data.indexOf("getmarkup|")){let s=t.data.indexOf("|")+1,n=t.data.slice(s);e.cM("Recevied get markup message: "+n);let o=this._getFrameByEvent(t).closest(".everyonelovesstackoverflow");const a=document.createElement("script");a.dataset.adZoneId=o.id,a.src=n,document.body.appendChild(a)}else if(0===t.data.indexOf("window-location|")){let s=t.data.indexOf("|")+1,n=t.data.slice(s);e.cM("Recevied window location message: "+n),n.startsWith("/")||(n="/"+n),window.open(window.location.protocol+"//"+window.location.host+n,"_blank")}else if(0===t.data.indexOf("request-brand-survey-submit|")){let s=t.data.split("|"),n=s[1],o=s[2],a=s[3],i=JSON.parse(a);e.cM(n),e.cM(o),e.cM(a),e.cM("Received brand survey "+n+" response message: "+o);var v=new FormData;for(var b in i)v.append(b,i[b]);let r=this._getFrameByEvent(t);if(_.alreadyCompletedThisBrandSurvey(+n))return e.cM("Already completed this brand survey. Not submitting duplicate to server."),void r.contentWindow.postMessage("response-brand-survey-submit-duplicate|","*");e.cM("Send the brand survey to the server"),fetch(o,{method:"POST",body:v}).then(e=>e.json()).then(e=>r.contentWindow.postMessage({messageType:p},"*")).catch(e=>r.contentWindow.postMessage({messageType:p},"*"))}else if(0===t.data.indexOf("brand-survey-completed-store|")){let s=t.data.split("|"),n=(s[1],s[2]);if(e.cM("Received brand survey completed store message for survey ID "+n),_.alreadyCompletedThisBrandSurvey(+n))return void e.cM("Already completed this brand survey. Not recording duplicate locally.");e.cM("Record brand survey completion locally"),(new c).recordBrandSurveyCompleted(+n)}else if(0===t.data.indexOf(h)){let s=t.data.split("|"),n=s[1],o=s[2];e.cM("Received message: "+h+" with Brand Survey ID "+o);let a=(new c).getBrandSurveyEngagement().getBrandLineItemImpressions(+n),i=JSON.stringify(a),r=this._getFrameByEvent(t);e.cM("sending impression data: "+i),r.contentWindow.postMessage("response-brand-survey-metadata|"+this.opt.responseHash+"|"+this.opt.perRequestGuid+"|"+i+"|"+this.opt.countryCode+"|"+this.opt.qualtricsSurveyData,"*")}else if(0===t.data.indexOf("refresh-if-duplicate-brand-survey|")){let e=t.data.split("|")[1],s=this.getSlotElementIdByEvent(t);_.refreshAdIfBrandSurveyIsDuplicated(googletag,+e,s)}else if(0===t.data.indexOf(m)){e.cM("Received message: "+m+" with args: "+t.data);let s=t.data.split("|"),n=s[1],o=s[2],a=s[3],i=s[4],r=new FormData;r.append("brandSurveyId",a.toString()),r.append("responseHash",this.opt.responseHash),r.append("perRequestGuid",this.opt.perRequestGuid),r.append("questionNumber",n.toString()),r.append("metricType",i.toString()),fetch(o,{method:"POST",body:r}).then(e=>e.ok).catch(t=>{e.cM("SendMetricToServer: Error sending metric to server: "+t)})}else if(0===t.data.indexOf(u)){e.cM("Received message: "+u+" with args: "+t.data);let s=this._getFrameByEvent(t);if(!this.opt.targeting["so-tag"])return void s.contentWindow.postMessage(f,"*");const n=this.opt.targeting["so-tag"].join(",");e.cM("sending targeting tags: "+n),s.contentWindow.postMessage(f+n,"*")}else e.cM("Received unhandled message")}getSlotElementIdByEvent(e){let t=this._getFrameByEvent(e),s=t.parentElement?.parentElement?.id;return s||""}_getFrameByEvent(e){return Array.from(document.getElementsByTagName("iframe")).filter(t=>t.contentWindow===e.source)[0]}classifyZoneIds(e){const t=e.map(o.Nj).filter(o.yb);return{eligible:t.filter(o.xb).filter(o.pn),ineligible:t.filter(o.xj)}}applyExtraMarginBottom(t){if(t&&t.slot&&!t.isEmpty&&(t.creativeId||t.lineItemId||!t.isEmpty)){var s=t.slot.getSlotElementId();if(s){var o=document.getElementById(s);if(o)if((0,n.eq)(s)){var a=o?.closest(".js-zone-container");a.style.marginBottom="24px",e.cM("Applied extra margin to the bottom of "+s)}else e.cM("Not applying extra margin to the bottom of "+s+": shouldHaveReportButton = false");else e.cM("Not applying extra margin to the bottom of "+s+": resolved invalid adUnit element")}else e.cM("Not applying extra margin to the bottom of element: invalid adUnitElementId")}else e.cM("Not applying extra margin to the bottom of element: invalid SlotRenderEndedEvent")}async load(s=(0,n.kG)()){const r=this.opt.tlb_position===t.Above?["dfp-mlb","dfp-smlb"]:["dfp-mlb","dfp-smlb","dfp-tlb"];if(!this.isGptReady())return e.cM("Initializing..."),this.initGpt(),void googletag.cmd.push(()=>this.load(s));this.opt.adReportEnabled?(e.cM("Ad reporting enabled"),this.adReports=new a.t(googletag,this)):(e.cM("Ad reporting not enabled"),this.handleSlotRenderedNoAdReport()),this.opt.refresh?(e.cM("Ad refresh enabled"),this.adRefresh=new i(googletag,this.opt.refreshInterval)):e.cM("Ad refresh not enabled"),this.opt.brandSurveyEnabled&&(e.cM("Brand Survey enabled"),this.brandSurvey=new g(googletag,this.opt.brandSurveySettings)),e.cM("Attempting to load ads into ids: ",s);const{eligible:d,ineligible:l}=this.classifyZoneIds(s);if(this.initDebugPanel(googletag,d.concat(l)),d.forEach(e=>(0,o.cf)(e)),l.forEach(o.wo),0===d.length)return void e.cM("Found no ad ids on page");e.cM("Eligible ids:",d),this.opt.abd&&this.appendAdblockDetector();var c=googletag.pubads().getSlots();if(c){var p=c.filter(e=>s.indexOf(e.getSlotElementId())>=0);googletag.destroySlots(p)}this.opt.sf&&(googletag.pubads().setForceSafeFrame(!0),googletag.pubads().setSafeFrameConfig({allowOverlayExpansion:!0,allowPushExpansion:!0,sandbox:!0})),e.cM("Targeting consent: Checking...");let h=!1,m=!1;void 0!==this.opt.targeting_consent&&(m=!0,e.cM("Targeting consent: Parameter set"),e.cM("Targeting consent: Consent given? ",this.opt.targeting_consent),h=this.opt.targeting_consent),void 0!==this.opt.personalization_consent&&(e.cM("Personalization consent: Parameter set"),e.cM("Personalization consent: Consent given? ",this.opt.personalization_consent),h=h&&this.opt.personalization_consent),h=h&&m,this.setPrivacySettings(h),this.opt.ll||googletag.pubads().enableSingleRequest(),cam.sreEvent||(googletag.pubads().addEventListener("slotRenderEnded",e=>this.onSlotRendered(e)),cam.sreEvent=!0),await this.setTargeting();var u=d.filter(e=>!this.opt.ll||r.indexOf(e.id)<0),f=d.filter(e=>!!this.opt.ll&&r.indexOf(e.id)>=0);e.cM("Up front ids:",u),e.cM("Lazy loaded ids:",f),u.forEach(t=>{e.cM(`Defining ad for element ${t.id}`),this.defineSlot(t.id,googletag),t.setAttribute("data-dfp-zone","true")}),googletag.enableServices(),u.forEach(t=>{e.cM(`Displaying ad for element ${t.id}`),this.clc_options.dv_enabled?window.onDvtagReady(function(){googletag.display(t.id)}):googletag.cmd.push(()=>googletag.display(t.id))}),this.opt.ll&&(e.cM("Enabling lazy loading for GAM"),googletag.pubads().enableLazyLoad({fetchMarginPercent:0,renderMarginPercent:0}),e.cM("Setting up lazy loaded ad units"),f.forEach(t=>{e.cM(`Lazy loading - Defining Slot ${t.id}`),this.defineSlot(t.id,googletag)}),f.forEach(t=>{e.cM(`Lazy loading - Displaying ad for element ${t.id}`),this.clc_options.dv_enabled?window.onDvtagReady(function(){googletag.display(t.id)}):googletag.cmd.push(()=>googletag.display(t.id))}))}setPrivacySettings(e){e||googletag.pubads().setPrivacySettings({nonPersonalizedAds:!0})}async setTargeting(){if(!googletag)throw new Error("googletag not defined");let t=this.opt.targeting;if(!t)throw new Error("Targeting not defined (is "+typeof t+")");Object.keys(t).forEach(s=>{e.cM(`-> targeting - ${s}: ${t[s]}`),googletag.pubads().setTargeting(s,t[s])});let s=!1;if(void 0!==this.opt.targeting_consent&&(s=this.opt.targeting_consent),s){let t=(new c).getBrandSurveyEngagement();if(t.getTotalBrandImpressions().forEach((t,s)=>{e.cM(`-> targeting - BrandImpressions: ${s}: ${t}`),googletag.pubads().setTargeting("brand_"+s.toString()+"_impressions",t.toString())}),t.surveysIdsCompleted.forEach(t=>{e.cM(`-> targeting - SurveysTaken: ${t}`),googletag.pubads().setTargeting("survey_"+t+"_taken","true")}),this.clc_options.tgt_e&&this.getUserMetaPromise){let t=await this.getUserMetaPromise;t&&t.tgt_acct?(e.cM("-> targeting - User Account: "+t.tgt_acct),googletag.pubads().setTargeting("user-acct",t.tgt_acct.company_name),googletag.pubads().setTargeting("user_acct_top",t.tgt_acct.company_name),googletag.pubads().setTargeting("user_industry",t.tgt_acct.industry),googletag.pubads().setTargeting("user_employee_count",t.tgt_acct.employee_range)):e.cM("-> targeting - User Account: Not Found"),t&&Object.prototype.hasOwnProperty.call(t,"is_high_rep_earner")?(e.cM("-> targeting - High Rep Earner: "+t.is_high_rep_earner),googletag.pubads().setTargeting("IsHighRepEarner",t.is_high_rep_earner?"true":"false")):e.cM("-> targeting - High Rep Earner: not found")}if(localStorage){e.cM('Checking local storage for "jobs-last-clicked" key.');let t=localStorage.getItem("jobs-last-clicked")?"true":"false";e.cM(`-> targeting - jobs_clicked: ${t}`),googletag.pubads().setTargeting("jobs_clicked",t)}}}appendAdblockDetector(){const e=document.createElement("div");e.className="adsbox",e.id="clc-abd",e.style.position="absolute",e.style.pointerEvents="none",e.innerHTML="&nbsp;",document.body.appendChild(e)}onSlotRendered(s){try{const i=s.slot.getSlotElementId();let r=[];i||r.push("id=0");const d=document.getElementById(i);if(i&&!d&&r.push("el=0"),0!==r.length)return void this.stalled(r.join("&"));const{path:l,sizes:c,zone:g}=(0,n.Z7)(i,this.clc_options.upo);if(this.collapsed[g]&&s.isEmpty)return e.cM(`No line item for the element #${d.id}... collapsing.`),void(0,o.wo)(d);if(this.slotsRenderedEvents.push(s),s.lineItemId||s.creativeId||!s.isEmpty){e.cM(`Rendered ad for element #${d.id} [line item #${s.lineItemId}]`),e.cM(s);var a=d.parentElement;if(a.classList.contains("js-zone-container")){switch((0,o.cf)(a),i){case"dfp-tlb":this.opt.tlb_position===t.Above?a.classList.add("mb8"):a.classList.add("mt16");break;case"dfp-tag":a.classList.add("mb8");break;case"dfp-msb":a.classList.add("mt16");break;case"dfp-mlb":case"dfp-smlb":case"dfp-bmlb":a.classList.add("my8");break;case"dfp-isb":a.classList.add("mt24");break;case"dfp-m-aq":a.classList.add("my12"),a.classList.add("mx-auto")}(0,o.$Z)(a),(0,o.$Z)(d)}else e.cM(`No ad for element #${d.id}, collapsing`),e.cM(s),(0,o.wo)(d)}}catch(t){e.cM("Exception thrown onSlotRendered"),e.cM(t),this.stalled("e=1")}}stalled(e){(new Image).src=`https://${this.clc_options.h}/stalled.gif?${e}`}defineSlot(t,s){"dfp-isb"===t&&(e.cM("-> targeting - Sidebar: Inline"),s.pubads().setTargeting("Sidebar",["Inline"])),"dfp-tsb"===t&&(e.cM("-> targeting - Sidebar: Right"),s.pubads().setTargeting("Sidebar",["Right"]));const{path:o,sizes:a,zone:i}=(0,n.Z7)(t,this.clc_options.upo);e.cM(`Defining slot for ${t}: ${o}, sizes: ${JSON.stringify(a)}`),s.defineSlot(o,a,t).addService(s.pubads())}importGptLibrary(){this.gptImported||(this.gptImported=!0,void 0===this.opt.targeting_consent||this.opt.targeting_consent?(0,o.Gx)("https://securepubads.g.doubleclick.net/tag/js/gpt.js"):(0,o.Gx)("https://pagead2.googlesyndication.com/tag/js/gpt.js"))}importDvLibrary(){this.clc_options.dv_enabled&&(e.cM("Adding DoubleVerify library"),(0,o.Gx)("https://pub.doubleverify.com/dvtag/21569774/DV1289064/pub.js"),e.cM("Adding DoubleVerify onDvtagReady handler"),window.onDvtagReady=function(t,s=750){e.cM("DoubleVerify onDvtagReady called"),window.dvtag=window.dvtag||{},dvtag.cmd=dvtag.cmd||[];const n={callback:t,timeout:s,timestamp:(new Date).getTime()};dvtag.cmd.push(function(){dvtag.queueAdRequest(n)}),setTimeout(function(){const e=n.callback;n.callback=null,e&&e()},s)})}isGptReady(){return"undefined"!=typeof googletag&&!!googletag.apiReady}initGpt(){"undefined"==typeof googletag&&(window.googletag={cmd:(0,o.QZ)(()=>{this.importGptLibrary(),this.importDvLibrary()})})}getUserMeta(){if(this.opt.allowAccountTargetingForThisRequest&&this.clc_options.tgt_e&&this.clc_options.tgt_p>0){if(e.cM("Targeting enabled."),this.clc_options.tgt_p<100){e.cM("Targeting rate limit enabled. Rolling the dice...");const t=Math.floor(100*Math.random())+1;if(e.cM("Rolled "+t+" and the max is "+this.clc_options.tgt_p),t>this.clc_options.tgt_p)return void e.cM("Will not request targeting.")}return e.cM("Will request targeting."),function(e,t,s,n){if(t){const t=new Headers;return t.append("Accept","application/json"),async function(e,t={},s=5e3){if("number"!=typeof s&&null!=s&&!1!==s){if("string"!=typeof s)throw new Error("fetchWithTimeout: timeout must be a number");if(s=parseInt(s),isNaN(s))throw new Error("fetchWithTimeout: timeout must be a number (or string that can be parsed to a number)")}const n=new AbortController,{signal:o}=n,a=fetch(e,{...t,signal:o}),i=setTimeout(()=>n.abort(),s);try{const e=await a;return clearTimeout(i),e}catch(e){throw clearTimeout(i),e}}(s+"?"+new URLSearchParams({omni:e}),{method:"GET",mode:"cors",headers:t},n).then(e=>e.json())}return Promise.reject("No consent")}(this.opt.omni,this.opt.targeting_consent,this.clc_options.tgt_u,this.clc_options.tgt_to).catch(t=>{e.vU("Error fetching user account targeting"),e.vU(t)})}e.cM("Targeting disabled. Will not request account targeting data.")}initDebugPanel(t,s){e.cM("initDebugPanel"),e.cM("Not showing debug panel.")}},window.clcGamLoaderOptions&&(cam.init(),cam.load())})()})();</script>
<footer id="footer" class="site-footer js-footer" role="contentinfo">
<div class="site-footer--container">
<nav class="site-footer--nav" aria-label="Footer">
<div class="site-footer--col">
<h5 class="-title"><a href="/">Code Review</a></h5>
<ul class="-list js-primary-footer-links">
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 2 })" href="/tour">Tour</a></li>
<li><a href="/help" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 3 })">Help</a></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 5 })" href="https://chat.stackexchange.com?tab=site&host=codereview.stackexchange.com">Chat</a></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 13 })" href="/contact">Contact</a></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 14 })" href="https://codereview.meta.stackexchange.com">Feedback</a></li>
</ul>
</div>
<div class="site-footer--col">
<h5 class="-title"><a class="js-gps-track" data-gps-track="footer.click({ location: 2, link: 1 })" href="https://stackoverflow.co/">Company</a></h5>
<ul class="-list">
<li><a href="https://stackoverflow.com" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 15})">Stack Overflow</a></li>
<li><a href="https://stackoverflow.co/teams/" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 29 })">Teams</a></li>
<li><a href="https://stackoverflow.co/advertising/" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 21 })">Advertising</a></li>
<li><a href="https://stackoverflow.co/advertising/employer-branding/" class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 20 })">Talent</a></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 1 })" href="https://stackoverflow.co/">About</a></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 27 })" href="https://stackoverflow.co/company/press/">Press</a></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 7 })" href="https://stackoverflow.com/legal">Legal</a></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 8 })" href="https://stackoverflow.com/legal/privacy-policy">Privacy Policy</a></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 37 })" href="https://stackoverflow.com/legal/terms-of-service/public">Terms of Service</a></li>
<li id="consent-footer-link"><button type="button" data-controller="cookie-settings" data-action="click->cookie-settings#toggle" class="s-btn s-btn__link py4 js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 38 })" data-consent-popup-loader="footer">
Cookie Settings </button></li>
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link: 39 })" href="https://stackoverflow.com/legal/cookie-policy">Cookie Policy</a></li>
</ul>
</div>
<div class="site-footer--col site-footer--categories-nav">
<div>
<h5 class="-title"><a href="https://stackexchange.com" data-gps-track="footer.click({ location: 2, link: 30 })">Stack Exchange Network</a></h5>
<ul class="-list">
<li>
<a href="https://stackexchange.com/sites#technology" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
Technology
</a>
</li>
<li>
<a href="https://stackexchange.com/sites#culturerecreation" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
Culture &amp; recreation
</a>
</li>
<li>
<a href="https://stackexchange.com/sites#lifearts" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
Life &amp; arts
</a>
</li>
<li>
<a href="https://stackexchange.com/sites#science" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
Science
</a>
</li>
<li>
<a href="https://stackexchange.com/sites#professional" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
Professional
</a>
</li>
<li>
<a href="https://stackexchange.com/sites#business" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
Business
</a>
</li>
<li class="mt16 md:mt0">
<a href="https://api.stackexchange.com/" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
API
</a>
</li>
<li>
<a href="https://data.stackexchange.com/" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 24 })">
Data
</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="site-footer--copyright fs-fine md:mt24">
<ul class="-list -social md:mb8">
<li><a class="js-gps-track -link" data-gps-track="footer.click({ location: 2, link:4 })" href="https://stackoverflow.blog?blb=1">Blog</a></li>
<li><a href="https://www.facebook.com/officialstackoverflow/" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 31 })">Facebook</a></li>
<li><a href="https://twitter.com/stackoverflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 32 })">Twitter</a></li>
<li><a href="https://linkedin.com/company/stack-overflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 33 })">LinkedIn</a></li>
<li><a href="https://www.instagram.com/thestackoverflow" class="-link js-gps-track" data-gps-track="footer.click({ location: 2, link: 36 })">Instagram</a></li>
</ul>
<p class="md:mb0">
<span>Site design / logo © 2025 Stack Exchange Inc; </span>
<span>user contributions licensed under </span>
<a class="-link s-link td-underline" href="https://stackoverflow.com/help/licensing">CC BY-SA</a>
<span>. </span>
<span id="svnrev">rev&nbsp;2025.3.27.24496</span>
</p>
</div>
</div>
</footer>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-S812YQPLT2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
</script>
<script>
StackExchange.ready(function() {
var ga3Settings = {
autoLink: ["stackoverflow.blog","info.stackoverflowsolutions.com","stackoverflowsolutions.com"],
sendTitles: true,
tracker: window.ga,
trackingCodes: [
'UA-108242619-5'
],
checkDimension: 'dimension42'
};
var customGA4Dimensions = {};
customGA4Dimensions["requestid"] = "8b89fffe-e4e2-46a9-b938-cf7f2b66ca95";
customGA4Dimensions["routename"] = "Questions/Show";
customGA4Dimensions["post_id"] = "27986";
customGA4Dimensions["tags"] = "|c&#x2B;&#x2B;|game|classes|adventure-game|";
var ga4Settings = {
tracker: gtag,
trackingCodes: [
'G-S812YQPLT2'
],
consentsToPerformanceCookies: "denied",
consentsToTargetingCookies: "denied",
eventParameters: customGA4Dimensions,
checkForAdBlock: true,
sendTitles: true,
trackClicks: false,
};
StackExchange.ga.init({ GA3: ga3Settings, GA4: ga4Settings });
StackExchange.ga.setDimension('dimension1', '41080829');
StackExchange.ga.setDimension('dimension2', '|c&#x2B;&#x2B;|game|classes|adventure-game|');
StackExchange.ga.setDimension('dimension3', 'Questions/Show');
StackExchange.ga.setDimension('dimension7', "1743331693.533644000");
StackExchange.ga.trackPageView();
});
</script>
<script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" charset="UTF-8" data-document-language="true" data-domain-script="cb0f3c87-b769-4e66-bbaa-377f9194216d"></script>
<script defer src="https://cdn.sstatic.net/Js/modules/cookie-consent.en.js?v=36bebc18e04f"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment