Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RunCat365/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<setting name="FirstLaunch" serializeAs="String">
<value>True</value>
</setting>
<setting name="HighScore" serializeAs="String">
<value>0</value>
</setting>
</RunCat365.Properties.UserSettings>
</userSettings>
</configuration>
22 changes: 19 additions & 3 deletions RunCat365/EndlessGameForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal class EndlessGameForm : Form
private int counter = 0;
private int limit = 5;
private int score = 0;
private int highScore = UserSettings.Default.HighScore;
private bool isJumpRequested = false;
private readonly bool isAutoPlay = false;

Expand Down Expand Up @@ -141,6 +142,7 @@ private void UpdateRoads()
if (firstRoad == Road.Sprout)
{
score += 1;
highScore = Math.Max(score, highScore);
}
counter = counter > 0 ? counter - 1 : limit - 1;
if (counter == 0)
Expand Down Expand Up @@ -252,7 +254,8 @@ private void RenderScene(object? sender, PaintEventArgs e)
Alignment = StringAlignment.Far,
LineAlignment = StringAlignment.Center
};
g.DrawString($"{Strings.Game_Score}: {score}", font15, brush, new Rectangle(20, 0, 560, 50), stringFormat);
g.DrawString($"{Strings.Game_HighScore}: {highScore}", font15, brush, new Rectangle(20, 0, 560, 50), stringFormat);
g.DrawString($"{Strings.Game_Score}: {score}", font15, brush, new Rectangle(20, 30, 560, 50), stringFormat);
}

roads.Take(20).Select((road, index) => new { road, index }).ToList().ForEach(
Expand All @@ -278,7 +281,15 @@ private void RenderScene(object? sender, PaintEventArgs e)
var message = Strings.Game_PressSpaceToPlay;
if (status == GameStatus.GameOver)
{
message = $"{Strings.Game_GameOver}\n{message}";
if (score >= highScore)
{
SaveRecord(score);
message = $"{Strings.Game_NewRecord}!!\n{message}";
}
else
{
message = $"{Strings.Game_GameOver}\n{message}";
}
}
var stringFormat = new StringFormat
{
Expand All @@ -288,6 +299,11 @@ private void RenderScene(object? sender, PaintEventArgs e)
g.DrawString(message, font18, brush, new Rectangle(0, 0, 600, 250), stringFormat);
}
}
private void SaveRecord(int score)
{
UserSettings.Default.HighScore = score;
UserSettings.Default.Save();
}
}

internal static class ListExtension
Expand All @@ -297,4 +313,4 @@ internal static bool HasCommonElements(this List<int> list1, List<int> list2)
return list1.Intersect(list2).Any();
}
}
}
}
20 changes: 20 additions & 0 deletions RunCat365/Properties/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions RunCat365/Properties/Strings.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,10 @@
<data name="Menu_SpeedSource" xml:space="preserve">
<value>速度の基準</value>
</data>
<data name="Game_HighScore" xml:space="preserve">
<value>ハイスコア</value>
</data>
<data name="Game_NewRecord" xml:space="preserve">
<value>新記録</value>
</data>
</root>
6 changes: 6 additions & 0 deletions RunCat365/Properties/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,10 @@
<data name="Menu_SpeedSource" xml:space="preserve">
<value>Speed based on</value>
</data>
<data name="Game_HighScore" xml:space="preserve">
<value>High Score</value>
</data>
<data name="Game_NewRecord" xml:space="preserve">
<value>New Record</value>
</data>
</root>
20 changes: 16 additions & 4 deletions RunCat365/Properties/UserSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion RunCat365/Properties/UserSettings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
<Setting Name="FirstLaunch" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="HighScore" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="SpeedSource" Type="System.String" Scope="User">
<Value Profile="(Default)">CPU</Value>
</Setting>
</Settings>
</SettingsFile>
</SettingsFile>