Beispiel #1
0
function play_with($self, $partner)
{
    include "inc/db.inc";
    /** check if my partner is ready **/
    if (partner_ready($self, $partner)) {
        /** create a new opponents entity or join existing one **/
        /** if the partner is already waiting, assume he has created the opponents-record, so we just join it **/
        $sql = "select oppid from users_opponents where uid = (select uid from users where username = '******') and active = 1";
        $oppid = mysql_result(mysql_query($sql, $mysql_access), 0);
        // if I was active in other opponents-records, set active there to 0
        $sql = "update users_opponents set active = 0 " . "where active = 1 and uid = (select uid from users where username = '******') and oppid != {$oppid}";
        mysql_query($sql, $mysql_access);
        // join the opponents-record
        $sql = "insert into users_opponents (oppid, uid) values ('{$oppid}', (select uid from users where username = '******')) ";
        mysql_query($sql, $mysql_access);
        /** now we can create a new game **/
        // check if there already exist an actual game with this oppid, if not - create new one and take its gameid
        $sql = "select gameid from games where oppid = '{$oppid}' and unix_timestamp(start_time) + timelimit > unix_timestamp(now())";
        $q = mysql_query($sql, $mysql_access);
        if (mysql_num_rows($q) > 0) {
            $gameid = mysql_result($q, 0);
        } else {
            $gameid = create_game($oppid);
        }
    } else {
        /** look if there exists oponents-record where I am the only active opponent **/
        $sql = "select oppid, count(*) as c from users_opponents where oppid in " . "(select oppid from users_opponents where active = 1 and uid = (select uid from users where username = '******')) " . "group by oppid having c = 1";
        $q = mysql_query($sql, $mysql_access);
        if (mysql_num_rows($q) > 0) {
            /** if yes, choose its oppid **/
            $oppid = mysql_result($q, 0);
        } else {
            /** if no, create a new one and take its oppid **/
            $sql = "insert into opponents (time_formed) values (now())";
            mysql_query($sql, $mysql_access);
            $oppid = mysql_insert_id();
        }
        // if I was active in other opponents-records, set active there to 0
        $sql = "update users_opponents set active = 0 " . "where active = 1 and uid = (select uid from users where username = '******') and oppid != {$oppid}";
        mysql_query($sql, $mysql_access);
        /** write to users_opponents: if already done, nothing changes, if new opponents, change oppid **/
        $sql = "insert into users_opponents (oppid, uid) values ('{$oppid}', (select uid from users where username = '******'))";
        mysql_query($sql, $mysql_access);
    }
}
Beispiel #2
0
<?php

