Dirty Scripts


When I’m building a game I like to jump right in and build the parts I don’t know much how to do.  In this time I felt like GD is a great place to make some fun images.  So today we start with a graphics port of hangman.

If men can run the world, why can’t they stop wearing neckties. How intelligent is it to start the day by tying a little noose around your neck.
-Linda Ellerbee

This code below is good for draw up to 13 misses, has code for drawing the word as well as the entire hangman graphic seen below

hangman

This is easily adaptable to several types of data sources including MYSQL, SQL Server, and any SQL or flat-file like csv. In the second part I will hook it up to a worldlist stored in Mysql.

0){
		//draw head
		imageellipse($im,$left_point,$bottom_point,$head_size,$head_size,$text_color);
	}
	if($misses>1){
		//draw body
		imageline($im,$left_point,$neck_point,$left_point,$leg_point,$text_color);
	}
	if($misses>2){
		//left leg
		imageline($im,$left_point,$leg_point,$left_legX,$left_legY,$text_color);
	}
	if($misses>3){
		//right leg
		imageline($im,$left_point,$leg_point,$right_legX,$right_legY,$text_color);
	}
	if($misses>4){
		//left arm
		imageline($im,$left_point,$neck_point,$left_arm,$neck_point,$text_color);
	}
	if($misses>5){
		//right arm
		imageline($im,$left_point,$neck_point,$right_arm,$neck_point,$text_color);
	}
	if($misses>6){
		//left leg
		imageellipse($im,$left_legX,$left_legY,$foot_size,$foot_size,$text_color);
	}
	if($misses>7){
		//right leg
		imageellipse($im,$right_legX,$right_legY,$foot_size,$foot_size,$text_color);
	}
	if($misses>8){
		//left hand
		imageellipse($im,$left_arm,$neck_point,$hand_size,$hand_size,$text_color);
	}
	if($misses>9){
		//right hand
		imageellipse($im,$right_arm,$neck_point,$hand_size,$hand_size,$text_color);
	}
	if($misses>10){
		//right eye
		imageellipse($im,$right_eyeX,$eyeY,$eye_width,$eye_height,$text_color);
	}
	if($misses>11){
		//left eye
		imageellipse($im,$left_eyeX,$eyeY,$eye_width,$eye_height,$text_color);
	}
	if($misses>12){
		//mouth
		imagearc($im,$left_point,$mouth_center,$mouth_width, $mouth_height, 160, 20,$text_color);
	}
	if($misses>13){
		//double x
		imageline($im,$right_eyeX-3,$eyeY-3,$right_eyeX+3,$eyeY+3,$text_color);
		imageline($im,$left_eyeX-3,$eyeY-3,$left_eyeX+3,$eyeY+3,$text_color);
		imageline($im,$right_eyeX+3,$eyeY-3,$right_eyeX-3,$eyeY+3,$text_color);
		imageline($im,$left_eyeX+3,$eyeY-3,$left_eyeX-3,$eyeY+3,$text_color);
	}

	return $im;
}

$im = drawTxt($im,$word,array('a'));
$im = drawHangMan($im,13);
header ("Content-type: image/png");
ImagePng ($im);
?>
Our Sponsors

Today I bring you an example of almost any type of form data to textfile representation in php.  The following code had id tags that can allow for easy cascade styling into whatever you believe is appropriate.

Remeber this is just an example and is not men to be used exclusively as a production forum or anything.   To make this a forum script, just change the $databoard to something like $databoard = ‘thread’.rand(1,99999);    Then just copy this everywhere you want to make a thread/forum.  You can just slap some graphics on it and you have a guestbook.

There is rudimentray error handling as well.  I hope you like it.


Posted on '.date('m-d-y').'
'.$name.'
'.$comments.'
'."\n"; file_put_contents($databoard,$old_data.$new_data); $result = '
Successfully Insertion of Comment
'; $display = file_get_contents($databoard); }else{ $display = file_get_contents($databoard); } echo $result; echo $display; ?>
Your Name

New opinions often appear first as jokes and fancies, then as blasphemies and treason, then as questions open to discussion, and finally as established truths.
-George Bernard Shaw

So tonight you better stop and rebuild all your ruins, because peace and trust can win the day despite all your losing.
-Led Zeppelin

When attempting to use my quotes grabber for a real-time application it turned out to take to long to request pages, parse them, then return a result for a high volume site.

A simple solution for a page that doesn’t change much in 24 hours (you can of course adjust for less) is the following PHP Caching system uses just a day file and checks against it.

$v)
		$ch = curl_init($v);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
		curl_setopt($ch, CURLOPT_HEADER      ,0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
		$url_str = curl_exec($ch);

		preg_match_all('~

]*>(.*?)

~is',$url_str,$matches);
		foreach($matches[0] as $k=>$v){
			$str .= $v;
		}

		file_put_contents($datename,$str);
	}else{
		$str = file_get_contents($datename);
	}

?>

Fairly simple but sometimes simple things evade the smartest people.

« Previous PageNext Page »