import { create_svg_element } from "./svg.js";
import { card_href, value_ace_low } from "./card.js";
import { GameWithChat } from "./gamechat.js";
-import { break_lines } from "./words.js";
import { CongratulateWinner } from "./winner.js";
export class Cribbage extends GameWithChat {
this.active = null;
this.dealer = null;
+ this.dealing = false;
const table = create_svg_element(this.svg, "ellipse", [], [["cx", "250"], ["cy", "253"], ["rx", "250"], ["ry", "110"], ["fill", "#604010"]]);
const felt = create_svg_element(this.svg, "ellipse", [], [["cx", "250"], ["cy", "250"], ["rx", "240"], ["ry", "100"], ["fill", "green"]]);
return active;
}
+ clear_pegging() {
+ this.count = 0;
+ this.passed.clear();
+ for (const [username, hand] of this.played) {
+ for (const card of hand) {
+ this.svg.removeChild(card.image);
+ card.image = this.card_image(username, null);
+ }
+ }
+ }
+
take_action(user_action) {
super.take_action(user_action);
switch (user_action.action.action) {
this.redraw_players();
break;
case "NextToDeal":
+ this.dealing = true;
this.dealer = user_action.username;
for (const card of this.community) {
this.svg.removeChild(card.image);
if (!this.scores.has(user_action.username)) {
this.scores.set(user_action.username, 0);
}
- const info_text = user_action.username + " scores " + user_action.action.points + ": " + user_action.action.reason;
- this.set_info_text(break_lines(info_text, 65));
+ this.set_info_text(user_action.username + " scores " + user_action.action.points + ": " + user_action.action.reason);
this.scores.set(user_action.username, this.scores.get(user_action.username) + user_action.action.points);
if ([...this.hands.values()].every(hand => hand.length === 0)) {
this.hands = this.played;
case "PlayCard":
this.count += value_ace_low(user_action.action.card.rank);
if (this.count === 31) {
- this.passed.clear();
- this.count = 0;
+ this.clear_pegging();
}
const played = this.remove_card(user_action.username, user_action.action.card);
if (played !== undefined) {
case "Pass":
this.passed.add(user_action.username);
if (this.passed.size === this.hands.size) {
- this.count = 0;
- this.passed.clear();
+ this.clear_pegging();
}
this.active = this.next_active_player(user_action.username);
this.redraw_cards();
this.redraw_cards();
break;
case "PutInBox":
- const removed = this.remove_card(user_action.username, user_action.action.card);
- if (removed !== undefined) {
- this.svg.removeChild(removed.image);
- this.box.push({card: null, image: this.card_image(null, null)});
+ if (!this.dealing) {
+ const removed = this.remove_card(user_action.username, user_action.action.card);
+ if (removed !== undefined) {
+ this.svg.removeChild(removed.image);
+ }
}
+ this.box.push({card: null, image: this.card_image(null, null)});
this.redraw_cards();
break;
case "CommunityCard":
this.redraw_players();
break;
case "EndDeal":
+ this.dealing = false;
this.active = user_action.username;
this.redraw_players();
break;
import { create_svg_element } from "./svg.js";
import { Game } from "./game.js";
import { Chatroom } from "./chatroom.js";
+import { break_lines } from "./words.js";
export class GameWithChat extends Game {
constructor(container, summary, actions, username, send, close) {
set_text(style, text) {
this.error.setAttribute("class", style);
- const lines = text.split("\n", this.error_text.length);
+ const MAX_LINE_LENGTH = 65;
+ const lines = break_lines(text, MAX_LINE_LENGTH).split("\n", this.error_text.length);
for (const text of this.error_text) {
text.textContent = "";
}