"; // let o == cat $o = "pic of cat"; if (($rows >= 4) && ($columns >= 4)) { $this->rows = $rows; $this->columns = $columns; } else { $this->rows = 6; $this->columns = 7; } if ($s_layout) { $this->layout = unserialize($s_layout); } else { for($i = 0; $i < $rows; $i++) { for($j = 0; $j < $columns; $j++) { $tmp[$j] = ' '; } $this->layout[] = $tmp; } /* $this->layout = array ( array (' ', ' ', ' ',' ', ' ', ' ',' '), array (' ', ' ', ' ',' ', ' ', ' ',' '), array (' ', ' ', ' ',' ', ' ', ' ',' '), array (' ', ' ', ' ',' ', ' ', ' ',' '), array (' ', ' ', ' ',' ', ' ', ' ',' '), array (' ', ' ', ' ',' ', ' ', ' ',' '), ); */ /* $this->layout = array ( array (" ", " ", " "," ", " ", " ", " "), array (" ", " ", " "," ", " ", " ", " "), array (" ", " ", " "," ", " ", " ", " "), array (" ", " ", " "," ", " ", " ", " "), array (" ", " ", "$o"," ", "$x", "$o", " "), array (" ", "$x", "$x","$o", "$o", "$x", "$o"), ); */ } } function pick_first() { $i = rand(0,1); if ($i == 0) { $this->turn = 'cat'; } if ($i == 1) { $this->turn = 'dog'; } } function print_layout() { prethis($this->layout); } function update() { // update array $column = (int) $_POST["{$_POST['s_turn']}_move"]; // put at bottom of array $i_key = $this->rows - 1; // number of rows $i_sent = 1; while ($i_sent > 0) { if ($this->layout[$i_key][$column] == ' ') { $this->layout[$i_key][$column] = "pic of {$_POST[\n"; $i_sent = 0; } if ($i_key == 0) { $i_sent = 0; } $i_key--; } if ($_POST['s_turn'] == 'dog') { $this->turn = 'cat'; } if ($_POST['s_turn'] == 'cat') { $this->turn = 'dog'; } } function display() { $columns = $this->columns; // $s_display .= "rows: {$this->rows} columns: {$this->columns}
\n"; $s_display .= "\n"; $s_display .= "\n"; for ($i = 0; $i < $columns; $i++) { $s_display .= "\n"; } $s_display .= "\n"; foreach($this->layout as $row) { $s_display .= "\n"; foreach($row as $item) { $s_display .= "\n"; } $s_display .= "\n"; } $s_display .= "
"; if (IsColumnFilled($this->rows, $i, $this->layout)) { $s_display .= "pic of {$this->turn}"; } else { $s_display .= ""; } // $s_display .= "(" . ($this->layout[$i]) . ")\n"; $s_display .= "
\n"; $s_display .= $item; $s_display .= "
\n"; return $s_display; } } function IsColumnFilled($rows, $column, $a_set) { if (!is_int($column)) { return false; } $i_filled = 0; foreach($a_set as $row) { $i = 0; foreach ($row as $item) { if ($i == $column) { if (strcmp($item, ' ') != 0) { $i_filled++; } } $i++; } } if ($i_filled == $rows) { return true; } return false; } ?>