/** * check item * @param string $size * @param string $matrix */ public static function hwdoku_check_item($size, $matrix) { global $wpdb; if (empty($size)) { $size = self::getSize(); } //get sudoku size $matrix = unserialize($matrix); $i = $_GET['i']; $j = $_GET['j']; $a = $_GET['a']; #echo $size; $game1 = new HQ_Sudoku($size); $game1->grid = $matrix; $valid = $game1->valid_item($i, $j, $a); if ($valid) { $game1->set_item($i, $j, $a); //save to db try { $exists = $wpdb->get_var('select count(*) from ' . HWDOKU_DB_TABLE); if (!$exists) { $wpdb->insert(HWDOKU_DB_TABLE, array('grid' => $game1->matrix_string())); } else { $query = $wpdb->prepare("UPDATE " . HWDOKU_DB_TABLE . " SET grid = %s LIMIT 1", $game1->matrix_string()); $wpdb->query($query); } } catch (Exception $err) { } //$db->query("update sudoku set grid='".$game1->matrix_string()."'"); echo '<textarea>' . $game1->matrix_string() . ($game1->is_full_matrix() ? '[DONE]' : '') . '</textarea>'; echo '<script>hwdoku_debug("' . valid_str_in_str($game1->suggest_result(false, 'ok')) . '");</script>'; exit; } else { //out1($i.'-'.$j); $game1->remove_item($i, $j); echo '<textarea>' . $game1->matrix_string() . '[FALSE]</textarea>'; #exit(); } }
/** * Hiển thị trò chơi * @param $opt1 * @param $opt2 */ public function show_game($opt1 = true, $opt2 = 'miss_items') { $view = '<table class="table" id="sudoku" border="1px solid gray" cellspadding=0 cellspacing=0 class="hwdoku-view">'; $items_hidden = ''; for ($i = 0; $i < $this->size; $i++) { $hide = pick_rand_more(0, $this->size - 1, pick_rand_number(1, $this->size - 1)); $tr = '<tr >'; for ($j = 0; $j < $this->size; $j++) { if (in_array($j, $hide)) { $items_hidden .= $i . '-' . $j . ','; $str = '<input onclick="hw_game.focus_item(this)" onBlur="hw_game._input_item_event(this)" class="hwdoku-hide" pos="' . $i . '-' . $j . '" value=""/>'; //$this->grid[$i][$j] } else { $str = $this->grid[$i][$j]; } $tr .= '<td width="50">' . $str . '</td>'; } $tr .= '</tr>'; $view .= $tr; } $view .= '</table>'; if ($opt1 == true) { echo $view; } $game1 = new HQ_Sudoku($this->size); $game1->grid = $this->grid; $game1->remove_item(explode(',', $items_hidden)); return $opt2 == 'miss_items' ? substr($items_hidden, 0, strlen($items_hidden) - 1) : $game1->grid; }