function make_move($move, $userid, $roomid) { $move--; if (!is_numeric($move)) { die; } global $db, $ir; $game = $db->query("SELECT * FROM bs_room WHERE id={$roomid}", $c) or die("1"); $ga = $db->fetch_row($game); $turn = $ga['turn']; if ($turn == $userid) { $ginfo = $db->query("SELECT * FROM bs_game WHERE bs_room={$roomid}"); $gin = $db->fetch_row($ginfo); if ($gin['p1'] == $userid) { $oppboard = explode('|', $gin['p2b']); $icoppboard = explode('|', $gin['p1bo']); $boardfield = "p1bo"; } else { if ($gin['p2'] == $userid) { $oppboard = explode('|', $gin['p1b']); $icoppboard = explode('|', $gin['p2bo']); $boardfield = "p2bo"; } } if ($icoppboard[$move] == 0) { if ($oppboard[$move] == 0 && ctype_digit($oppboard[$move])) { $oppboard[$move] = -1; } $icoppboard[$move] = $oppboard[$move]; $uicoppboard = implode("|", $icoppboard); $db->query("UPDATE bs_game SET {$boardfield} = '{$uicoppboard}' WHERE bs_room = {$roomid}"); $db->query("UPDATE bs_room SET play_time=unix_timestamp() WHERE id={$roomid}"); $winner = check_win($roomid); if ($winner != 0) { award_win($roomid, $winner); } else { toggle_turn($roomid); } //only toggle turn if no win yet } } }
function make_move($move, $userid, $roomid) { global $db, $ir; $game = $db->query("SELECT * FROM ttt_room WHERE id={$roomid}", $c) or die("1"); $ga = $db->fetch_row($game); $turn = $ga['turn']; if ($turn == $userid) { $ginfo = $db->query("SELECT * FROM ttt_game WHERE ttt_room={$roomid}"); $gin = $db->fetch_row($ginfo); $field = "b" . $move; if ($gin[$field] == 0) { $ctime = time(); $db->query("UPDATE ttt_game SET {$field} = {$userid} WHERE ttt_room = {$roomid}"); $db->query("UPDATE ttt_room SET play_time=unix_timestamp() WHERE id={$roomid}"); $winner = check_win($roomid); if ($winner != 0) { award_win($roomid, $winner); } else { toggle_turn($roomid); } //only toggle turn if no win yet } } }
function make_move($move, $userid, $roomid) { global $db, $ir; $game = $db->query("SELECT * FROM man_room WHERE id={$roomid}", $c) or die("1"); $ga = $db->fetch_row($game); $turn = $ga['turn']; if ($turn == $userid) { $ginfo = $db->query("SELECT * FROM man_game WHERE man_room={$roomid}"); $gin = $db->fetch_row($ginfo); $movefrom = "b" . $move; //make sure square is not empty if ($gin["{$movefrom}"] > 0) { //make sure square is on their side of the board if ($gin['bottom'] == $userid && $move > 0 && $move < 7 or $gin['bottom'] != $userid && $move > 7 && move < 14) { $totstones = $gin["{$movefrom}"]; $gin["{$movefrom}"] = 0; $spot = ($move + 1) % 14; while ($totstones > 0) { if ($spot != 7 && $spot != 0 || ($spot == 7 && $gin['bottom'] == $userid || $spot == 0 && $gin['bottom'] != $userid)) { $totstones--; $gin["b" . $spot] += 1; $finalspot = $spot; $spot++; } if ($spot == 7 && $gin['bottom'] != $userid || $spot == 0 && $gin['bottom'] == $userid) { $spot++; } $spot = $spot % 14; } if ($finalspot == 0 || $finalspot == 7) { $notoggle = 1; } if ($gin["b" . $finalspot] == 1 && $finalspot != 0 && $finalspot != 7) { $oppspot = get_opp($finalspot); if ($gin["b" . $oppspot] > 0) { //only if on your side of the board if ($finalspot > 0 && $finalspot < 7 && $gin['bottom'] == $userid || $finalspot > 7 && $finalspot < 14 && $gin['bottom'] != $userid) { $wonstones = 1 + $gin["b" . $oppspot]; if ($gin['bottom'] == $userid) { $gin['b7'] += $wonstones; } if ($gin['bottom'] != $userid) { $gin['b0'] += $wonstones; } $gin["b" . $oppspot] = 0; $gin["b" . $finalspot] = 0; } } } $db->query("UPDATE man_game SET b0={$gin['b0']},b1={$gin['b1']},b2={$gin['b2']},b3={$gin['b3']},b4={$gin['b4']},b5={$gin['b5']},b6={$gin['b6']},b7={$gin['b7']},b8={$gin['b8']},b9={$gin['b9']},b10={$gin['b10']},b11={$gin['b11']},b12={$gin['b12']},b13={$gin['b13']} WHERE man_room={$roomid}"); $db->query("UPDATE man_room SET play_time=unix_timestamp() WHERE id={$roomid}"); $winner = check_win($roomid); if ($winner != 0) { award_win($roomid, $winner); } else { if (!$notoggle) { toggle_turn($roomid); } } } } } }
function end_turn($userid, $roomid) { global $db, $ir; $ui = $db->fetch_row($db->query("SELECT p1,p2,turn FROM or_room WHERE id = {$roomid}")); if ($ui['turn'] == $userid) { toggle_turn($roomid); } }
function toggle_turn($roomid) { global $db, $ir; $ui = $db->fetch_row($db->query("SELECT p1,p2,turn FROM or_room WHERE id = {$roomid}")); if ($ui['turn'] == $ui['p1']) { $db->query("UPDATE or_room SET notifyturn=0,play_time=unix_timestamp(),turn={$ui['p2']} WHERE id={$roomid}"); $availablemoves = get_available_moves($roomid, $ui['p2']); $anyavail = count($availablemoves); if ($anyavail == 0) { $uname = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$ui['p2']}")); $_POST['chattxt'] = "{$uname['username']} has no legal moves and passed their turn."; $db->query("INSERT INTO or_chat (or_room, timestamp, txt) VALUES({$roomid}, unix_timestamp(), '{$_POST['chattxt']}')"); toggle_turn($roomid); //only toggle turn if no win yet } } else { $db->query("UPDATE or_room SET notifyturn=0,play_time=unix_timestamp(),turn={$ui['p1']} WHERE id={$roomid}"); $availablemoves = get_available_moves($roomid, $ui['p1']); $anyavail = count($availablemoves); if ($anyavail == 0) { $uname = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$ui['p1']}")); $_POST['chattxt'] = "{$uname['username']} has no legal moves and passed their turn."; $db->query("INSERT INTO or_chat (or_room, timestamp, txt) VALUES({$roomid}, unix_timestamp(), '{$_POST['chattxt']}')"); toggle_turn($roomid); //only toggle turn if no win yet } } }
if ($username) { //Check the clock - 35 seconds per move //UPDATE - now time is a variable amount set by user $turntime = $ga['time_left']; if ($turntime < 35) { $turntime = 35; } $lastmove = $ga['play_time']; $ctime = time(); $timespent = $ctime - $lastmove; $timeleft = $turntime - $timespent; if ($timeleft <= 0) { $movelist = move_list(0, 0, $gi['listofmoves'], $gi['posa'], 0, 0); $db->query("UPDATE st_game SET listofmoves = '{$movelist}' WHERE st_room={$roomid}"); //lost their turn toggle_turn($roomid); $txt = "{$username} ran out of time and lost his/her move."; $db->query("INSERT INTO {$gpre}chat ({$gpre}room, timestamp, txt) VALUES({$roomid}, unix_timestamp(), '{$txt}')"); if ($ga['turn'] == $ga['p1']) { $missfield = "p1missed"; $missuserid = $ga['p1']; } if ($ga['turn'] == $ga['p2']) { $missfield = "p2missed"; $missuserid = $ga['p2']; } if ($ga["{$missfield}"] >= 2) { $db->query("UPDATE {$gpre}room SET p1missed=0,p2missed=0,pleft={$missuserid} WHERE id={$roomid}"); $db->query("UPDATE users SET {$gpre}room=0 WHERE userid={$missuserid}", $c); $db->query("UPDATE {$gpre}room SET p1=0 WHERE p1={$missuserid}", $c); $db->query("UPDATE {$gpre}room SET p2=0 WHERE p2={$missuserid}", $c);
function end_turn($userid, $roomid) { global $db, $ir; $ui = $db->fetch_row($db->query("SELECT p1,p2,turn FROM bg_room WHERE id = {$roomid}")); if ($ui['turn'] == $userid) { $db->query("UPDATE bg_game SET d1=0,d2=0,d3=0,d4=0,dselected=0 WHERE bg_room={$roomid}"); toggle_turn($roomid); } }
function make_move($move, $userid, $roomid) { global $db, $ir; $game = $db->query("SELECT * FROM st_room WHERE id={$roomid}", $c) or die("1"); $ga = $db->fetch_row($game); $game2 = $db->query("SELECT * FROM st_game WHERE st_room={$roomid}", $c) or die("1"); $gijoe = $db->fetch_row($game2); $turn = $ga['turn']; $red = $gijoe['red']; if ($gijoe['p1'] == $red) { $blue = $gijoe['p2']; } else { $blue = $gijoe['p1']; } $pselect = $gijoe['pselected']; $uname = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$userid}")); $attackersusername = $uname['username']; if ($userid == $red) { $uname = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$blue}")); } else { $uname = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$red}")); } $defendersusername = $uname['username']; if ($turn == $userid) { if ($userid == $red) { $loc = "a"; $antiloc = "b"; } else { $loc = "b"; $antiloc = "a"; } if ($pselect == $move) { $db->query("UPDATE st_game SET pselected = 0 WHERE st_room={$roomid}"); die; } //deselect their piece if ($gijoe[$loc . $move] != 0) { $db->query("UPDATE st_game SET pselected = {$move} WHERE st_room={$roomid}"); die; } //basic moves //pselect working and deselect working basic moves so normal pieces can move. $piecetomove = $gijoe[$loc . $pselect]; //out of bounds if ($move == 56 || $move == 46 || $move == 53 || $move == 43) { die; } if ($move < 11 || $move > 88 || $move == 19 || $move == 29 || $move == 39 || $move == 49 || $move == 59 || $move == 69 || $move == 79) { die; } //movement of linear pieces if (abs($piecetomove) > 0 && abs($piecetomove) < 7 || abs($piecetomove) == 8) { if ($gijoe[$antiloc . $move] != 0) { //if the oppent has a piece there ATTACK if (valid_move($pselect, $move) == 1) { $piece1 = $gijoe[$loc . $pselect]; //attacker $piece2 = $gijoe[$antiloc . $move]; //defender if (attack_piece(abs($piece1), abs($piece2)) == 2) { $startingspot = $loc . $pselect; //start spot $finishingspot = $loc . $move; //finishing spot $revealedpiece = "-" . abs($gijoe[$startingspot]); // reveal the piece $opponentsspot = $antiloc . $move; // losers spot $Attackname = number_to_name(abs($piece1)); // name of attackers piece $Defendname = number_to_name(abs($piece2)); // name of defenders piece $text = $attackersusername . "\\'s " . $Attackname . " (" . abs($piece1) . ") killed " . $defendersusername . "\\'s " . $Defendname . " (" . abs($piece2) . ")"; $piecelost = "p" . $loc . abs($piece2); //piece captured $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$startingspot} = 0, {$finishingspot} = {$revealedpiece}, {$opponentsspot} = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}"); toggle_turn($roomid); } else { if (attack_piece(abs($piece1), abs($piece2)) == 1) { $startingspot = $loc . $pselect; $finishingspot = $antiloc . $move; $piecesname = number_to_name(abs($piece1)); // name of the two pieces $text = "Both " . $piecesname . "\\'s (" . abs($piece1) . ") were killed"; $piecelost = "p" . $loc . abs($piece2); // piece captured $piecelost2 = "p" . $antiloc . abs($piece1); //piece lost $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$piecelost2} = {$piecelost2} +1,{$startingspot} = 0, {$finishingspot} = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}"); toggle_turn($roomid); } else { if (attack_piece(abs($piece1), abs($piece2)) == 3) { $winningpiece = number_to_name(abs($piece1)); // name of the two pieces $text = $attackersusername . "\\'s " . $winnpiece . " (" . abs($piece1) . ") captured the flag"; $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', battletxt = '{$text}' WHERE st_room={$roomid}"); award_win($roomid, $userid); } else { $Attackname = number_to_name(abs($piece1)); // name of attackers piece $Defendname = number_to_name(abs($piece2)); // name of defenders piece $text = $attackersusername . "\\'s " . $Attackname . " (" . abs($piece1) . ") lost to " . $defendersusername . "\\'s " . $Defendname . " (" . abs($piece2) . ")"; $startingspot = $loc . $pselect; $finishingspot = $antiloc . $move; $revealedpiece = "-" . abs($gijoe[$finishingspot]); $piecelost = "p" . $antiloc . abs($piece1); $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$startingspot} = 0, {$finishingspot} = {$revealedpiece}, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}"); toggle_turn($roomid); } } } } } else { if ($gijoe[$loc . $move] == 0) { if (valid_move($pselect, $move) == 1) { $startingspot = $loc . $pselect; $finishingspot = $loc . $move; $piecetomove = $gijoe[$startingspot]; $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$startingspot} = 0, {$finishingspot} = {$piecetomove}, pselected = 0, lastmove = {$move}, battletxt = '' WHERE st_room={$roomid}"); toggle_turn($roomid); } } } } //movement of scout if (abs($piecetomove) == 7) { if ($gijoe[$antiloc . $move] != 0) { //if the oppent has a piece there ATTACK $scoutresults = array(); $scoutresults = valid_scout($pselect, $move); $differenceofspots = $scoutresults['distance']; $direction = $scoutresults['direction']; if ($differenceofspots > 0) { $openspots = 1; for ($i = 1; $i < $differenceofspots; $i++) { if ($direction == 4) { $checklake = $pselect + $i; if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) { $openspots = 0; } $temp1 = $loc . ($pselect + $i); $temp2 = $antiloc . ($pselect + $i); $openplayer = $gijoe[$temp1]; $openopponent = $gijoe[$temp2]; if ($openplayer != 0 || $openopponent != 0) { $openspots = 0; } } if ($direction == 3) { $checklake = $pselect - $i; if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) { $openspots = 0; } $temp1 = $loc . ($pselect - $i); $temp2 = $antiloc . ($pselect - $i); $openplayer = $gijoe[$temp1]; $openopponent = $gijoe[$temp2]; if ($openplayer != 0 || $openopponent != 0) { $openspots = 0; } } if ($direction == 2) { $movevalue = $i . "0"; $checklake = $pselect - $movevalue; if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) { $openspots = 0; } $temp1 = $loc . ($pselect - $movevalue); $temp2 = $antiloc . ($pselect - $movevalue); $openplayer = $gijoe[$temp1]; $openopponent = $gijoe[$temp2]; if ($openplayer != 0 || $openopponent != 0) { $openspots = 0; } } if ($direction == 1) { $movevalue = $i . "0"; $checklake = $pselect + $movevalue; if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) { $openspots = 0; } $temp1 = $loc . ($pselect + $movevalue); $temp2 = $antiloc . ($pselect + $movevalue); $openplayer = $gijoe[$temp1]; $openopponent = $gijoe[$temp2]; if ($openplayer != 0 || $openopponent != 0) { $openspots = 0; } } } if ($openspots == 1) { $piece1 = $gijoe[$loc . $pselect]; //attacker $piece2 = $gijoe[$antiloc . $move]; //defender if (attack_piece(abs($piece1), abs($piece2)) == 2) { $startingspot = $loc . $pselect; //start spot $finishingspot = $loc . $move; //finishing spot $revealedpiece = "-" . abs($gijoe[$startingspot]); // reveal the piece $opponentsspot = $antiloc . $move; // losers spot $Attackname = number_to_name(abs($piece1)); // name of attackers piece $Defendname = number_to_name(abs($piece2)); // name of defenders piece $text = $attackersusername . "\\'s " . $Attackname . " (" . abs($piece1) . ") killed " . $defendersusername . "\\'s " . $Defendname . " (" . abs($piece2) . ")"; $piecelost = "p" . $loc . abs($piece2); //piece captured $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$startingspot} = 0, {$finishingspot} = {$revealedpiece}, {$opponentsspot} = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}"); toggle_turn($roomid); } else { if (attack_piece(abs($piece1), abs($piece2)) == 1) { $startingspot = $loc . $pselect; $finishingspot = $antiloc . $move; $piecesname = number_to_name(abs($piece1)); // name of the two pieces $text = "Both " . $piecesname . "\\'s (" . abs($piece1) . ") were killed"; $piecelost = "p" . $loc . abs($piece2); // piece captured $piecelost2 = "p" . $antiloc . abs($piece1); //piece lost $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$piecelost2} = {$piecelost2} +1,{$startingspot} = 0, {$finishingspot} = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}"); toggle_turn($roomid); } else { if (attack_piece(abs($piece1), abs($piece2)) == 3) { $winningpiece = number_to_name(abs($piece1)); // name of the two pieces $text = $attackersusername . "\\'s " . $Attackname . "captured the flag"; $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', battletxt = '{$text}' WHERE st_room={$roomid}"); award_win($roomid, $userid); } else { $Attackname = number_to_name(abs($piece1)); // name of attackers piece $Defendname = number_to_name(abs($piece2)); // name of defenders piece $text = $attackersusername . "\\'s " . $Attackname . " (" . abs($piece1) . ") lost to " . $defendersusername . "\\'s " . $Defendname . " (" . abs($piece2) . ")"; $startingspot = $loc . $pselect; $finishingspot = $antiloc . $move; $revealedpiece = "-" . abs($gijoe[$finishingspot]); $piecelost = "p" . $antiloc . abs($piece1); $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$piecelost} = {$piecelost} +1,{$startingspot} = 0, {$finishingspot} = {$revealedpiece}, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}"); toggle_turn($roomid); } } } } } } else { if ($gijoe[$loc . $move] == 0) { $scoutresults = array(); $scoutresults = valid_scout($pselect, $move); $differenceofspots = $scoutresults['distance']; $direction = $scoutresults['direction']; if ($differenceofspots > 0) { $openspots = 1; for ($i = 1; $i < $differenceofspots; $i++) { if ($direction == 4) { $checklake = $pselect + $i; if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) { $openspots = 0; } $temp1 = $loc . ($pselect + $i); $temp2 = $antiloc . ($pselect + $i); $openplayer = $gijoe[$temp1]; $openopponent = $gijoe[$temp2]; if ($openplayer != 0 || $openopponent != 0) { $openspots = 0; } } if ($direction == 3) { $checklake = $pselect - $i; if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) { $openspots = 0; } $temp1 = $loc . ($pselect - $i); $temp2 = $antiloc . ($pselect - $i); $openplayer = $gijoe[$temp1]; $openopponent = $gijoe[$temp2]; if ($openplayer != 0 || $openopponent != 0) { $openspots = 0; } } if ($direction == 2) { $movevalue = $i . "0"; $checklake = $pselect - $movevalue; if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) { $openspots = 0; } $temp1 = $loc . ($pselect - $movevalue); $temp2 = $antiloc . ($pselect - $movevalue); $openplayer = $gijoe[$temp1]; $openopponent = $gijoe[$temp2]; if ($openplayer != 0 || $openopponent != 0) { $openspots = 0; } } if ($direction == 1) { $movevalue = $i . "0"; $checklake = $pselect - $movevalue; if ($checklake == 56 || $checklake == 46 || $checklake == 53 || $checklake == 43) { $openspots = 0; } $temp1 = $loc . ($pselect + $movevalue); $temp2 = $antiloc . ($pselect + $movevalue); $openplayer = $gijoe[$temp1]; $openopponent = $gijoe[$temp2]; if ($openplayer != 0 || $openopponent != 0) { $openspots = 0; } } } if ($openspots == 1) { $startingspot = $loc . $pselect; $finishingspot = $loc . $move; $piecetomove = $gijoe[$startingspot]; $text = ""; $newmovelist = move_list($pselect, $move, $gijoe['listofmoves'], $gijoe['posa'], $attackersusername, $defendersusername); $db->query("UPDATE st_game SET listofmoves = '{$newmovelist}', {$startingspot} = 0, {$finishingspot} = {$piecetomove}, pselected = 0, lastmove = {$move}, battletxt = '{$text}' WHERE st_room={$roomid}"); toggle_turn($roomid); } } } } } } }