所以,我正在尝试用 Javascript (jQuery) 做一个小浏览器游戏。我已经有了战斗系统,现在我正在尝试做移动系统,这样你就可以在世界各地移动。
假设我想打开 map 并进城,然后去购物。打开 MAP 窗口并关闭所有其他窗口,然后打开 TOWN 窗口并关闭 MAP 窗口,然后打开 SHOP 窗口并关闭 TOWN 窗口的最佳方法是什么?
我尝试了一些东西,但感觉有点糟糕..这是一个好方法吗?
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<style>
.shopBox {
width: 300px;
height: 100px;
border: 1px solid black;
display: none;
}
.mapBox {
width: 500px;
height: 500px;
border: 1px solid black;
display: none;
}
.button {
width: 50px;
height: auto;
border: 1px dashed black;
margin: 5px;
padding: 2px;
cursor: pointer;
}
.shop {
width: 50px;
height: 50px;
border: 1px solid black;
position: relative;
left: 50px;
top: 100px;
cursor: pointer;
}
</style>
<script>
$(document).ready(function(){
$("#exit").hide();
$("#mapBtn").click(function(){
$("#map").show();
$("#exit").show();
$("#shop").hide();
$("#mapBtn").hide();
});
$("#shopImg").click(function(){
$("#map").hide();
$("#shop").show();
$("#exit").show();
});
});
</script>
<div class="button" id="mapBtn">Map</div>
<div class="mapBox" id="map">
This is your map
<div class="shop" id="shopImg">Shop!!</div>
</div>
<div class="shopBox" id="shop">Welcome to my shop!</div>
</body>
</html>
最佳答案
您编写的代码看起来很实用。我没有看到任何问题。您将遇到的唯一问题是当您开始引入更多细节和复杂性时。
只要确保你开始将它们制作成带有注释的函数,否则你会迷失方向。
顺便说一句,考虑一下 Unity 开发平台或 Flash,或者考虑使用库,这将为您节省大量时间:例如。 Crafty
否则,您将在继续编码的过程中学习。重点关注功能,然后优化。在经验有限的情况下同时做这两件事可能会适得其反。
干杯
关于javascript - jQuery RPG 游戏 Movemen 系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29147919/