用 HTML/CSS 或 Javascript 制作井字游戏板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26964025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making a tic tac toe board in HTML/CSS or Javascript
提问by Amdyrim
For my class I have to make the game of Tic Tac Toe using what I have learned which is HTML/CSS and some javascript. I have not learned arrays, loops, or objects yet. So I am hoping this is possible. What I have learned is functions, variables, and if/else/else if. Basically I don't want to ask you nice people to help me with the entire thing because I don't think anyone would do that and it would take to long. I will, however, say that I have no idea where to even start but hopefully I can figure it out. What I do need help on however is setting up the actual board. Do you think I could do something in HTML for setting up the board? Like using the table, th, and tr elements? Or would CSS be better? Thanks a bunch to the people that help!
对于我的课程,我必须使用我所学的 HTML/CSS 和一些 javascript 来制作 Tic Tac Toe 游戏。我还没有学习数组、循环或对象。所以我希望这是可能的。我学到的是函数、变量和 if/else/else if。基本上我不想请你们好人帮我做整件事,因为我认为没有人会这样做,而且需要很长时间。但是,我要说的是,我什至不知道从哪里开始,但希望我能弄清楚。然而,我需要帮助的是设置实际的电路板。你认为我可以用 HTML 来设置电路板吗?喜欢使用 table、th 和 tr 元素吗?或者 CSS 会更好吗?非常感谢提供帮助的人!
回答by michaelpri
Here's a table that would help.
这是一个可以提供帮助的表格。
Html:
网址:
<table>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
Css:
css:
td {
border: 1px solid black;
height: 50px;
width: 50px;
}
回答by user2226786
As rpax said,
正如 rpax 所说,
Use a table with the number of rows you want and the number of columns.
使用包含所需行数和列数的表格。
Another suggestion I have for game programming in general is draw it out and write every action possible for all characters down. It may even be a good idea to brainstorm ways to do these tasks on paper. The main thing is, WRITE IT OUT. This will make sure you have a saved plan and you can always change it later.
我对游戏编程的另一个建议是将其绘制出来并写下所有角色的每一个可能的动作。集思广益在纸上完成这些任务的方法甚至可能是一个好主意。最重要的是,写出来。这将确保您有一个已保存的计划,并且您以后可以随时更改它。
回答by user2478240
I would create a div in each cell with an id and an onclick function.
我会在每个单元格中创建一个带有 id 和 onclick 函数的 div。
Maybe you could do something like
也许你可以做类似的事情
var a =1 ;
function dosomething(){
if(a=1){
document.getElementById('').innerHTML='x';
}else{
document.getElementById('').innerHTML='O';
}
a=0;
}