Jump to content

Need help


Worqy

Recommended Posts

Hi.

I'm making a little game, and I have done a bit progress in it.

But now I want the player to chance to build some buildings.

 

Here is the code:

<?php


Session_start();

if($_SESSION['LoginS1'] == false) 
{
header('Location:login.php');
}
else
{

// Include
include ("config.php");

// ...
$villageID = $_SESSION['villageID'];
$fieldid = $_SESSION['fieldID'];
$level = $_SESSION['level'];
$field = "field1";
$nextlevel = $level + 1;

// Connect to server and select database
$connect = mysql_connect("$host","$username","$password")or die("cannot connect");
mysql_select_db("s1-prices")or die("cannot select Database");
$sql = mysql_query("SELECT * FROM $field WHERE level='$nextlevel'") or die(mysql_error());
while($data = mysql_fetch_array( $sql )) 
{
	$three = $data['three'];
	$clay = $data['clay'];
	$iron = $data['iron'];
	$wheat = $data['wheat'];
	$time = $data['time'];
}

// Close MySQL
mysql_close($connect);

$connect2 = mysql_connect("$host","$username","$password")or die("cannot connect");
    mysql_select_db("s1-overall")or die("cannot select Database");
    $sql2 = mysql_query("SELECT * FROM resources") or die(mysql_error());
while($data2 = mysql_fetch_array( $sql2 )) 
{
	if($data2['three']  > $three && $data2['clay'] >  $clay && $data2['iron']  > $iron && $data2['clay']  > $clay) 
	{
		// Three
		mysql_query("UPDATE resources SET three = three-$three");
		//Clay
		mysql_query("UPDATE resources SET clay = three-$clay");
		//Iron
		mysql_query("UPDATE resources SET iron = three-$iron");
		//Wheat
		mysql_query("UPDATE resources SET wheat = three-$wheat");
		echo "Done!";
		echo "<br>";
		echo "Time: " . $time;

		// Set in Time value to MySQL
		// Run buildsuccess.php when time is 00:00:00
		}
	else 
	{
		header('Location:build.php');
	}
}
}
?>

 

Now, as you see this code searches for the 'price' of the building and the time how long it takes to build it ( $time ).

Now I need this script to but in the the time when the building is ready (ex: If the clock is now 12:00 and it takes 10min for the building to be ready, the time would be 12:10)

 

That isn't maby the bigges thing, because I also need somekind of system that checks if the time is 12:00 (when the building is ready ( see example)).

And this system need to run whatever the page is open or not...

//Kevin

Link to comment
Share on other sites

You possibly want to look at Ajax as altough PHP can track when a building is complete. You'll have to reload the page to verify with PHP that the building is truly complete. If you use a framework like jQuery it's really easy to apply Ajax calls.

 

Okey, thank you.

You know any specific Ajax tutorial/guide I would need to look at?

Because I haven't used Ajax quite much, or to be exact, I havent used Ajax to anything.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.