/    Sign up×
Community /Pin to ProfileBookmark

somebody please help me.. battle simulator

I’m trying to make a battle simulator where you can select classes to fight each other. I can’t for the life of me understand what i’m doing wrong!

[code]
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<!–[if IE]>
<script src=”http://html5shiv.googlecode.com/svn/trunk/html5.js”></script>
<![endif]–>
<link href=”CSS/styles.css” type=”text/css” rel=”stylesheet” />

<script type=”text/javascript”>

var monsters = {

reaper : { hitpoints: 250, strength : 17, luck : 3 },

dragon : { hitpoints: 1000, strength: 50, luck : 5},

orc : { hitpoints: 100, strength: 12, luck : 2 },

ogre: { hitpoints: 50, strength: 10, luck: 1 }

}

function startFight()
{
charFightHP = charHP;
beastFightHP = beastHP;
fightTrue = 1;
charDmg = charStr – beastDef;
beastDmg = beastStr – charDef;
beastName = document.getElementById(“theBName”).innerHTML;

if (charDmg < 0)
{
charDmg = 0;
}
else if (beastDmg < 0)
{
beastDmg = 0;
}

while (fightTrue != 0)
{
if (charFightHP > 0 && beastFightHP > 0)
{
charFightHP = beastDmg – charFightHP;
beastFightHP = charDmg – beastFightHP;
alert(“You do “+charDmg+” damage to “+beastName+”. “+beastName+” does “+beastDmg+” damage to you.”);
document.getElementById(“theHP”).innerHTML = charFightHP;
document.getElementById(“theBHP”).innerHTML = beastFightHP;
}
else{
fightTrue = 0;
}
}

if (beastFightHP < 0 && charFightHP > 0)
{
fightWin();
}

if (charFightHP < 0)
{
alert(“You are dead”);
createChar();
}
}

</script>

</head>
<header>

<div style=”clear:both;”></div>
</header>
<body>

<div id=”content”>
<form class=”form”>

<h2>Simulator</h2>

<field name=”fieldName” static=”true” type=”FieldType” value=”code”>Strength</field>

<input type = “text” value=”300″ disabled=”disable” id=”hitpoints” />

<input type = “text” value=”100″ disabled=”disable” id=”strength” />

<input type = “text” value=”100″ disabled=”disable” id=”luck” />

<select>
<option>Dragon</option>
<option>Orc</option>
<option>Ogre</option>
<option>Reaper</option>
</select>

<input type=”button” value=”Fight” onclick=”startFight()”;/>

</form>
</div>
</body>
<footer>

</footer>
</html>
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@chrisranjanaMar 18.2013 — Most of the Right Hand Side variables in the function startFight() seems to be undefined ?
Copy linkTweet thisAlerts:
@fastskater07authorMar 18.2013 — Yes I pulled that function from the internet and posted it to see if that was helpful. I thought it would steer me in the way of figuring it out but i dont understand it.
Copy linkTweet thisAlerts:
@fastskater07authorMar 18.2013 — This is my code thus far (all of what I coded)

<i>
</i>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Register&lt;/title&gt;
&lt;!--[if IE]&gt;
&lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
&lt;![endif]--&gt;
&lt;link href="CSS/styles.css" type="text/css" rel="stylesheet" /&gt;

<i> </i>&lt;script type="text/javascript"&gt;
var character = { hitpoints: 300, strength: 100, luck: 100}

var monsters = {
reaper : { hitpoints: 250, strength : 17, luck : 3 },
dragon : { hitpoints: 1000, strength: 50, luck : 5},
orc : { hitpoints: 100, strength: 12, luck : 2 },
ogre: { hitpoints: 50, strength: 10, luck: 1 }
}

function battlesim()
{

}




<i> </i>&lt;/script&gt;

<i> </i>&lt;/head&gt;
<i> </i>&lt;header&gt;


<i> </i> &lt;div style="clear:both;"&gt;&lt;/div&gt;
<i> </i>&lt;/header&gt;
<i> </i>&lt;body&gt;




<i> </i> &lt;div id="content"&gt;
<i> </i> &lt;form class="form"&gt;



&lt;h2&gt;Simulator&lt;/h2&gt;

&lt;field name="fieldName" static="true" type="FieldType" value="code"&gt;Strength&lt;/field&gt;


&lt;input type = "text" value="300" disabled="disable" id="" /&gt;

&lt;input type = "text" value="100" disabled="disable" id="" /&gt;

&lt;input type = "text" value="100" disabled="disable" id="" /&gt;

&lt;select&gt;
&lt;option&gt;Dragon&lt;/option&gt;
&lt;option&gt;Orc&lt;/option&gt;
&lt;option&gt;Ogre&lt;/option&gt;
&lt;option&gt;Reaper&lt;/option&gt;
&lt;/select&gt;






&lt;input type="button" value="Fight" onclick='battlesim()';/&gt;

<i> </i>&lt;/form&gt;
<i> </i> &lt;/div&gt;
<i> </i>&lt;/body&gt;
<i> </i>&lt;footer&gt;

<i> </i>&lt;/footer&gt;
&lt;/html&gt;
×

Success!

Help @fastskater07 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...