Ejemplo n.º 1
0
function game_OnExportHTML_snakes($game, $html, $destdir)
{
    require_once "exporthtml_millionaire.php";
    global $CFG, $DB;
    if ($html->filename == '') {
        $html->filename = 'snakes';
    }
    $filename = $html->filename . '.htm';
    $ret = '';
    $board = game_snakes_get_board($game);
    if ($game->sourcemodule == 'quiz' or $game->sourcemodule == 'question') {
        $questionsM = game_millionaire_html_getquestions($game, $context, $maxquestions, $countofquestionsM, $retfeedback, $files);
    } else {
        $questionsM = array();
        $countofquestionsM = 0;
        $retfeedback = '';
    }
    $questionsS = game_exmportjavame_getanswers($game, false);
    ob_start();
    //Here is the code of hangman
    require "exporthtml_snakes.php";
    $output_string = ob_get_contents();
    ob_end_clean();
    $courseid = $game->course;
    $course = $DB->get_record('course', array('id' => $courseid));
    $filename = $html->filename . '.htm';
    file_put_contents($destdir . '/' . $filename, $ret . "\r\n" . $output_string);
    $src = $CFG->dirroot . '/mod/game/export/html/snakes';
    game_copyfiles($src, $destdir);
    mkdir($destdir . '/css');
    $src = $CFG->dirroot . '/mod/game/export/html/snakes/css';
    game_copyfiles($src, $destdir . '/css');
    mkdir($destdir . '/js');
    $src = $CFG->dirroot . '/mod/game/export/html/snakes/js';
    game_copyfiles($src, $destdir . '/js');
    mkdir($destdir . '/images');
    $destfile = $destdir . '/images/' . $board->fileboard;
    if ($game->param3 != 0) {
        //Is a standard board
        copy($board->imagesrc, $destfile);
    } else {
        $cmg = get_coursemodule_from_instance('game', $game->id, $game->course);
        $modcontext = get_context_instance(CONTEXT_MODULE, $cmg->id);
        $fs = get_file_storage();
        $files = $fs->get_area_files($modcontext->id, 'mod_game', 'snakes_board', $game->id);
        foreach ($files as $f) {
            if ($f->is_directory()) {
                continue;
            }
            break;
        }
        $f->copy_content_to($destfile);
    }
    $a = array('player1.png', 'dice1.png', 'dice2.png', 'dice3.png', 'dice4.png', 'dice5.png', 'dice6.png', 'numbers.png');
    foreach ($a as $file) {
        copy($CFG->dirroot . '/mod/game/snakes/1/' . $file, $destdir . '/images/' . $file);
    }
    $filezip = game_create_zip($destdir, $courseid, $html->filename . '.zip');
    game_send_stored_file($filezip);
}
Ejemplo n.º 2
0
function game_snakes_play($id, $game, $attempt, $snakes, $context)
{
    global $CFG, $DB, $OUTPUT;
    $board = game_snakes_get_board($game);
    $showboard = false;
    if ($snakes->position > $board->cols * $board->rows && $snakes->queryid != 0) {
        $finish = true;
        if (!($cm = $DB->get_record('course_modules', array('id' => $id)))) {
            print_error("Course Module ID was incorrect id={$id}");
        }
        echo '<B>' . get_string('win', 'game') . '</B><BR>';
        echo '<br>';
        echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id={$id}\">" . get_string('nextgame', 'game') . '</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
        echo "<a href=\"{$CFG->wwwroot}/course/view.php?id={$cm->course}\">" . get_string('finish', 'game') . '</a> ';
        $gradeattempt = 1;
        $finish = 1;
        game_updateattempts($game, $attempt, $gradeattempt, $finish);
    } else {
        $finish = false;
        if ($snakes->queryid == 0) {
            game_snakes_computenextquestion($game, $snakes, $query);
        } else {
            $query = $DB->get_record('game_queries', array('id' => $snakes->queryid));
        }
        if ($game->toptext != '') {
            echo $game->toptext . '<br>';
        }
        $showboard = true;
    }
    if ($showboard and $game->param8 == 0) {
        game_snakes_showquestion($id, $game, $snakes, $query, $context);
    }
    ?>
    <script language="javascript" event="onload" for="window">
    <!--    
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if( elements[ i].type == 'text'){
            elements[ i].focus();
            break;
        }
    }
    -->
    </script>

	<table>
	<tr>
		<td>

<div id="board" STYLE="position:relative; left:0px;top:0px; width:<?php 
    p($board->width);
    ?>
px; height:<?php 
    p($board->height);
    ?>
px;">
<img src="<?php 
    echo $board->imagesrc;
    ?>
"></img>
</div>

<?php 
    if ($finish == false) {
        game_snakes_showdice($snakes, $board);
    }
    ?>
		</td>
	</tr>
	</table>
<?php 
    if ($game->bottomtext != '') {
        echo '<br>' . $game->bottomtext;
    }
    if ($showboard and $game->param8 != 0) {
        game_snakes_showquestion($id, $game, $snakes, $query, $context);
    }
}