this.set_text("game-error", text);
}
+ player_angle(seat) {
+ const rel_seat = this.my_seat > seat ? this.num_seats + seat - this.my_seat : seat - this.my_seat;
+ if (this.num_seats % 4 === 0) {
+ if (rel_seat < this.num_seats / 4) {
+ return rel_seat * 2 * Math.PI / (this.num_seats + 2);
+ } else if (rel_seat >= this.num_seats / 4 && rel_seat <= 3 * this.num_seats / 4) {
+ return (rel_seat + 1) * 2 * Math.PI / (this.num_seats + 2);
+ } else {
+ return (rel_seat + 2) * 2 * Math.PI / (this.num_seats + 2);
+ }
+ } else {
+ return rel_seat * 2 * Math.PI / this.num_seats;
+ }
+ }
+
redraw_players() {
this.fold_control.classList.toggle("active", this.active === this.username && this.chips_to_call() > 0);
this.call_control.classList.toggle("active", this.active === this.username);
this.user_icons.delete(username);
} else {
const seat = this.seats.get(username);
- const angle = ((seat - this.my_seat) % this.num_seats) * 2 * Math.PI / this.num_seats;
+ const angle = this.player_angle(seat);
const x = 240 - 180 * Math.sin(angle);
const y = 240 + 120 * Math.cos(angle) + 60 * (Math.sign(Math.cos(angle)) || 1);
user.setAttribute("x", x);
const user = document.createElementNS(svgns, "text");
const text = document.createTextNode(username);
user.append(text);
- const angle = ((seat - this.my_seat) % this.num_seats) * 2 * Math.PI / this.num_seats;
+ const angle = this.player_angle(seat);
const x = 240 - 180 * Math.sin(angle);
const y = 240 + 120 * Math.cos(angle) + 60 * (Math.sign(Math.cos(angle)) || 1);
user.setAttribute("x", x);
redraw_cards() {
for (const [username, cards] of this.hands) {
const seat = this.seats.get(username);
- const angle = ((seat - this.my_seat) % this.num_seats) * 2 * Math.PI / this.num_seats;
+ const angle = this.player_angle(seat);
const offset = cards.length * 10;
let x = 227.5 + offset - 180 * Math.sin(angle);
const y = 210 + 120 * Math.cos(angle);
this.set_text("game-error", text);
}
+ player_angle(seat) {
+ const rel_seat = this.my_seat > seat ? this.num_seats + seat - this.my_seat : seat - this.my_seat;
+ if (this.num_seats % 4 === 0) {
+ if (rel_seat < this.num_seats / 4) {
+ return rel_seat * 2 * Math.PI / (this.num_seats + 2);
+ } else if (rel_seat >= this.num_seats / 4 && rel_seat <= 3 * this.num_seats / 4) {
+ return (rel_seat + 1) * 2 * Math.PI / (this.num_seats + 2);
+ } else {
+ return (rel_seat + 2) * 2 * Math.PI / (this.num_seats + 2);
+ }
+ } else {
+ return rel_seat * 2 * Math.PI / this.num_seats;
+ }
+ }
+
redraw_players() {
const active_player = this.call || this.active;
for (const [username, [icon, tricks, active]] of this.user_icons) {
this.user_icons.delete(username);
} else {
const seat = this.seats.get(username);
- const angle = ((seat - this.my_seat) % this.num_seats) * 2 * Math.PI / this.num_seats;
+ const angle = this.player_angle(seat);
const x = 240 - 180 * Math.sin(angle);
const y = 250 + 120 * Math.cos(angle) + 50 * Math.sign(Math.cos(angle));
icon.setAttribute("x", x);
const icon = document.createElementNS(svgns, "text");
const text = document.createTextNode(username);
icon.append(text);
- const angle = ((seat - this.my_seat) % this.num_seats) * 2 * Math.PI / this.num_seats;
+ const angle = this.player_angle(seat);
const x = 240 - 180 * Math.sin(angle);
const y = 250 + 120 * Math.cos(angle) + 50 * (Math.sign(Math.cos(angle)) || 1);
icon.setAttribute("x", x);
redraw_cards() {
for (const [username, cards] of this.hands) {
const seat = this.seats.get(username);
- const angle = ((seat - this.my_seat) % this.num_seats) * 2 * Math.PI / this.num_seats;
+ const angle = this.player_angle(seat);
const offset = cards.length * 10;
let x = 227.5 + offset - 180 * Math.sin(angle);
const y = 210 + 120 * Math.cos(angle);