before_action("check_entry", array("show", "skip", "turn", "daybook", "revert"), array("model_name" => "game"));
before_action("create_form", array("new", "create"), "new_game");
before_action("check_form", array("create"), "new_game");
before_action("create_form", array("show", "turn"), "turn");
before_action("check_form", array("turn"), "turn");
switch ($_GET["action"]) {
    case "index":
        break;
    case "new":
        break;
    case "create":
        define("game", create_game($_POST["identity"]));
        define("turn", -1);
        foreach ($_POST["cards_suspect"] as $suspect => $cards) {
            create_player($suspect, $cards);
        }
        foreach ($_POST["known_cards"] as $card) {
            add_card_owner_status($card, $_POST["identity"], owned);
        }
        foreach (select_suspects() as $player) {
            if (select_cards_player($player["id"]) == 0) {
                foreach (select_cards() as $card) {
                    add_card_owner_status($card["id"], $player["id"], not_owned);
                }
            }
        }
        $game["id"] = game;
        redirect_to_action("show");
        break;
function new_game($bot1, $bot2)
{
    // Shuffle the deck and deal two hands.
    $hands = deal();
    $hand1 = hand_to_array($hands[0]);
    $hand2 = hand_to_array($hands[1]);
    // Create the game.
    $game = create_game($bot1, $bot2, $hand1, $hand2);
    // Assign the game to both players.
    assign_game($game, $bot1, $hand1);
    assign_game($game, $bot2, $hand2);
}
    $opprating = $rat2rat;
} else {
    $myrating = $rat2rat;
    $opprating = $rat1rat;
}
if ($gi["{$firstmovemarkfield}"] == $ir['userid']) {
    $mymark = " {$person1mark}";
    $oppmark = " {$person2mark}";
} else {
    $mymark = " {$person2mark}";
    $oppmark = " {$person1mark}";
}
$vstxt = "<h3>{$ir['username']} ({$myrating} - {$mymark}) vs. {$opponent} ({$opprating} - {$oppmark})</h3>";
if ($ga['p1'] > 0 && $ga['p2'] > 0 && $gamerunning == 0) {
    //game not yet started
    create_game($ga['id']);
} else {
    if (($ga['p1'] > 0 && $ga['p2'] == 0 || $ga['p1'] == 0 && $ga['p2'] > 0) && $gamerunning == 1 && $ga['play_time'] != 0) {
        //game started, other player left, award win, unless no moves yet made
        if ($ga['p1'] > 0) {
            $winner = $ga['p1'];
        } else {
            $winner = $ga['p2'];
        }
        if ($gi['winner'] == 0) {
            award_win($roomid, $winner);
            $defaultwin = "Opponent left, so you won the game (along with any bets).";
        } else {
            $defaultwin = "Opponent left.";
        }
        set_up_replay($roomid, $winner, -1, $ga['bet']);
session_start();
require_once 'mysqli_connect.php';
include 'account_utils.php';
include 'constants.php';
if (!isset($_SESSION['login']) or !is_admin($dbc)) {
    header("Location: index.php");
    exit;
}
if (isset($_GET["week"])) {
    $week = $_GET['week'];
} else {
    $week = WEEK;
}
if (isset($_POST['new_game'])) {
    create_game($dbc, $week, $_POST['home'], $_POST['away']);
}
$query = "SELECT t.id, name, rank from teams t left join rankings r on t.id=r.team_id and r.week=" . $week . " order by r.rank IS NULL, r.rank, t.name";
$games = "SELECT g.id as 'game_id', home_team_id, away_team_id, h_rank.rank as 'h_rank', h.name as 'home', a.name as 'away', a_rank.rank as 'a_rank' FROM games g INNER JOIN teams h ON g.home_team_id = h.id INNER JOIN teams a ON g.away_team_id=a.id LEFT JOIN rankings h_rank ON h_rank.team_id=h.id AND h_rank.week=g.week LEFT JOIN rankings a_rank ON a_rank.team_id=a.id AND a_rank.week=g.week WHERE g.week=" . $week . " ORDER BY g.id";
$response = @mysqli_query($dbc, $query);
$games_response = @mysqli_query($dbc, $games);
if ($response and $games_response) {
    while ($row = mysqli_fetch_array($response)) {
        $name = $row['name'];
        $id = $row['id'];
        $rank = $row['rank'];
        if (!is_null($rank)) {
            $name = '#' . $rank . ' ' . $name;
        }
        $teams[$id] = $name;
    }
Beispiel #6
0
        $name = $_POST["tname"];
    }
    if (isset($_POST["ad_image"])) {
        $image = $_POST["ad_image"];
    }
    if (isset($_POST["info"])) {
        $info = $_POST["info"];
    }
    //insert
    //insert
    if (isset($_POST['game'])) {
        global $wpdb;
        $wpdb->insert($table1, array('name' => $name, 'image' => $image, 'info' => $info), array('%s', '%s', '%s'));
    }
}
create_game();
function create_tour()
{
    global $wpdb;
    $table1 = $wpdb->prefix . 'igtour';
    if (isset($_POST["tname"])) {
        $name = $_POST["tname"];
    }
    if (isset($_POST["info"])) {
        $info = $_POST["info"];
    }
    //insert
    if (isset($_POST['insert_tour'])) {
        global $wpdb;
        $wpdb->insert($table1, array('name' => $name, 'info' => $info), array('%s', '%s'));
    }
<?php

session_start();
require '../../app/Autoloader.class.php';
App\Autoloader::register();
$config = App\Config::getInstance();
$bdd = App\database\Database::getInstance_bdd($config->get("db_name"), $config->get("db_user"), $config->get("db_pass"), $config->get("db_host"));
require '../../functions/functions.php';
if (isset($_POST['name']) && isset($_POST['player1']) && isset($_POST['player2']) && $_POST['player1'] !== $_POST['player2']) {
    if ($id_game = create_game($bdd, $_POST['name'], '1', $_POST['player1'])) {
        if (add_player_in_game($bdd, $id_game, $_POST['player2'])) {
            for ($i = 0; $i < 10; $i++) {
                insert_into_map($bdd, $id_game, 'barrier', mt_rand(0, 150), mt_rand(0, 100), mt_rand(3, 15), mt_rand(3, 15), 0);
            }
            insert_into_map($bdd, $id_game, 'ship', 1, 1, 10, 8, $_POST['player1'], 1);
            insert_into_map($bdd, $id_game, 'ship', 141, 89, 10, 8, $_POST['player2'], 1);
            $_SESSION['alert'] = "Success";
            header("Location: ../index.php");
            die;
        } else {
            $_SESSION['alert'] = "Error";
            header("Location: ../index.php?pg=create_game");
            die;
        }
    } else {
        $_SESSION['alert'] = "Error";
        header("Location: ../index.php?pg=create_game");
        die;
    }
} else {
    $_SESSION['alert'] = "Error";