VB icon

PHP Mine

Email
Submitted on: 1/1/2015 3:03:00 AM
By: PHP Code Exchange (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 4416
 
     PHP version of famous "Minesweeper" game by Microsoft by Mathias Daval
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: PHP Mine
// Description:PHP version of famous "Minesweeper" game by Microsoft by Mathias Daval
// By: PHP Code Exchange (from psc cd)
//**************************************

<? 
/*/////// PHPMINE v1.0 
///////// 
// Copyright 2000, Kidou / PHPVault (http://www.phpvault.com) 
////////////////////////////////////////////////////////////////////////// 
// Ce script est un freeware. Vous pouvez l'utiliser et le modifier librement, mais vous devez laisser le copyright. Merci de me faire savoir si vous trouvez ce script utile. (mathias@phpvault.com) 
// PHPMine est une version PHP du célèbre jeu "Démineur" de Mirosoft. 
///////////////////////////////////////////////////////////////////////// 
// This script is a freeware. You can use it and modify it freely as long as you leave the copyright. Please tell me if you find this script useful (mathias@phpvault.com) 
// PHPMine is a PHP version of famous game "Minesweeper" by Microsoft. 
/////////////////////////////////////////////////////////////////////////*/ 
print "<html>"; 
print "<head>"; 
print "<title>PHPVault's PHPMine v1.0</title>"; 
print "</head>"; 
print "<body><center>"; 
print "<font size=4 face=Verdana><b>PHPMine v1.0</b>"; 
if ($submit=="") { 
 $NumMine=4; 
 $RowSize=5; 
 $ColSize=5; 
 $generer=1; 
} 
if ($generer==1) { 
 srand((double)microtime()*100000000); 
 $time_start=time(); 
 if (($RowSize<=1) || ($ColSize<=1) || ($NumMine==0)) { 
 print "<p><br><font size=-1 color=red>Wrong number for Rows, Cols or Mines!</font>"; 
 exit; 
 } 
 if ($NumMine > $RowSize*$ColSize) { 
 print "<p><br><font size=-1 color=red>Too many mines!</font>"; 
 exit; 
 } 
 
 for ($Row=1;$Row<=$RowSize;$Row++) { 
 for ($Col=1;$Col<=$ColSize;$Col++) { 
 $Mine[$Row][$Col]="0"; 
 $Decouv[$Row][$Col]="0"; 
 } 
 } 
 $index=0; 
 while ($index<$NumMine) { 
 $Row=rand(1,$RowSize); 
 $Col=rand(1,$ColSize); 
 if ($Mine[$Row][$Col]=="0") { 
 $Mine[$Row][$Col]="1"; 
 $index++; 
 } 
 } 
} else { 
 $perdu=0; 
 $reste=$RowSize*$ColSize; 
 for ($Row=1;$Row<=$RowSize;$Row++) { 
 for ($Col=1;$Col<=$ColSize;$Col++) { 
 $temp="Mine".($Row*($ColSize+1)+$Col); 
 $Mine[$Row][$Col]=$$temp; 
 $temp="Decouv".($Row*($ColSize+1)+$Col); 
 $Decouv[$Row][$Col]=$$temp; 
 if ($Decouv[$Row][$Col]=="1") {$reste=$reste-1;} 
 $temp="submit".($Row*($ColSize+1)+$Col); 
 if ($$temp=="ok") { 
 $reste=$reste-1; 
 if ($Mine[$Row][$Col]=="0") { 
 $Decouv[$Row][$Col]="1"; 
 } else { 
 $perdu=1; 
 } 
 } 
 } 
 } 
 if ($perdu==1) { 
 print "<h2>You Lose!</h2>"; 
 for ($i=1;$i<=$RowSize;$i++) { 
 for ($j=1;$j<=$ColSize;$j++) { 
 $Decouv[$i][$j]="1"; 
 } 
 } 
 } 
 if (($reste==$NumMine)&&($perdu!=1)) { 
 print "<h2>You Win!</h2>"; 
 $time_stop=time(); 
 $time=$time_stop-$time_start; 
 print "<p><font size=-1><i>Your score: $time</i></font>"; 
 
 for ($i=1;$i<=$RowSize;$i++) { 
 for ($j=1;$j<=$ColSize;$j++) { 
 $Decouv[$i][$j]="1"; 
 } 
 } 
 } 
} 
print "<form method=get action=\"$PHP_SELF\">"; 
print "<input type=hidden name=time_start value=$time_start>"; 
print "<input type=hidden name=NumMine value=$NumMine>"; 
print "<input type=hidden name=RowSize value=$RowSize>"; 
print "<input type=hidden name=ColSize value=$ColSize>"; 
print "<input type=hidden name=generer value=0>"; 
print "<p><table border=1 cellpadding=8>"; 
for ($Row=1; $Row<=$RowSize; $Row++) { 
 print "<tr>"; 
 for ($Col=1; $Col<=$ColSize; $Col++) { 
 $nb=0; 
 for ($i=-1; $i<=1; $i++) { 
 for ($j=-1; $j<=1; $j++) { 
 if ($Mine[$Row+$i][$Col+$j] == "1") { 
 $nb++; 
 } 
 } 
 } 
 print "<td width=15 height=15 align=center valign=middle>"; 
 if ($Decouv[$Row][$Col]=="1") { 
 if ($nb==0) { 
 print " "; 
 } else { 
 if ($Mine[$Row][$Col]=="1") { 
 print "*"; 
 } else { 
 print "$nb"; 
 } 
 } 
 } else { 
 print "<input type=hidden name=submit value=ok>"; 
 print "<input type=submit name=submit".($Row*($ColSize+1)+$Col)." value=ok>"; 
 } 
 print "<input type=hidden name=Mine".($Row*($ColSize+1)+$Col)." value=".$Mine[$Row][$Col].">"; 
 print "<input type=hidden name=Decouv".($Row*($ColSize+1)+$Col)." value=".$Decouv[$Row][$Col].">"; 
 print "</td>"; 
 } 
 print "</tr>"; 
} 
print "</table>"; 
print "</form>"; 
?> 
<hr> 
<form method=post> 
Rows :  <input type=text name=RowSize value=5 size=2> 
<br>Cols :  <input type=text name=ColSize value=5 size=2> 
<br>Mines :  <input type=text name=NumMine value=4 size=2> 
<p><input type=submit name=submit value=Generate> 
<input type=hidden name=generer value=1> 
</form> 
<p> 
<center><font size=-2>(c) 2000, <a href="http://www.phpvault.com">PHPVault</a> - All rights reserved<br>Script by <a href="mailto:perso@kidou.net">Kidou</a> 
</font> 
</center> 
</body> 
</html>


Other 13 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.