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);
?>