diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-05-31 18:11:09 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-05-31 18:11:09 +0200 |
| commit | 0010f2de57cfa97106432ea1849c1bb75d3d99a1 (patch) | |
| tree | 41e89ff13aacfc4dc1324a365302a0867e316dc9 /src/Storage.ts | |
| parent | 344737031e5bbad5f24469aabf45be6535c893f3 (diff) | |
| download | 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.gz 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.zst 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.zip | |
All enemies movement
Diffstat (limited to 'src/Storage.ts')
| -rw-r--r-- | src/Storage.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Storage.ts b/src/Storage.ts new file mode 100644 index 0000000..50d70a2 --- /dev/null +++ b/src/Storage.ts @@ -0,0 +1,40 @@ +// export ine +export interface Score { + name: string[]; + score: string; + world: string; +} +export type Storage = Score[] +export function getStorage(): Storage { + const s = JSON.parse(localStorage.getItem("storage") ?? "{}"); + const storage = [ + { name: "...".split(''), score: "40000", world: "03" }, + { name: "...".split(''), score: "35000", world: "02" }, + { name: "...".split(''), score: "30000", world: "01" }, + { name: "...".split(''), score: "25000", world: "01" }, + { name: "...".split(''), score: "20000", world: "01" }, + { name: "...".split(''), score: "15000", world: "01" }, + ] as Storage; + if (s[1] == null) return storage + return s; +} + +export function setStorage(s: Storage) { + debugger + localStorage.setItem("storage", JSON.stringify(s)) +} + +export function getPlace(s: number): string { + const storage = getStorage(); + let place = 7 + for (let i = 1; i <= storage.length; i++) { + let sc = parseInt(storage[i - 1]['score']); + if (s > sc) { + place = i; break; + } + } + if (place === 1) return "1st"; + else if (place === 2) return "2nd"; + else if (place === 3) return "3rd"; + else return place + "th"; +} |
