Fixing auto-skip in harvest and adding restart-game.

logins
Thomas Hintz 5 years ago
parent f485f811ba
commit 38c2920b85

@ -1111,38 +1111,46 @@ class Die extends React.Component {
return roll; return roll;
} }
tick() { tick = () => {
this.acc += this.interval; let finished = false;
// update die face return function() {
if (this.ticks < this.maxTicks && this.acc >= this.trigger) { if (!finished) {
this.ticks++; this.acc += this.interval;
this.acc = 0; // update die face
// update trigger for decay if (this.ticks < this.maxTicks && this.acc >= this.trigger) {
if (this.props.decay) { this.ticks++;
this.trigger = decay(this.props.ms, this.decayFactorPct, this.acc = 0;
this.maxTicks - this.ticks); // update trigger for decay
} if (this.props.decay) {
// we're finished, clear things, set final roll value this.trigger = decay(this.props.ms, this.decayFactorPct,
if (this.ticks >= this.maxTicks) { this.maxTicks - this.ticks);
clearInterval(this.timerId); }
this.timerId = false; // we're finished, clear things, set final roll value
this.setState({ num: this.props.num, finalFace: true }); if (this.ticks >= this.maxTicks) {
if (this.props.showScreen) { finished = true;
this.showScreenTimerId = setInterval(() => { clearInterval(this.timerId);
this.props.showScreen(); this.timerId = false;
clearInterval(this.showScreenTimerId); this.setState({ num: this.props.num, finalFace: true });
this.showScreenTimerId = false; if (this.props.showScreen) {
}, this.props.showScreenDelay); this.showScreenTimerId = setInterval(() => {
this.props.showScreen();
clearInterval(this.showScreenTimerId);
this.showScreenTimerId = false;
}, this.props.showScreenDelay);
}
} else {
this.setState({ num: this.roll() });
}
} }
} else { } else {
this.setState({ num: this.roll() }); console.log('harvest die finished but still ticking');
} }
} }
} }
componentDidMount() { componentDidMount() {
if (this.props.roll) { if (this.props.roll) {
this.timerId = setInterval(() => this.tick(), this.interval); this.timerId = setInterval(this.tick().bind(this), this.interval);
} }
} }

@ -418,6 +418,17 @@
;; (print "</body></html>"))) ;; (print "</body></html>")))
) )
(define (restart-game game first-player)
(safe-set! (game-called-audit game) #f)
(safe-set! (game-state game) 'playing)
(for-each (lambda (p)
(safe-set! (player-finished p) #f)
(safe-set! (player-state p) 'turn-ended))
(game-players game))
(safe-set! (player-state first-player) 'pre-turn)
(safe-set! (game-current-player game) first-player)
(message-players! game #f '() type: "update"))
(define-method (player->list (p <player>)) (define-method (player->list (p <player>))
`((player . ((assets . ,(player-assets p)) `((player . ((assets . ,(player-assets p))
(ridges . ,(player-ridges p)) (ridges . ,(player-ridges p))
@ -1190,14 +1201,15 @@
(player (add-player-to-game game (player (add-player-to-game game
color color
(alist-ref 'playerName msg))) (alist-ref 'playerName msg)))
(ai-player (add-ai-to-game game 'red "AI Player 1"))) ;; (ai-player (add-ai-to-game game 'red "AI Player 1"))
)
(push! game (app-games *app*)) (push! game (app-games *app*))
(session-set! (sid) 'player player) (session-set! (sid) 'player player)
(session-set! (sid) 'game game) (session-set! (sid) 'game game)
(*game* game) (*game* game)
(set-startup-otbs game player 2) (set-startup-otbs game player 2)
(set-startup-otbs game ai-player 2) ;; (set-startup-otbs game ai-player 2)
(thread-start! (make-ai-push-receiver game ai-player)) ;; (thread-start! (make-ai-push-receiver game ai-player))
(create-start-response "new-game-started"))) (create-start-response "new-game-started")))
((string=? type "join-game") ((string=? type "join-game")
(let* ((name (alist-ref 'gameName msg)) (let* ((name (alist-ref 'gameName msg))
@ -2099,9 +2111,6 @@
;; info actions should look better ;; info actions should look better
;; you can get $50 from operating expense ;; you can get $50 from operating expense
;; auto-skip loop
;; harvester / tractor don't say total price
;; mark spaces ;; mark spaces
;; error: ;; error:
@ -2148,6 +2157,4 @@
;; Error: (assv) bad argument type: #<coops instance of `<game>'> ;; Error: (assv) bad argument type: #<coops instance of `<game>'>
;; auto-skip loop wtih harvest
;; when getting trade the name is wrong ;; when getting trade the name is wrong

Loading…
Cancel
Save