写一个html 狙击游戏
时间: 2023-07-20 19:30:32 浏览: 65
好的,下面是一个简单的 HTML 狙击游戏的示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>狙击游戏</title>
<style type="text/css">
#game-board {
width: 800px;
height: 600px;
background-color: #333;
position: relative;
}
#target {
width: 50px;
height: 50px;
background-color: red;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
cursor: pointer;
}
</style>
</head>
<body>
<div id="game-board">
<div id="target"></div>
</div>
<script type="text/javascript">
var target = document.getElementById("target");
target.addEventListener("click", function() {
alert("你命中了目标!");
});
</script>
</body>
</html>
```
这个游戏板是一个 `800x600` 的黑色矩形,中央有一个红色目标,玩家需要点击目标来命中它。当玩家点击目标时,弹出一个窗口显示“你命中了目标!”的消息。注意,这只是一个简单的示例,可以根据需求进行修改和扩展。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)