游戏是用网页做的,大家就把下面这个存成.htm文件再打开就是了:
<html><head><title>智力游戏(把所有按钮变成蓝色的)</title>
<style>
body{
text-align:center;
background-color:#EAF5FF;
margin:0px;
font-size:12px;
font-family:"宋体";
}
table{
table-layout: fixed;
border-collapse: collapse;
}
td{
cursor:hand;
overflow:hidden;
text-overflow:ellipsis;
width:100px;
height:100px;
border:1px solid yellow;
}
td.x{
background-color:red;
}
td.o{
background-color:blue;
}
</style>
<script language="javascript">
var clk=0;
function init(){
var gameborder=document.all.gameborder;
for(var i=0;i<5;i++){
var newRow=gameborder.insertRow();
for(var j=0;j<5;j++){
var newCell=newRow.insertCell();
newCell.className="x";
newCell.onclick=press;
}
}
}
function press(){
clk++;
this.className=this.className=="x"?"o":"x";
if(this.cellIndex>0){
var obj=this.parentElement.cells[this.cellIndex-1];
obj.className=obj.className=="x"?"o":"x";
}
if(this.cellIndex<4){
var obj=this.parentElement.cells[this.cellIndex+1];
obj.className=obj.className=="x"?"o":"x";
}
var par=this.parentElement;
if(par.rowIndex>0){
var obj=par.parentElement.rows[par.rowIndex-1].cells[this.cellIndex];
obj.className=obj.className=="x"?"o":"x";
}
if(par.rowIndex<4){
var obj=par.parentElement.rows[par.rowIndex+1].cells[this.cellIndex];
obj.className=obj.className=="x"?"o":"x";
}
testWin();
}
function testWin(){
var gameborder=document.all.gameborder;
for(var i=0;i<5;i++)
for(var j=0;j<5;j++)
if(gameborder.rows[i].cells[j].className=="x")return;
alert("You win at take "+clk+" click");
}
</script></head><body onload="init();"><table id="gameborder"></table></body></html>
<html><head><title>智力游戏(把所有按钮变成蓝色的)</title>
<style>
body{
text-align:center;
background-color:#EAF5FF;
margin:0px;
font-size:12px;
font-family:"宋体";
}
table{
table-layout: fixed;
border-collapse: collapse;
}
td{
cursor:hand;
overflow:hidden;
text-overflow:ellipsis;
width:100px;
height:100px;
border:1px solid yellow;
}
td.x{
background-color:red;
}
td.o{
background-color:blue;
}
</style>
<script language="javascript">
var clk=0;
function init(){
var gameborder=document.all.gameborder;
for(var i=0;i<5;i++){
var newRow=gameborder.insertRow();
for(var j=0;j<5;j++){
var newCell=newRow.insertCell();
newCell.className="x";
newCell.onclick=press;
}
}
}
function press(){
clk++;
this.className=this.className=="x"?"o":"x";
if(this.cellIndex>0){
var obj=this.parentElement.cells[this.cellIndex-1];
obj.className=obj.className=="x"?"o":"x";
}
if(this.cellIndex<4){
var obj=this.parentElement.cells[this.cellIndex+1];
obj.className=obj.className=="x"?"o":"x";
}
var par=this.parentElement;
if(par.rowIndex>0){
var obj=par.parentElement.rows[par.rowIndex-1].cells[this.cellIndex];
obj.className=obj.className=="x"?"o":"x";
}
if(par.rowIndex<4){
var obj=par.parentElement.rows[par.rowIndex+1].cells[this.cellIndex];
obj.className=obj.className=="x"?"o":"x";
}
testWin();
}
function testWin(){
var gameborder=document.all.gameborder;
for(var i=0;i<5;i++)
for(var j=0;j<5;j++)
if(gameborder.rows[i].cells[j].className=="x")return;
alert("You win at take "+clk+" click");
}
</script></head><body onload="init();"><table id="gameborder"></table></body></html>
解决方案 »
- 实现扑克牌 就是斗地主欢迎大家讨论,
- java 解析excel的问题
- javascript 怎么获取 maxlength 属性的值
- 连sqlserver的问题。
- 用jdbc odbc桥连接access数据库的初级问题 在线等!!!!!
- 大家有没有注意到在java中23/12结果是多少呢?
- 怎么设置Bean的路径
- 谁帮我解释graphic.copyArea(0, i, m_nImgWidth, 1, 0, m_nImgHeight - i)
- 关于*.JDR的问题?
- 我怒了!J2SDK 1.4出的鬼问题,到底怎么回事?
- 这个从 TreeMap 得到的 keySet 为什么jcreator编译不过去?javac 就没问题。。
- 闷!
for(int i=0;i<0x1FFFFFF;i++){
int above=i<<5;
int underside=i>>5;
int left=i<<1&0x1EF7BDE;
int right=i>>1&0xF7BDEF;
int result=i^above^underside^left^right;
if((result&0x1FFFFFF)==0x1FFFFFF){
String s="";
for(int j=0;j<25;j++){
s+=(i>>j&1)==1?" ●":" ○";
if(j%5==4) s+="\r\n";
}
System.out.println(s);
}
}
其次,成功的解法中,每个格子自己、上、下、左、右等5个位置中,必须有奇数个被点击
由此2条规则可得:游戏的解一共是2的25次方个;每个解的结果中每个格子与上述5个位置的点击总数相关解题思路:
1、循环2的25次方次,即0x1FFFFFF次(其实首尾的很多都是肉眼可排除的,不过不影响大局)
2、每次循环得到一个整数,用这个整数的每一个二进制位对应这25个格子,位上为1表示该格子需要按下
3、计算上、下、左、右四个方位,使其与中心位置对应(注意由于左右两边的边界问题,需要两个数相与,而上下由于位移时全为0不影响,所以不需要额外处理)
4、计算该中心位置的最终结果,计算方式为统计上述5个位置的点击总数,若为奇数则成功,否则失败(最好的计算方式:异或,具体自行理解)
5、判断每个格是否都成功,若全成功,则打印出当前解