Skip to content

Commit

Permalink
scores
Browse files Browse the repository at this point in the history
  • Loading branch information
eguneys committed Dec 26, 2023
1 parent b24d0c7 commit d77e3ce
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 34 deletions.
6 changes: 6 additions & 0 deletions content/trans/en.trans
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ turning_limit=turning limit
no_limit=no limit
three_passes=3 passes
one_pass=1 pass
threecards=3 cards
onecard=1 card
nolimit=no limit
threepass=3 passes
onepass=1 pass

8 changes: 7 additions & 1 deletion content/trans/tr.trans
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ one_card=1 kart
turning_limit=açma limiti
no_limit=limitsiz
three_passes=3 geçiş
one_pass=1 geçiş
onepass=1 geçiş
threecards=3 kart
onecard=1 kart
nolimit=limitsiz
threepass=3 geçiş
onepass=1 geçiş

9 changes: 7 additions & 2 deletions src/showcase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,11 @@ export class CardDropTarget extends Play {

let i = 0
export class Cards extends Play {


frees!: Array<Card>
used!: Array<Card>


borrow() {
let card = this.frees.shift()!
this.used.push(card)
Expand Down Expand Up @@ -705,7 +705,6 @@ type TableuData = {
}

export class Tableu extends Play {

get data() {
return this._data as TableuData
}
Expand All @@ -718,6 +717,12 @@ export class Tableu extends Play {
return this.backs.top_position
}

release_all() {
return this.free()
}



free() {
return [
...this.backs.remove_cards(this.backs.length),
Expand Down
63 changes: 56 additions & 7 deletions src/solitaire.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Sound from './sound'
import { TextureFilter, TextureSampler } from 'blah'
import { Color } from 'blah'
import { Rect, Vec2, Mat3x2 } from 'blah'
Expand All @@ -24,6 +25,8 @@ import { Tween } from './tween'
import { Button } from './ui'
import { Card } from './showcase'
import { SolitaireGame, card_sort_key } from './solitaire_game'
import { make_solitaire_back } from './solitaire_back'
import { Settings } from 'lsolitaire'

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

Expand Down Expand Up @@ -434,6 +437,46 @@ class Overlay extends Play {
}
}


class SolitaireGameTitle extends Play {

set settings(_: Settings) {
this.cards.text = _.cards
this.limit.text = _.limit
}

cards!: TransText
limit!: TransText

_init() {

let _ = this.make(TransText, Vec2.make(0, 0), {
no_trans: true,
key: 'Solitaire',
width: 350,
height: 64,
color: Color.white
})

this.cards = this.make(TransText, Vec2.make(350, 5), {
key: 'one_pass',
width: 350,
height: 40,
color: Color.white,
})

this.limit = this.make(TransText, Vec2.make(550, 5), {
key: 'no_limit',
width: 350,
height: 40,
color: Color.white,
})



}
}

export class SolitairePlay extends Play {

set sidebar_open(v: boolean) {
Expand All @@ -449,15 +492,10 @@ export class SolitairePlay extends Play {
_init() {

let sidebar: SideBar
let scoreboard: ScoreBoard

this.make(Background, Vec2.zero, undefined)

let game = this.make(SolitaireGame, Vec2.make(0, 0), {
on_score(score: number) {
scoreboard.score = score
}
})
let game = this.make(SolitaireGame, Vec2.make(0, 0), {})

this.make(Button, Vec2.make(160, 1000), {
text: 'undo',
Expand All @@ -466,7 +504,18 @@ export class SolitairePlay extends Play {
}
})

scoreboard = this.make(ScoreBoard, Vec2.make(16, 860), {})

let title = this.make(SolitaireGameTitle, Vec2.make(640, 16), {})
let scoreboard = this.make(ScoreBoard, Vec2.make(16, 860), {})

make_solitaire_back(game).then(back_res => {
game.back_res = back_res
game._collect_pov()
Sound.music('main')

title.settings = back_res.game_pov.game.settings
})


let self = this
let overlay = this.make(Overlay, Vec2.zero, {
Expand Down
44 changes: 37 additions & 7 deletions src/solitaire_back.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { SolitaireGame } from './solitaire_game'
import { Settings, Cards, Solitaire, SolitairePov, Game as OSolitaireGame, GamePov, IMoveType } from 'lsolitaire'
import { SolitaireStore } from './store'
import { arr_random } from './util'

export type BackRes = {
game_pov: GamePov<SolitairePov, Solitaire>,
cmd(cmd: IMoveType<SolitairePov, Solitaire>, data?: any): void,
undo(): void
undo(): void,
new_game(): void,
}

export const make_solitaire_back = async (game: SolitaireGame): Promise<BackRes> => {

let back = new SolitaireBack()
export const make_solitaire_back = async (game: SolitaireGame, on_score: (_: number) => void, on_settings: (_: Settings) => void): Promise<BackRes> => {

let back = solitaire_back
let game_pov = await back.get_pov()

return {
Expand Down Expand Up @@ -44,6 +48,13 @@ export const make_solitaire_back = async (game: SolitaireGame): Promise<BackRes>
} else {
game.cant_undo()
}
},
async new_game() {
solitaire_back = new SolitaireBack()
back = solitaire_back
game_pov = await solitaire_back.get_pov()

game.new_game()
}
}

Expand All @@ -52,11 +63,14 @@ export const make_solitaire_back = async (game: SolitaireGame): Promise<BackRes>

class SolitaireBack {

static resume = () => {
return new SolitaireBack()
}

game: OSolitaireGame<SolitairePov, Solitaire>

constructor() {
let settings: Settings = { cards: 'threecards', limit: 'nolimit' }
let solitaire = Solitaire.make(settings, Cards.deck)
let solitaire = Solitaire.make(SolitaireStore.general_settings, shuffleArray(Cards.deck))
this.game = OSolitaireGame.make<SolitairePov, Solitaire>(solitaire)
}

Expand All @@ -65,11 +79,27 @@ class SolitaireBack {
}

async apply(cmd: IMoveType<SolitairePov, Solitaire>, data: any) {
return this.game.apply(cmd, data)
let res = await this.game.apply(cmd, data)
return res
}


async undo() {
return this.game.undo()
let res = await this.game.undo()
return res
}

}

let solitaire_back = new SolitaireBack()

/* Randomize array in-place using Durstenfeld shuffle algorithm */
function shuffleArray<T>(array: T[]): T[] {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array
}
50 changes: 36 additions & 14 deletions src/solitaire_game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { HitStock, Recycle,
TableuToFoundation,
FoundationToTableu,
} from 'lsolitaire'
import { SolitaireStore } from './store'

export type TableuDrag = {
tableu: number,
Expand Down Expand Up @@ -94,7 +95,6 @@ type StockData = {
}

class Stock extends Play {

get data() {
return this._data as StockData
}
Expand All @@ -103,6 +103,12 @@ class Stock extends Play {
return this.stock.length === 0
}

release_all() {
return this.free()
}



free() {

return [
Expand Down Expand Up @@ -131,6 +137,7 @@ class Stock extends Play {


add_stocks(cards: Array<Card>) {
cards.forEach(_ => _.flip_back())
this.stock.add_cards(cards)
}

Expand Down Expand Up @@ -250,6 +257,14 @@ class Foundation extends Play {
drop_target!: CardDropTarget


release_all() {
return this.free()
}

free() {
return this.remove_cards(this.foundation.length)
}

add_cards(cards: Array<Card>) {
this.foundation.add_cards(cards)
this.foundation.top_card?.bind_drag(e => this.data.on_front_drag(e))
Expand Down Expand Up @@ -470,16 +485,6 @@ export class SolitaireGame extends Play {
}
})


make_solitaire_back(this).then(back_res => {
this.back_res = back_res
this._collect_pov()
})



Sound.music('main')

}

_release_cancel_drag() {
Expand Down Expand Up @@ -514,15 +519,27 @@ export class SolitaireGame extends Play {

_init_pov() {

let { pov, stock, tableus } = this

this.recycle_view.visible = pov.can_recycle

stock.add_stocks(pov.stock.stock.cards.map(card => this.cards.borrow()))
let { pov, stock, tableus, foundations } = this


n_seven.map(i => {
let tableu = tableus[i]
tableu.release_all().forEach(_ => this.cards.release(_))
})
stock.release_all().forEach(_ => this.cards.release(_))
n_four.map(i => {
let foundation = foundations[i]
foundation.release_all().forEach(_ => this.cards.release(_))
})

this.recycle_view.visible = pov.can_recycle

stock.add_stocks(pov.stock.stock.cards.map(card => this.cards.borrow()))

n_seven.map(i => {

let tableu = tableus[i]
let t_pov = pov.tableus[i]

Expand Down Expand Up @@ -551,6 +568,10 @@ export class SolitaireGame extends Play {
}
}

new_game() {
this._collect_pov()
}

undo(res: IMove<SolitairePov, Solitaire>) {
Sound.play('undo2')
if (res instanceof HitStock) {
Expand Down Expand Up @@ -688,6 +709,7 @@ export class SolitaireGame extends Play {
}

request_new_game() {
this.back_res.new_game()
}
}

Expand Down
Loading

0 comments on commit d77e3ce

Please sign in to comment.