Exemplo n.º 1
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);
    }
}
Exemplo n.º 2
0
function game_snakes_play($id, $game, $attempt, $snakes)
{
    global $CFG, $DB;
    $board = $DB->get_record('game_snakes_database', array('id' => $snakes->snakesdatabaseid));
    if ($board == false) {
        require_once dirname(__FILE__) . '/../db/importsnakes.php';
        $board = $DB->get_record('game_snakes_database', array('id' => $snakes->snakesdatabaseid));
    }
    if ($board == false) {
        print_error('No board');
    }
    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('snakes_win', 'game') . '</B><BR>';
        echo '<br>';
        echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id={$id}\">" . get_string('snakes_new', '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>';
        }
        game_snakes_showquestion($id, $game, $snakes, $query);
    }
    ?>
    <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;">
<b><center><img src="snakes/boards/<?php 
    p($board->fileboard);
    ?>
"></img></center>
</DIV>

<?php 
    if ($finish == false) {
        game_snakes_showdice($snakes, $board);
    }
    ?>
		</td>
	</tr>
	</table>
<?php 
    if ($game->bottomtext != '') {
        echo '<br>' . $game->bottomtext;
    }
}