Designing solutions through programming - May 25 Lesson Notes
What are we going to learn today?[edit]<?php
// This progam creates and prints a simple grid
// initialize the array
$grid = [];
// populate the array:
for($i=0;$i<300;$i++){
$new_number = rand(1,3);
if($new_number == 2 || $new_number ==3){
$new_number = rand(1,3);
}
$grid[] = $new_number;
}
// print the array so it looks like a grid
echo "<!doctype html>";
echo "<html>";
echo "<meta charset=\"utf-8\"/>";
echo "<style>
body { font-family: \"courier\"; }</style>";
$count = 0;
$row_length = 20;
$player_location = 50;
$grid[$player_location] = 4;
foreach($grid as $i) {
$count = $count + 1;
if($i==1){
echo " . ";
} elseif($i==2) {
echo "<font color=\"green\"> \u{1F332} </font>";
} elseif($i==3) {
echo "<font color=\"red\"> \u{26F0} </font>";
} elseif($i == 4) {
echo " \u{1F464} ";
}
if($count == $row_length) {
echo "<br />";
$count = 0;
}
}
$count_terrain_features = array_count_values($grid);
echo "<br /><hr /><br />";
echo "There are $count_terrain_features[1] open terrain tiles on this map<br />";
echo "There are $count_terrain_features[2] trees tiles on this map.<br />";
echo "There are $count_terrain_features[3] mountain tiles on this map<br />";
echo "<br /><hr /><br />";
// print_r($count_terrain_features);
// we now just draw the numbers to help map designers understand the numbers :-)
$count = 0;
foreach($grid as $i){
$count= $count+1;
echo " $i ";
if($count == $row_length){
echo "<br />";
$count =0;
}
}
echo "<br /><hr /><br />";
$count =0;
$position = 0;
foreach($grid as $i){
$count++;
$position ++;
echo str_pad($position,4,".",STR_PAD_BOTH);
if($count == $row_length) {
echo "<br />";
$count = 0;
}
}
?>
|
What is our homework?[edit]
|
|
How am I being assessed today?[edit]
|
||
Standards we are covering today[edit] |
As a computer scientist, you have:[edit]
|
|
Credits[edit] |