예제 #1
0
function checkMovesDriver($current_pos, $moves, $board, $count_moves)
{
    //echo "FUNCTION CALLED<br>";
    // if we've reached the end, the given board is already resulting board
    if ($count_moves - $current_pos < 2) {
        return $board;
    }
    //echo "INDEX: " . $current_pos . "<br>";
    // else, check if move is valid based on given board
    // if move is valid, update the board and check the next move
    // otherwise, return null;
    $temp_board = makeMove($moves[$current_pos], $moves[$current_pos + 1], $board);
    //echo "TEMP: " . $temp_board . "<br>";
    if ($temp_board != NULL) {
        $board = $temp_board;
        return checkMovesDriver($current_pos + 1, $moves, $board, $count_moves);
    } else {
        return NULL;
    }
}
예제 #2
0
파일: stratego.php 프로젝트: rwruss/ib3
function handleMessage($tst_msg, $userSocket)
{
    global $openGames;
    switch ($tst_msg->type) {
        case "message":
            $user_name = $tst_msg->name;
            //sender name
            $user_message = $tst_msg->message;
            //message text
            $user_color = $tst_msg->color;
            //color
            //prepare data to be sent to client
            $response_text = mask(json_encode(array('type' => 'usermsg', 'name' => $user_name, 'message' => $user_message, 'color' => $user_color)));
            send_message($response_text);
            //send data
            echo "User: "******"Send message " . $response_text . "<br>";
            break;
            //exist this loop
        //exist this loop
        case "move":
            makeMove($tst_msg->gameID, $tst_msg->playerID, $tst_msg->oldSpot, $tst_msg->newSpot);
            echo "process a move from user " . $userSocket . "\n";
            break;
        case "showOpenGames":
            echo "Show open games:\n";
            print_r($openGames);
            $response_text = mask(json_encode(array('type' => 'script', 'message' => 'showGames([' . implode(",", $openGames) . '])')));
            send_message($response_text);
            //send data
            break;
        case "startGame":
            startGame($tst_msg);
            //$response_text = mask(json_encode(array('type'=>'script', 'name'=>'nada', 'message'=>'console.log("recveive a script message")')));
            //send_message($response_text); //send data
            break;
        case "join":
            joinGame($tst_msg, $userSocket);
            break;
        case "newGame":
            createGame($tst_msg->playerID, $userSocket);
            break;
    }
}
예제 #3
0
파일: move.php 프로젝트: kperson/Connect4
<?php

require_once 'init.php';
header('Cache-Control: no-cache');
header('Content-Type: text/javascript');
$game_id = $_GET['game'];
$move_num = $_GET['moveNum'];
$col_num = $_GET['col'];
if (makeMove($_SESSION['member_id'], $game_id, $col_num)) {
    echo json_encode(array('stat' => 'ok'));
} else {
    echo json_encode(array('stat' => 'failure'));
}