我正在编写一个非常简单的风险游戏,每当你点击一个国家时,它的颜色就会从红色变为绿色、黄色、紫色,然后再变为白色。
你从一张“全白”地图开始,我想做的是创建不同的插槽,让我可以说一旦我给一些地图上色,将游戏保存在那个插槽中,然后重新加载插槽号 1 例如和继续我离开的地方。对于 4 个不同的插槽,我怎么能做到这一点?世界地图是一个 SVG 文件,我将每个区域的颜色更改为event.target.style.fill.
拿这个代码:
HTML
<svg width="100%" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 701 300" style="enable-background:new 0 0 701 300;" xml:space="preserve">
<g onclick="changeColor(event)">
<path class="st1" d="M308.6,112.3l-0.1,0.2l-0.1,0.2l-0.1-0.1h-0.1l-0.1-0.1l0.1-0.1h0.1l0.1-0.1l0.1-0.1L308.6,112.3L308.6,112.3z
M313.4,111.6v0.2l0.1,0.1l-0.1,0.2v0.1l-0.1,0.1l-0.2,0.1l-0.1,0.1l-0.2-0.1l-0.2-0.2l-0.1-0.1v-0.2l0.2-0.1v-0.2v-0.1h0.2h0.1h0.1
L313.4,111.6z M309.9,111.8L309.9,111.8l-0.2-0.1l-0.1-0.1v-0.1v-0.1h0.1h0.1l0.2,0.1v0.1L309.9,111.8L309.9,111.8z M312,110.6
L312,110.6l-0.2,0.2l-0.1,0.2l-0.1,0.1v0.1l-0.1,0.2v0.1l-0.2,0.2v0.1h-0.1l-0.2,0.1l0,0v-0.1l-0.1-0.1v-0.1l-0.1-0.1v-0.1l-0.1-0.2
l0.2-0.1l0.1,0.1l0.2-0.1h0.1l0.2-0.1l0.2-0.1v-0.1l0.2-0.1h0.2L312,110.6L312,110.6z M315.6,111.6l-0.1,0.1h-0.1h-0.1h-0.1v-0.1
h0.1l0.2-0.1l0.1-0.1l0.1-0.1v-0.2V111l0.1-0.2l0.1-0.1l0.1-0.2l0.1-0.3l0.1-0.1h0.1l0.1,0.1v0.2v0.2v0.2v0.2l0,0l-0.1,0.2l-0.1,0.1
H316L315.6,111.6L315.6,111.6z M308.8,110h0.1l0.1,0.1l0.1,0.2l-0.1,0.1v0.1l-0.2,0.3l0,0v-0.1l-0.1-0.3v-0.1v-0.1L308.8,110h0.1
H308.8z M317.1,109.3L317.1,109.3l-0.1,0.3l-0.2,0.2h-0.2l-0.1,0.2l-0.2-0.1l0,0l0.1-0.1v-0.1l0.1-0.1l0.1-0.1h0.1l0.1-0.1h0.2l0,0
L317.1,109.3l0.1-0.1l0.1,0.1H317.1z"/>
</g>
</svg>
CSS(初始颜色 = 白色)
.st1{fill:#FFFFFF;stroke:#000000;stroke-linejoin:round;}
这是现场演示和网站,您可以查看。我添加的最后一件事是用于保存和加载游戏的 UI。(可以在“加载/保存游戏”按钮上找到。
https://risk-git-saves-system.swilkery.vercel.app/
呼啦一阵风
相关分类