I am trying to make a checkers game for php

two players on the same computer here is what I got and was wondering if there's anything

wrong with this code

note: piece movement would be based from text move A1 to B2

function drawBoard()
{
			global $cBoard;

                	$R = "<img src=rp.gif>"; //Red piece
					$B = "<img src=bp.gif>";     //black piece
					$ES = "<img src=blank.gif>"; // legal square image
					$IS = "<img src=blank1.gif>"; //illegal square image





	$cBoard = array(
			  array($IS, $R, $IS, $R, $IS, $R, $IS, $R),
			  array($R, $IS, $R, $IS, $R, $IS, $R, $IS),
			  array($IS, $R, $IS, $R, $IS, $R, $IS, $R),
			  array($ES, $IS, $ES, $IS, $ES, $IS, $ES, $IS),
			  array($IS, $ES, $IS, $ES, $IS, $ES, $IS, $ES),
		          array($B, $IS, $B, $IS, $B, $IS, $B, $IS),
			  array($IS, $B, $IS, $B, $IS, $B, $IS, $B),
		          array($B, $IS, $B, $IS, $B, $IS, $B, $IS)
	);



            echo "<table border='3' width='200'>\n";
			foreach ($cBoard as $row)
			{
	     		 switch($row)
	     		 {
	     		 	case "8": $row = 0; break;
	     		 	case "7": $row = 1; break;
	     		 	case "6": $row = 2; break;
	     		 	case "5": $row = 3; break;
	     		 	case "4": $row = 4; break;
	     		 	case "3": $row = 5; break;
	     		 	case "2": $row = 6; break;
	     		 	case "1": $row = 7; break;

	     		 }

					echo "<tr>\n";
     				foreach ($row as $piece){
               				echo "<td>";
               				echo "$piece ";
               				echo "</td>\n";
               				 switch($Piece)
				             {
				             	case "A": $piece = 0; break;
				             	case "B": $piece = 1; break;
				             	case "C": $piece = 2; break;
				             	case "D": $piece = 3; break;
				             	case "E": $piece = 4; break;
				             	case "F": $piece = 5; break;
				             	case "G": $piece = 6; break;
				             	case "H": $piece = 7; break;
				     		 }
     				}
			}
					echo "</tr>\n";
					echo "</table>\n";

Recommended Answers

All 2 Replies

$piece in your switch block is capitalized, uncapitalized it.

switch($Piece)

I am having trouble making the pieces movie

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.