Created
November 7, 2012 23:43
-
-
Save gregbarcza/4035416 to your computer and use it in GitHub Desktop.
Php amőba gyakorló feladat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* | |
FELADAT LEÍRÁSA | |
Készíts egy egyszerü amőba programot. Rakni úgy lehessen hogy megadod az x illetve az y kordinátákat, illetve hogy milyen karaktert használ a játékos. Ezeket a program adatbázisban tárolja. | |
A játék "rajzolásához" használj táblázatot. | |
Minta URL: apps.dcw.hu/amoba/ | |
SQL: apps.dcw.hu/amoba/amoba.sql | |
* | |
*/ | |
$db_user="TOLTSD KI!"; | |
$db_jelszo="TOLTSD KI!"; | |
$db_name="TOLTSD KI!"; | |
$link = mysql_connect ('localhost', $db_user, $db_jelszo); | |
if (!$link) { | |
die('Nem tudok kapcsolódni az adatbázishoz'); | |
} | |
mysql_select_db($db_name); | |
mysql_query("SET NAMES utf8"); | |
mysql_query("SET CHARACTER SET utf8"); | |
if (isset($_GET['x']) AND isset($_GET['y']) AND isset($_GET['ertek'])) { | |
mysql_query("INSERT INTO `amoba` (`x` ,`y` ,`ertek` ,`reg`) | |
VALUES ('".$_GET['x']."', '".$_GET['y']."', '".$_GET['ertek']."',NOW())"); | |
} | |
?> | |
<html> | |
<style> | |
td{ | |
width:20px; | |
text-align: center; | |
} | |
td.red{ | |
color: red; | |
} | |
td.blue{ | |
color: blue; | |
} | |
</style> | |
<form action="" method="GET"> | |
<input name="x"> | |
<input name="y"> | |
<select name="ertek"> | |
<option>o</option> | |
<option>x</option> | |
</select> | |
<input type="submit"> | |
</form> | |
<table border='1'> | |
<?php | |
$result = mysql_query("SELECT * FROM amoba"); | |
$rakasok=array(); | |
while ($row = mysql_fetch_assoc($result)) { | |
$rakasok[]=$row; | |
} | |
for($i=1; $i<=10; $i++) { | |
echo "<tr>"; | |
for($j=1; $j<=10; $j++) { | |
$rak=FALSE; | |
foreach($rakasok as $rakas){ | |
if($rakas['x'] == $j AND $rakas['y'] == $i){ | |
if($rakas['ertek'] == "x"){ | |
echo '<td class="red">'.$rakas['ertek']."</td>"; | |
} | |
elseif($rakas['ertek'] == "o"){ | |
echo '<td class="blue">'.$rakas['ertek']."</td>"; | |
} | |
$rak=TRUE; | |
break; | |
} | |
} | |
if(!$rak){ | |
echo "<td> </td>"; | |
} | |
} | |
echo "</tr>"; | |
} | |
?> | |
</table> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment