예제 #1
0
 protected function check()
 {
     $this->poker1 = new CardsPoker(explode(",", $this->data['poker_starter_cards']));
     $this->solve1 = $this->poker1->solve();
     $this->text1 = $this->poker1->solve_text($this->solve1);
     $cards = $this->data['poker_challenger_cards'] ? explode(",", $this->data['poker_challenger_cards']) : null;
     $this->poker2 = new CardsPoker($cards);
     $this->poker2->remove_cards($this->poker1->get_cards());
     if ($cards) {
         $this->solve2 = $this->poker2->solve();
         $this->text2 = $this->poker2->solve_text($this->solve2);
     }
     // gått ut på tid?
     if ($this->data['poker_state'] == self::STATE_CHALLENGE && $this->data['poker_time_challenge'] <= time() - self::MAX_CHALLENGE_TIME) {
         $this->auto_play();
     }
 }
예제 #2
0
    // hent nye kort
    if (count($replace) > 0) {
        $poker->new_cards($replace);
    }
    $status->update("cards", implode(",", $poker->get_cards()));
    $status->update("cards_used", implode(",", array_unique(array_merge(explode(",", $status->get("cards_used")), $poker->get_cards()))));
    $status->update("finish", 1);
    login::$user->player->oppdrag->update_status($oppdrag['o_id'], $status);
    redirect::handle();
}
// ferdig?
$success = false;
if ($finish) {
    $poker = new CardsPoker(explode(",", $cards));
    $poker_pc = new CardsPoker(explode(",", $status->get("cards_pc")));
    $poker_pc->remove_cards(explode(",", $status->get("cards_used")));
    // spill for pcen
    $poker_pc->play();
    $solve = $poker->solve();
    $solve_pc = $poker_pc->solve();
    // hvem vant?
    $won = CardsPoker::compare($solve, $solve_pc);
    if ($won[0] == 1) {
        // brukeren vant -- gi tilbake nye chips
        $chips = $chips + $status->get("bet");
    } elseif ($won[0] == 2) {
        // pcen vant -- trekk fra chips
        $chips = $chips - $status->get("bet");
    }
    $status->update("chips", $chips);
    $cards = false;
예제 #3
0
파일: poker.php 프로젝트: Kuzat/kofradia
 /**
  * Utfordre en spiller
  */
 protected function challenge()
 {
     if (!isset($_POST['utfordre']) || !isset($_POST['id'])) {
         return;
     }
     // finn utfordringen
     $id = (int) $_POST['id'];
     $result = \Kofradia\DB::get()->query("\n\t\t\tSELECT poker_id, poker_starter_up_id, poker_starter_cards, poker_time_start, poker_cash\n\t\t\tFROM poker\n\t\t\tWHERE poker_id = {$id} AND poker_state = 2 AND poker_starter_up_id != " . $this->up->id);
     $row = $result->fetch();
     if (!$row) {
         ess::$b->page->add_message("Fant ikke utfordringen. Noen kan ha kommet før deg!", "error");
         redirect::handle();
     }
     // ikke råd?
     if (bccomp($row['poker_cash'], $this->up->data['up_cash']) == 1) {
         ess::$b->page->add_message("Du har ikke så mye penger på hånda.", "error");
         redirect::handle();
     }
     // nostatuser?
     if (bccomp($row['poker_cash'], 10000) == 1 && MAIN_SERVER && (access::is_nostat() && $this->up->data['up_u_id'] != 1)) {
         ess::$b->page->add_message("Nostat kan ikke spille poker med beløp over 10 000 kr.", "error");
         redirect::handle();
     }
     // sett opp pokerhånd
     $poker1 = new CardsPoker(explode(",", $row['poker_starter_cards']));
     $poker2 = new CardsPoker();
     $poker2->remove_cards($poker1->get_cards());
     $poker2->new_cards(5);
     // oppdater utfordringen
     $a = \Kofradia\DB::get()->exec("UPDATE poker SET poker_state = 3, poker_challenger_up_id = " . $this->up->id . ", poker_challenger_cards = '" . implode(",", $poker2->get_cards()) . "', poker_time_challenge = '" . time() . "' WHERE poker_id = {$row['poker_id']} AND poker_state = 2");
     if ($a == 0) {
         ess::$b->page->add_message("Fant ikke utfordringen. Noen kan ha kommet før deg!", "error");
         redirect::handle();
     }
     // trekk fra pengene fra brukeren
     $a = \Kofradia\DB::get()->exec("UPDATE users_players SET up_cash = up_cash - {$row['poker_cash']} WHERE up_id = " . $this->up->id . " AND up_cash >= {$row['poker_cash']}");
     // ble ikke brukeren oppdatert?
     if ($a == 0) {
         ess::$b->page->add_message("Du har ikke så mye penger på hånda.", "error");
         // fjern challenge
         \Kofradia\DB::get()->exec("UPDATE poker SET poker_state = 2, poker_challenger_up_id = 0, poker_challenger_cards = '', poker_time_challenge = 0 WHERE poker_id = {$row['poker_id']}");
         redirect::handle();
     }
     poker_round::update_cache();
     redirect::handle();
 }