/** * valid game * @param null $size * @param $matrix * @param $items_string */ public static function hwdoku_valid_game($size, $matrix, $items_string) { #$size = self::getSize(); //get sudoku size $matrix = unserialize($matrix); #$items_string=$_GET['items_string']; $items = explode(',', $items_string); $game1 = new HQ_Sudoku($size); $game1->grid = $matrix; $valid = 1; foreach ($items as $v) { $item = explode(':', $v); $ij = explode('-', $item[0]); $game1->set_item($ij[0], $ij[1], $item[1]); } foreach ($items as $v) { $item = explode(':', $v); $ij = explode('-', $item[0]); if (!$game1->valid_item($ij[0], $ij[1], $item[1])) { $valid = 0; break; } } echo '<textarea>' . $valid . '</textarea>'; }
} ?> </select> <input type='submit' class="hw-button" onclick="" value='<?php _e('Reset', 'hwdoku'); ?> '/> <a class='hw-button' href='javascript:void(0)' onclick="hw_game.suggest_item()"><?php _e('>> Suggest Me', 'hwdoku'); ?> </a> </form> </div> <?php $game = new HQ_Sudoku($size); $game->init(); $game_grid = serialize($game->show_game(true, 'grid')); ?> <textarea id='matrix_string' style='visibility:hidden;'><?php echo $game_grid; ?> </textarea> <script> <?php if (isset($game)) { ?> var hw_game = new HW_Sudoku({ 'enabled_valid' : <?php
/** * 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; }