-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGlobal.cs
65 lines (55 loc) · 1.49 KB
/
Global.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Godot;
using System;
public class Global : Node
{
private static int _score;
private static bool _hardcore;
private static int _hits;
private static int _highscore;
private static string ScoreFile = "user://highscore.txt";
public override void _Ready()
{
GD.Print(OS.GetUserDataDir());
Setup();
}
public override void _Process(float delta)
{
base._Process(delta);
if (Input.IsActionJustReleased("exit"))
{
GetTree().Quit();
}
}
public static int Hits { get => _hits; set => _hits = value; }
public static int Score { get => _score; set => _score += value; }
public static bool Hardcore { get => _hardcore; set => _hardcore = value; }
public static int HighScore { get => _highscore; set => _highscore = value; }
public static void UpdateHits(int hit)
{
Hits += hit;
}
public static void SetHighscore()
{
if (Score <= HighScore) return;
HighScore = Score;
SaveScore();
}
public void Setup()
{
File f = new File();
if (f.FileExists(ScoreFile))
{
f.Open(ScoreFile, 1);
string content = f.GetAsText();
HighScore = Convert.ToInt32(content);
f.Close();
}
}
public static void SaveScore()
{
File f = new File();
f.Open(ScoreFile, 2);
f.StoreString(Convert.ToString(HighScore));
f.Close();
}
}