Skip to content

Commit

Permalink
sofo.demo
Browse files Browse the repository at this point in the history
  • Loading branch information
eguneys committed Jan 2, 2024
1 parent 02fe8de commit 50fed29
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 19 deletions.
36 changes: 23 additions & 13 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import Sound from './sound'
import Trans, { languages } from './trans'

import { limit_settings, cards_settings, SolitaireStore, GeneralStore } from './store'

import { SolitaireResultsStore } from './store'
import { GameResults, OverallResults } from './statistics'


type RectData = {
Expand Down Expand Up @@ -2055,17 +2056,22 @@ class OverallStatistics extends Play {
center: true
})

let overall_results = new OverallResults(
SolitaireResultsStore.results,
new GameResults([]),
new GameResults([]))

let h = 100

this.make(TransText, Vec2.make(700, 200), {
key: 'total_games_played%100%',
key: `total_games_played%${overall_results.total_played}%`,
width: 820,
height: 200,
center: true
})

this.make(TransText, Vec2.make(700, 200 + h * 1.2), {
key: 'games_won%20%',
key: `games_won%${overall_results.total_wins}%`,
width: 820,
height: 200,
center: true
Expand All @@ -2078,7 +2084,7 @@ class OverallStatistics extends Play {
center: true
})

let top_highscores = [10, 20, 30]
let top_highscores = overall_results.top_5_highscores

top_highscores.forEach((top, i) => {
this.make(TransText, Vec2.make(200, 200 + h * 4 + h * i * 1.5 + 80), {
Expand All @@ -2088,7 +2094,7 @@ class OverallStatistics extends Play {
no_trans: true
})
this.make(TransText, Vec2.make(700, 200 + h * 4 + h * i * 1.5 + 80), {
key: `${top}`,
key: `${top.multiplied_score}`,
width: 80,
height: 100,
no_trans: true,
Expand All @@ -2111,6 +2117,8 @@ class OverallStatistics extends Play {

class SolitaireStatistics extends Play {

height!: number

_init() {

this.make(TransText, Vec2.make(700, 0), {
Expand All @@ -2120,17 +2128,19 @@ class SolitaireStatistics extends Play {
center: true
})

let results = SolitaireResultsStore.results

let h = 100

this.make(TransText, Vec2.make(700, 200), {
key: 'total_games_played%100%',
key: `total_games_played%${results.total_played}%`,
width: 820,
height: 200,
center: true
})

this.make(TransText, Vec2.make(700, 200 + h * 1.2), {
key: 'games_won%20%',
key: `games_won%${results.total_wins}%`,
width: 820,
height: 200,
center: true
Expand All @@ -2143,7 +2153,7 @@ class SolitaireStatistics extends Play {
center: true
})

let top_highscores = [10, 20, 30]
let top_highscores = results.top_5_highscores

top_highscores.forEach((top, i) => {
this.make(TransText, Vec2.make(200, 200 + h * 4 + h * i * 1.5 + 80), {
Expand All @@ -2153,7 +2163,7 @@ class SolitaireStatistics extends Play {
no_trans: true
})
this.make(TransText, Vec2.make(700, 200 + h * 4 + h * i * 1.5 + 80), {
key: `${top}`,
key: `${top.multiplied_score}`,
width: 80,
height: 100,
no_trans: true,
Expand Down Expand Up @@ -2441,8 +2451,8 @@ export class MainMenu2 extends Play {

_ = this.make(Anim, Vec2.make(200, 150), { name: 'main_bg' })

let lisotaire = this.make(Text, Vec2.make(16, 32), { text: 'lisotaire', color: Color.hex(0x202431)})
this.make(Text, Vec2.make(16 + lisotaire.width, 32), { text: '.com', color: Color.hex(0xb4beb4)})
let sofo = this.make(Text, Vec2.make(16, 32), { text: 'sofo', color: Color.hex(0x202431)})
this.make(Text, Vec2.make(16 + sofo.width, 32), { text: '.demo', color: Color.hex(0xb4beb4)})


let card_x = 200
Expand Down Expand Up @@ -2584,8 +2594,8 @@ class SceneTransition extends Play {

//this.current = this._make(CardShowcase, Vec2.zero, {})
// this.current = this._make(MainMenu, Vec2.zero, {})
this.current = this._make(Statistics2, Vec2.zero, {})
// this.current = this._make(MainMenu2, Vec2.zero, {})
//this.current = this._make(Statistics2, Vec2.zero, {})
this.current = this._make(MainMenu2, Vec2.zero, {})
//this.current = this._make(HowtoPlay2, Vec2.zero, {})
//this.current = this._make(Settings2, Vec2.zero, {})
//this.current = this._make(SolitairePlay, Vec2.zero, {})
Expand Down
5 changes: 4 additions & 1 deletion src/solitaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { SolitaireGame } from './solitaire_game'
import { make_solitaire_back } from './solitaire_back'
import { card_sort_key, Settings } from 'lsolitaire'
import { Nine } from './nine'
import { SolitaireResultsStore } from './store'
import { SolitaireGameResult } from './statistics'

let rnd_screen_poss = [...Array(50).keys()].map(() => v_random().mul(v_screen.scale(0.8)))

Expand Down Expand Up @@ -691,9 +693,10 @@ export class SolitairePlay extends Play {
}
}

const on_game_over = (score: number) => {
const on_game_over = (_: Settings, score: number) => {
this.game_over_confetti_pop()
game_over_dialog = this.make(GameOverDialog, Vec2.make(0, 0), { score })
SolitaireResultsStore.add_result(SolitaireGameResult.from_win(_, score))
}

make_solitaire_back(game, on_score, on_new_game, on_game_over).then(back_res => {
Expand Down
23 changes: 19 additions & 4 deletions src/solitaire_back.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { SolitaireGame } from './solitaire_game'
import { Settings, Cards, Solitaire, SolitairePov, Game as OSolitaireGame, GamePov, IMoveType, TableuToTableu, IMove, TableuToFoundation, WasteToFoundation } from 'lsolitaire'
import { SolitaireStore } from './store'
import { SolitaireResultsStore, SolitaireStore } from './store'
import { arr_random } from './util'
import { SolitaireGameResult } from './statistics'

export type BackRes = {
game_pov: GamePov<SolitairePov, Solitaire>,
Expand All @@ -14,7 +15,7 @@ export type BackRes = {
export const make_solitaire_back = async (game: SolitaireGame,
on_score: (_: number) => void,
on_new_game: (_: Settings) => void,
on_game_over: (_: number) => void): Promise<BackRes> => {
on_game_over: (_: Settings, score: number) => void): Promise<BackRes> => {

let back = solitaire_back
let game_pov = await back.get_pov()
Expand All @@ -39,7 +40,7 @@ export const make_solitaire_back = async (game: SolitaireGame,

back.get_pov().then(_ => {
if (_.game.is_finished) {
on_game_over(_.score)
on_game_over(_.game.settings, _.score)
}
})
}
Expand Down Expand Up @@ -67,14 +68,28 @@ export const make_solitaire_back = async (game: SolitaireGame,
}
},
async new_game() {


back.get_pov().then(_ => {
let score = _.score

if (score > 0) {
if (!_.game.is_finished) {
SolitaireResultsStore.add_result(SolitaireGameResult.from_loss(_.game.settings, score))
}
}
})


solitaire_back = new SolitaireBack()
back = solitaire_back
game_pov = await solitaire_back.get_pov()

game.new_game()

back.get_pov().then(_ => on_score(_.score))
back.get_pov().then(_ => on_new_game(_.game.settings))

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/solitaire_game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { HitStock, Recycle,
TableuToFoundation,
FoundationToTableu,
} from 'lsolitaire'
import { SolitaireStore } from './store'
import { SolitaireStore, SolitaireResultsStore } from './store'
import { ticks } from './shared'
import { appr } from './lerp'

Expand Down
Loading

0 comments on commit 50fed29

Please sign in to comment.