Designing solutions through programming - May 25 Lesson Notes

From Computer Science Wiki
Revision as of 20:39, 24 May 2017 by Mr. MacKenty (talk | contribs) (Created page with " __NOTOC__ <table cellspacing="10" style="width:100%;"> <tr> <td style="width:50%; margin:0; margin-top:10px; margin-right:10px; border:1px solid #dfdfdf; padding:0 1em 1em 1...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Class plan.png 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;
    }

}


?>


Homework.png What is our homework?[edit]

  1. None

Target.png How am I being assessed today?[edit]

  1. You get a formative assessment today :-)

Ourstandards.png Standards we are covering today[edit]

Computer1.png As a computer scientist, you have:[edit]

  • Confidence in dealing with complexity
  • Persistence in working with difficult problems
  • Tolerance for ambiguity
  • The ability to deal with open-ended problems
  • The ability to communicate and work with others to achieve a common goal or solution

Credit.png Credits[edit]