我正在尝试在php中创建拼字游戏。一方面有用户转弯,另一方面有计算机。只有一组包含随机字母的堆。
每位用户转动后,计算机都会随机抽取字母并将其放置在板上。
现在,我想查找每转一圈该词在板上的位置。
这是我的php代码
<?php
include "config.php";
error_reporting(0);
$sql=mysql_query("SELECT * FROM animate ORDER BY RAND()") or die("query Failed");
echo "<div class='board'>";
for($row=0;$row<8;$row++){
for($column=0;$column<8;$column++){
echo "<div xy='x".$row."_y".$column."' class='empty'></div>";
}
}
echo "<div style='clear: both'></div>";
echo "</div>";
?>
将随机抽取的字母组成下一移动
<div class='words'>
<?php
for($column=0;$column<8;$column++){
echo '<div class="'.bluexyz.'">'.
$field1 = mysql_fetch_object($sql)->code
.'</div>';
}
?>
现在这是用于用户和计算机转向的JavaScript代码
var turn = Math.round(Math.random() * (1));
var player = turn;
var max = 8;
function put_val (max,pick_val){
var x = Math.round(Math.random() * (max-1));
var y = Math.round(Math.random() * (max-1));
var find_place = "x"+x+"_y"+y;
if ($(".board .empty[xy='"+find_place+"']").hasClass("empty")) {
$(".board .empty[xy='"+find_place+"']").text(pick_val);
$(".board .empty[xy='"+find_place+"']").removeClass("empty").addClass("cpu");
} else {
put_val(max,pick_val);
}
}
function cpu_turn (){
var rand_char = Math.round(Math.random() * (max-1));
$(".words div.bluexyz").each(function(i,e){
if (rand_char == i) {
var pick_val =($(this).text());
put_val(max,pick_val);
player = 0;
}
});
}
$(document).ready(function(){
// 1 = cpu
//0 = player
if (player == 1) {
cpu_turn();
} else {
alert("your turn");
}
});
var box = null;
$('.bluexyz').draggable({
revert: true,
helper: 'clone',
cursor: 'pointer',
start: function(event, ui) {
$(this).fadeTo('fast', 0.5);
},
stop: function(event, ui) {
$(this).fadeTo(0, 1);
box = $(this);
}
});
$(".empty").droppable({
drop: function(event, ui) {
var $this = $(this);
if ($(this).hasClass("empty") && player == 0) {
$this.text(ui.draggable.text());
player = 1;
$(this).removeClass("empty").addClass("user");
cpu_turn();
} else {
alert("this is full");
}
}
});
如何从木板上的这些字母中找到单词的组合。