擅长:python、mysql、java
<p>我不打算完全编码出如何为您编写菜单,因为这会破坏类练习的目的,但我可以为您指出正确的方向。</p>
<p>如果您有两个选项菜单,我将如何编写主菜单如下:quit and start game(伪代码):</p>
<pre><code>initialize all menu variables
draw menu pix and selections
while a selection has not been made:
look for key inputs (arrow keys/enter/esc)
if down arrow pressed:
move selection box to next option and note that the selection is on the next object down
if up arrow pressed:
move selection box to previous option and note that the selection is on the previous object up
if escape pressed:
quit the game
if enter pressed:
process which option in the menu was highlighted (quit of quit was selected, etc) and tell the while loop to stop
update the display
set up the game variables and such
main while loop
run the game and get an A+
</code></pre>
<p>如果这能回答你的问题,请告诉我。它背后的基本思想是添加另一个while循环,该循环显示一个基本菜单,并在它进入游戏之前显示它。这也许不是最有效的方法,但对我来说,这似乎是最简单的方法。</p>
<p>顺便说一句,你现在可能希望远离复杂的动画和鼠标事件,直到你找到了基本菜单。使用老式的好盒子和箭头键输入。</p>