Jump to content

[SOLVED] Combat game not working?


Roy766

Recommended Posts

Well, I was making a combat game, and I have so far come up with the following code:

 

<html>
<head>
<title>Combat Game</title>
</head>
<body>
<form>
Sword-wielding footmen:<input type="text" name="swordfootmen"><br>
Lance-wielding footmen:<input type="text" name="lancefootmen"><br>
Mounted sword wielders:<input type="text" name="mountedswordsmen"><br>
Mounted lance wielders:<input type="text" name="mountedlancemen"><br>
Horses:<input type="text" name="horses"><br>
<input type="submit" value="Attack!"><br>
</form>
<?php
  $sfcost = $_REQUEST['swordfootmen'] * 3;
  $lfcost = $_REQUEST['lancefootmen'] * 3;
  $mswcost = $_REQUEST['mountedswordsmen'] * 5;
  $mlwcost = $_REQUEST['mountedlancemen'] * 5;
  $hcost = $_REQUEST['horses'];
  $totalcost = $sfcost + $lfcost + $mswcost + $mlwcost;
  $sfatk = $_REQUEST['swordfootmen'] * 2;
  $lfatk = $_REQUEST['lancefootment'] * 2;
  $mswatk = $_REQUEST['mountedswordsmen'] * 4;
  $mlwatk = $_REQUEST['mountedlancemen'] * 4;
  $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $hcost;
  $compatk = rand(10, 150);
  if ( $totalatk > 150 )
    {
    echo "You spent too much money!";
    }
  else
    {
    echo "Your total attack force is " . $totalatk;
    }
   echo 'The computer's total attack force is ' . $compatk;
  if ( $compatk > $totalatk )
    {
    echo 'Sorry, the computer wins...';
    }
  else
    {
    echo 'You win! Congratulations!';
    }
?>
</body>
</html>

 

Well, I've been proofreading the file for the past 20 minutes, and I haven't found a thing.

I have tried the above code on two different hosts: my freehostia and my T35. Freehostia pops up with:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/www/roy766.freehostia.com/combatgame.php on line 35

and of course my T35 page just pops up with nothing, as usual.

 

I have checked line 35 (the second if statement) so many times that I have it memorized, but I can't find a single thing wrong with it.

 

If somebody finds some stupid mistake I made, I'm gonna slap myself to death  :P.

 

EDIT: Well, I defined the additional attack power of the horses with their cost...not like it matters. New line:

$hatk = $_REQUEST['horses'];

Line twenty-six is now:

$totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $hatk;

 

No difference in the error factor.

 

EDIT: OH MY GOD! "computer's" ends the echo tag! I AM SO STUPID! Please delete topic!

Link to comment
https://forums.phpfreaks.com/topic/107027-solved-combat-game-not-working/
Share on other sites

When I finished editing my post, you had replied with the error I found. One of the problems of having a large forum  :-\

 

:P

 

Well it took me about 20 seconds to be honest.. Put it in my notepad2 and looked at line 35..

 

Please press the "Topic Solved" button!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.