2

我有一个简单的 Windows 手机游戏,玩家在屏幕上拖动一艘船来收集物品并避开小行星。每次收集物品时,屏幕顶部的分数计数器都会增加一。

问题是,一旦玩家的飞船与小行星相撞,我想让游戏过渡到排行榜,但我不知道该怎么做。

我有一个整数来存储得分值,但是一旦玩家与小行星碰撞,该整数的值就会重置(当然)。

如何将玩家死亡前得分的最终值存储为单独的整数并在排行榜屏幕上显示?无需解释游戏状态管理,我已经知道如何使用它。

4

3 回答 3

2

首先,在处理小行星碰撞时发生的情况的代码中,您需要首先保存您的分数,然后在完成后将其重置。当你显示它时,你需要从一个序列化文件中加载你的排行榜。

我不打算详细介绍,因为我找到了一个基本上解释了我会告诉你的网站:http: //xnaessentials.com/tutorials/highscores.aspx

当然,您需要稍微修改一下并添加一种排序高分的方法,但我怀疑这应该让您开始。

于 2013-04-06T12:46:31.323 回答
1

好的。在检测到碰撞时将变量分数重置为 0 之前,请将分数存储在隔离存储设置中,并将密钥作为配置文件名称。只有当已经存在的键值较小时,您才可以进行其他操作,例如存储,或者如果没有找到键值,则立即存储它。

于 2013-04-06T12:26:44.377 回答
0

The simplest method of retaining the high score after the game ends is to make the int static and only reset it to zero at the start of a new game - rather than when the game ends.

So in your MyGame class: internal static int Score = 0;

In whatever function starts a new game: MyGame.Score = 0;

and in your Leaderboard screen: List highScores = new List();

...

if (highScores.Count == 0 || MyGame.Score > highScores[highScores.Count-1]) { // the score made the ordered list Leaderboard (you'll need to limit it to some maxiumum number of scores) }

于 2013-04-08T15:48:18.537 回答