Various adjustments
This commit is contained in:
parent
815481fcff
commit
2161f44895
13 changed files with 544 additions and 187 deletions
|
|
@ -1,7 +1,8 @@
|
|||
<template>
|
||||
<g class="button" @click="$emit('click')">
|
||||
<g class="button enabled" @click="$emit('click')">
|
||||
<rect :width="width" height="30" fill="gainsboro" stroke="black" rx="2" />
|
||||
<text text-anchor="middle" fill="black" :x="width / 2" y="16">{{ text }}</text>
|
||||
<text text-anchor="middle" fill="black" :x="width / 2" y="16">{{ getText() }}</text>
|
||||
<title>{{ text }}</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
|
|
@ -14,25 +15,9 @@ export default class Button extends Vue {
|
|||
|
||||
@Prop()
|
||||
width?: number;
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.button {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
rect {
|
||||
fill: silver;
|
||||
stroke: white;
|
||||
}
|
||||
|
||||
path {
|
||||
fill: white;
|
||||
}
|
||||
|
||||
text {
|
||||
fill: white;
|
||||
}
|
||||
getText() {
|
||||
return this.text!.length > 15 ? this.text?.substring(0, 5).concat('...') : this.text;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,34 +1,17 @@
|
|||
<template>
|
||||
<g class="button" @click="$emit('click')">
|
||||
<rect width="70" height="30" fill="gainsboro" stroke="black" rx="2" />
|
||||
<image x="10" y="10" width="10" height="10" href="../../icons/pass.svg" />
|
||||
<text text-anchor="middle" fill="black" x="42" y="16">Pass</text>
|
||||
<g :class="['button', { enabled }]" @click="$emit('click')">
|
||||
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
|
||||
<image x="15" y="8" width="10" height="10" href="../../icons/pass.svg" />
|
||||
<text text-anchor="middle" fill="black" x="47" y="13">Pass</text>
|
||||
<title>Pass turn</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component } from 'vue-property-decorator';
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class PassButton extends Vue {
|
||||
@Prop()
|
||||
enabled!: boolean;
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.button {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
rect {
|
||||
fill: silver;
|
||||
stroke: white;
|
||||
}
|
||||
|
||||
path {
|
||||
fill: white;
|
||||
}
|
||||
|
||||
text {
|
||||
fill: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1,34 +1,17 @@
|
|||
<template>
|
||||
<g class="button" @click="$emit('click')">
|
||||
<rect width="70" height="30" fill="gainsboro" stroke="black" rx="2" />
|
||||
<image x="6" y="6" width="16" height="16" href="../../icons/undo.svg" />
|
||||
<text text-anchor="middle" fill="black" x="42" y="16">Undo</text>
|
||||
<g :class="['button', { enabled }]" @click="$emit('click')">
|
||||
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
|
||||
<image x="11" y="4" width="16" height="16" href="../../icons/undo.svg" />
|
||||
<text text-anchor="middle" fill="black" x="47" y="13">Undo</text>
|
||||
<title>Undo last move</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component } from 'vue-property-decorator';
|
||||
import { Vue, Component, Prop } from 'vue-property-decorator';
|
||||
|
||||
@Component
|
||||
export default class UndoButton extends Vue {
|
||||
@Prop()
|
||||
enabled!: boolean;
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.button {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
rect {
|
||||
fill: silver;
|
||||
stroke: white;
|
||||
}
|
||||
|
||||
path {
|
||||
fill: white;
|
||||
}
|
||||
|
||||
text {
|
||||
fill: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</script>
|
||||
|
|
@ -1,19 +1,32 @@
|
|||
<template>
|
||||
<g :class="['placeholder', { enabled, overlapping }]">
|
||||
<rect :width="width" :height="height" />
|
||||
<g :class="['placeholder', { showDrop }]">
|
||||
<rect :width="width" :height="height" fill="black" />
|
||||
<title v-if="data && data.type == 'playerHarbor'">Harbor</title>
|
||||
<title v-else-if="data && data.type == 'factoryStore'">Factory Store</title>
|
||||
<title v-else-if="data && data.type == 'warehouseStore'">Harbor Store</title>
|
||||
<title v-else-if="data && data.type == 'factory'">Factory Slot</title>
|
||||
<title v-else-if="data && data.type == 'warehouse'">Warehouse Slot</title>
|
||||
<title v-else-if="data && data.type == 'supply'">Supply</title>
|
||||
<title v-else-if="data && data.type == 'openSea'">Open Sea</title>
|
||||
<title v-else-if="data && data.type == 'islandHarbor'">Island Harbor</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop, Watch, Inject } from 'vue-property-decorator';
|
||||
import { UIData } from '../types/ui-data';
|
||||
import { Vue, Component, Prop, Watch, Inject, InjectReactive } from 'vue-property-decorator';
|
||||
import { ContainerState, DropZoneType, PieceType, UIData } from '../types/ui-data';
|
||||
import { EventEmitter, Listener } from 'events';
|
||||
import Piece from './pieces/Piece.vue';
|
||||
import { Ship, Container, LoanCard } from './pieces';
|
||||
import { ShipPosition } from 'container-engine/src/gamestate';
|
||||
|
||||
@Component
|
||||
export default class DropZone extends Vue {
|
||||
@Inject()
|
||||
readonly ui!: UIData;
|
||||
|
||||
@InjectReactive()
|
||||
readonly player!: number;
|
||||
|
||||
@Inject()
|
||||
readonly communicator!: EventEmitter;
|
||||
|
||||
|
|
@ -36,8 +49,13 @@ export default class DropZone extends Vue {
|
|||
overlapping = false;
|
||||
|
||||
updateOverlapping(piece: Piece) {
|
||||
if (!this.enabled || !this.ui.dragged) {
|
||||
if (this.overlapping && this.enabled && !this.ui.dragged) {
|
||||
if (!this.enabled) {
|
||||
this.overlapping = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.ui.dragged) {
|
||||
if (this.overlapping) {
|
||||
if (this.accepts?.indexOf(piece.pieceType) != -1) {
|
||||
this.communicator.emit('pieceDrop', piece, this.data);
|
||||
}
|
||||
|
|
@ -47,6 +65,11 @@ export default class DropZone extends Vue {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!this.canDrop) {
|
||||
this.overlapping = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const rect1 = this.$el.getBoundingClientRect();
|
||||
const rect2 = this.ui.dragged!.$el.getBoundingClientRect();
|
||||
|
||||
|
|
@ -70,6 +93,62 @@ export default class DropZone extends Vue {
|
|||
this.communicator.off('draggedPosChanged', this.listener!);
|
||||
}
|
||||
}
|
||||
|
||||
get canDrop() {
|
||||
if (!this.enabled || !this.ui.dragged || this.accepts?.indexOf(this.ui.dragged.pieceType) == -1)
|
||||
return false;
|
||||
|
||||
if (this.ui.dragged.pieceType == PieceType.Loan) {
|
||||
const loan = this.ui.dragged as LoanCard;
|
||||
if (loan.owner == this.player) {
|
||||
if (this.data.type == DropZoneType.GetLoan)
|
||||
return false;
|
||||
} else {
|
||||
if (this.data.type == DropZoneType.PayLoan)
|
||||
return false;
|
||||
}
|
||||
} else if (this.ui.dragged.pieceType == PieceType.Ship) {
|
||||
const ship = this.ui.dragged as Ship;
|
||||
if (ship.position == ShipPosition.OpenSea) {
|
||||
if (this.data.type == DropZoneType.OpenSea)
|
||||
return false;
|
||||
|
||||
if (this.data.type == DropZoneType.IslandHarbor && ship.containers?.length == 0)
|
||||
return false;
|
||||
} else {
|
||||
if (this.data.type != DropZoneType.OpenSea)
|
||||
return false;
|
||||
}
|
||||
} else if (this.ui.dragged.pieceType == PieceType.Container) {
|
||||
const container = this.ui.dragged as Container;
|
||||
if (container.state == ContainerState.OnBoard) {
|
||||
if (this.data.type != DropZoneType.FactoryStore)
|
||||
return false;
|
||||
} else if (container.state == ContainerState.OnFactoryStore) {
|
||||
if (container.owner == this.player) {
|
||||
if (this.data.type != DropZoneType.FactoryStore && this.data.type != DropZoneType.Supply)
|
||||
return false;
|
||||
} else {
|
||||
if (this.data.type != DropZoneType.WarehouseStore)
|
||||
return false;
|
||||
}
|
||||
} else if (container.state == ContainerState.OnWarehouseStore) {
|
||||
if (container.owner == this.player) {
|
||||
if (this.data.type != DropZoneType.WarehouseStore && this.data.type != DropZoneType.Supply)
|
||||
return false;
|
||||
} else {
|
||||
if (this.data.type != DropZoneType.Ship)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
get showDrop() {
|
||||
return this.ui.helpOn && this.canDrop;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -77,7 +156,14 @@ export default class DropZone extends Vue {
|
|||
g.placeholder {
|
||||
rect {
|
||||
stroke: none;
|
||||
fill: none;
|
||||
fill: transparent;
|
||||
}
|
||||
|
||||
&.showDrop {
|
||||
rect {
|
||||
stroke: blue;
|
||||
stroke-width: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
&.canClick {
|
||||
|
|
|
|||
|
|
@ -3,15 +3,23 @@
|
|||
<div class="statusBar">
|
||||
{{ getStatusMessage() }}
|
||||
</div>
|
||||
<audio id="piece-drop" preload="none">
|
||||
<source src="/audio/piece-drop.mp3" type="audio/mpeg">
|
||||
</audio>
|
||||
<audio id="notification" preload="none">
|
||||
<source src="/audio/notification.mp3" type="audio/mpeg">
|
||||
<source src="/audio/notification.ogg" type="audio/ogg">
|
||||
</audio>
|
||||
<svg id="scene" viewBox="0 0 1250 650" height="650">
|
||||
<rect width="100%" height="100%" x="0" y="0" fill="lightblue" />
|
||||
<rect width="100%" height="100" x="0" y="0" fill="gray" />
|
||||
<rect width="390" height="220" x="860" y="430" fill="gray" />
|
||||
|
||||
<template v-if="isCurrentPlayer(player)">
|
||||
<PassButton transform="translate(1130, 15)" @click="pass()" />
|
||||
<UndoButton transform="translate(1130, 55)" @click="undo()" />
|
||||
</template>
|
||||
<PassButton transform="translate(1105, 5)" :enabled="canPass()" @click="pass()" />
|
||||
<UndoButton transform="translate(1105, 36)" :enabled="canUndo()" @click="undo()" />
|
||||
<LogButton transform="translate(1105, 67)" @click="showLog()" />
|
||||
<SoundButton transform="translate(1200, 15)" :isOn="soundOn" @click="toggleSound()" />
|
||||
<HelpButton transform="translate(1200, 55)" :isOn="ui.helpOn" @click="toggleHelp()" />
|
||||
|
||||
<DropZone transform="translate(5, 5)" :width="600" :height="90" :enabled="true" :accepts="'container'" :data="{ type: 'supply' }" />
|
||||
|
||||
|
|
@ -22,19 +30,25 @@
|
|||
:color="playerColors[i]"
|
||||
:transform="`translate(${250 * i}, 100)`"
|
||||
:owner="i"
|
||||
:currentPlayer="isCurrentPlayer(i)"
|
||||
:isCurrentPlayer="isCurrentPlayer(i)"
|
||||
:ended="gameEnded(G)"
|
||||
@pieceDrop="onPieceDrop" />
|
||||
<rect :key="'I' + i" width="390" height="41" x="860" :y="430 + i * 44" fill="none" stroke-width="3" :stroke="playerColors[i]" />
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<DropZone :transform="`translate(280, 425)`" :width="400" :height="225" :enabled="true" :accepts="'ship'" :data="{ type: 'openSea' }" />
|
||||
<DropZone :transform="`translate(770, 425)`" :width="480" :height="225" :enabled="true" :accepts="'ship'" :data="{ type: 'islandHarbor' }" />
|
||||
|
||||
<template v-for="ship in ships">
|
||||
<Ship :key="ship.id"
|
||||
:pieceId="ship.id"
|
||||
:targetState="{ x: ship.x, y: ship.y, rotate: ship.rotate }"
|
||||
:canDrag="canDragShip(ship)"
|
||||
:containers="ship.containers"
|
||||
:owner="ship.owner"
|
||||
:ownerName="G.players[ship.owner].name"
|
||||
:position="ship.position"
|
||||
:color="ship.color" />
|
||||
</template>
|
||||
|
||||
|
|
@ -63,6 +77,8 @@
|
|||
:canDrag="canDragWarehouse(warehouse)" />
|
||||
</template>
|
||||
|
||||
<DropZone :transform="`translate(1045, 5)`" :width="50" :height="90" :enabled="true" :accepts="'loan'" :data="{ type: 'payLoan' }" />
|
||||
|
||||
<template v-for="loanCard in loanCards">
|
||||
<LoanCard :key="loanCard.id"
|
||||
:targetState="{ x: loanCard.x, y: loanCard.y }"
|
||||
|
|
@ -73,15 +89,10 @@
|
|||
</template>
|
||||
|
||||
<template v-if="G">
|
||||
<PointCard :pointCard="G.players[player].pointCard" transform="translate(20, 440)" />
|
||||
<text x="20" y="620">Money: ${{ G.players[player].money }}</text>
|
||||
<text x="20" y="440">Money: ${{ G.players[player].money }}</text>
|
||||
<PointCard :pointCard="G.players[player].pointCard" transform="translate(20, 460)" />
|
||||
</template>
|
||||
|
||||
<DropZone :transform="`translate(280, 425)`" :width="400" :height="225" :enabled="true" :accepts="'ship'" :data="{ type: 'openSea' }" />
|
||||
<DropZone :transform="`translate(770, 425)`" :width="480" :height="225" :enabled="true" :accepts="'ship'" :data="{ type: 'islandHarbor' }" />
|
||||
|
||||
<DropZone :transform="`translate(1045, 10)`" :width="40" :height="70" :enabled="true" :accepts="'loan'" :data="{ type: 'payLoan' }" />
|
||||
|
||||
<template v-if="isCurrentPlayer(player)">
|
||||
<Calculator v-if="G.phase == 'bid'" transform="translate(140, 430)" @bid="bid($event)" />
|
||||
<template v-if="player == G.auctioningPlayer">
|
||||
|
|
@ -92,6 +103,48 @@
|
|||
</template>
|
||||
</template>
|
||||
|
||||
<template v-if="ui.helpOn">
|
||||
<template v-if="ui.dragged == null">
|
||||
<rect v-if="canBuyFactory('orange')" x="8" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canBuyFactory('brown')" x="128" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canBuyFactory('white')" x="248" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canBuyFactory('darkslategray')" x="368" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canBuyFactory('tan')" x="488" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<rect v-if="canBuyWarehouse()" x="615" y="10" width="424" height="72" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<rect v-if="canProduce('orange')" x="6" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canProduce('brown')" x="126" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canProduce('white')" x="246" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canProduce('darkslategray')" x="366" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canProduce('tan')" x="486" y="36" width="116" height="54" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<rect v-if="canGetLoan()" x="1045" y="5" width="50" height="90" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<rect v-if="canPass()" x="1104" y="4" width="82" height="28" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<rect v-if="canUndo()" x="1104" y="35" width="82" height="28" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<rect v-if="canPayLoan()" :x="200 + player * 250" y="123" width="47" height="77" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<g v-if="canSail()">
|
||||
<rect v-if="!ships[player].rotate" :x="ships[player].x - 5" :y="ships[player].y - 5" width="40" height="90" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-else :x="ships[player].x - 30" :y="ships[player].y + 20" width="90" height="40" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
</g>
|
||||
|
||||
<rect v-if="canArrangeFactory()" :x="6 + player * 250" y="158" width="188" height="44" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<rect v-if="canArrangeWarehouse()" :x="6 + player * 250" y="248" width="236" height="44" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
||||
<template v-if="G">
|
||||
<template v-for="(p, i) in G.players">
|
||||
<rect v-if="canBuyFromPlayerFactory(p)" :key="'PHF' + i" :x="6 + i * 250" y="158" width="188" height="44" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
<rect v-if="canBuyFromPlayerWarehouse(p)" :key="'PHW' + i" :x="6 + i * 250" y="248" width="236" height="44" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<use xlink:href="#moving" />
|
||||
<use xlink:href="#dragged" />
|
||||
</svg>
|
||||
|
|
@ -105,19 +158,13 @@ import { EventEmitter } from 'events';
|
|||
import { groupBy } from 'lodash';
|
||||
import { ContainerState, DropZoneType, Piece, PieceType, ShipType, UIData } from '../types/ui-data';
|
||||
import { ContainerColor, ShipPosition } from 'container-engine/src/gamestate';
|
||||
import { Container, Factory, Warehouse, Ship, LoanCard, Piece as PieceComponent } from './pieces';
|
||||
import { Button, PassButton, UndoButton, LogButton, SoundButton, HelpButton } from './buttons';
|
||||
import PlayerBoard from './PlayerBoard.vue';
|
||||
import Container from './pieces/Container.vue';
|
||||
import Factory from './pieces/Factory.vue';
|
||||
import Warehouse from './pieces/Warehouse.vue';
|
||||
import LoanCard from './pieces/LoanCard.vue';
|
||||
import PointCard from './PointCard.vue';
|
||||
import Ship from './pieces/Ship.vue';
|
||||
import Button from './buttons/Button.vue';
|
||||
import PassButton from './buttons/PassButton.vue';
|
||||
import UndoButton from './buttons/UndoButton.vue';
|
||||
import PieceComponent from './pieces/Piece.vue';
|
||||
import DropZone from './DropZone.vue';
|
||||
import Calculator from './Calculator.vue';
|
||||
import { LogMove } from 'container-engine/src/log';
|
||||
|
||||
@Component({
|
||||
created(this: Game) {
|
||||
|
|
@ -134,6 +181,9 @@ import Calculator from './Calculator.vue';
|
|||
Ship,
|
||||
PassButton,
|
||||
UndoButton,
|
||||
LogButton,
|
||||
SoundButton,
|
||||
HelpButton,
|
||||
DropZone,
|
||||
Calculator,
|
||||
Button
|
||||
|
|
@ -154,7 +204,9 @@ export default class Game extends Vue {
|
|||
|
||||
@Provide()
|
||||
ui: UIData = {
|
||||
waitingAnimations: 0
|
||||
dragged: null,
|
||||
waitingAnimations: 0,
|
||||
helpOn: true
|
||||
};
|
||||
|
||||
@Provide()
|
||||
|
|
@ -175,6 +227,8 @@ export default class Game extends Vue {
|
|||
|
||||
animationQueue: Array<Function> = [];
|
||||
|
||||
soundOn = true;
|
||||
|
||||
@Watch('state', { immediate: true })
|
||||
onStateChanged(state: GameState) {
|
||||
this.replaceState(state);
|
||||
|
|
@ -184,6 +238,21 @@ export default class Game extends Vue {
|
|||
this.G = JSON.parse(JSON.stringify(state));
|
||||
|
||||
this.createPieces();
|
||||
|
||||
if (this.soundOn && this.G?.log[this.G?.log.length - 1].type == 'move') {
|
||||
const move = (this.G?.log[this.G?.log.length - 1] as LogMove).move;
|
||||
if (move.name == MoveName.Pass && this.G.currentPlayer == this.player) {
|
||||
(document.getElementById('notification')!.cloneNode(true) as HTMLAudioElement).play();
|
||||
} else {
|
||||
if (move.name == MoveName.DomesticSale || move.name == MoveName.BuyWarehouse || move.name == MoveName.ArrangeWarehouse ||
|
||||
move.name == MoveName.BuyFactory || move.name == MoveName.BuyFromFactory || move.name == MoveName.Produce ||
|
||||
move.name == MoveName.Sail || move.name == MoveName.ArrangeFactory) {
|
||||
setTimeout(() => { (document.getElementById('piece-drop')!.cloneNode(true) as HTMLAudioElement).play(); }, 800);
|
||||
} else if (move.name == MoveName.Accept || move.name == MoveName.Decline || move.name == MoveName.BuyFromWarehouse) {
|
||||
(document.getElementById('piece-drop')!.cloneNode(true) as HTMLAudioElement).play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createPieces() {
|
||||
|
|
@ -301,8 +370,8 @@ export default class Game extends Vue {
|
|||
|
||||
// Loan Cards
|
||||
this.loanCards = [];
|
||||
this.G?.loansLeft.forEach(loan => {
|
||||
this.loanCards.push({ id: loan.id, x: 1050, y: 15, owner: -1 });
|
||||
this.G?.loansLeft.forEach((loan, i) => {
|
||||
this.loanCards.push({ id: loan.id, x: 1050 + i, y: 29 - i * 2, owner: -1 });
|
||||
});
|
||||
|
||||
this.G?.players.forEach((player, pi) => {
|
||||
|
|
@ -317,31 +386,17 @@ export default class Game extends Vue {
|
|||
const color = ['dodgerblue', 'red', 'yellow', 'limegreen', 'mediumorchid'][pi];
|
||||
switch (player.ship.shipPosition) {
|
||||
case ShipPosition.OpenSea:
|
||||
this.ships.push({ id: player.ship.piece.id, x: 380 + pi * 44, y: 480, rotate: 0, color, containers: player.ship.containers, owner: pi });
|
||||
this.ships.push({ id: player.ship.piece.id, x: 380 + pi * 44, y: 480, rotate: 0, color, containers: player.ship.containers, owner: pi, position: player.ship.shipPosition });
|
||||
break;
|
||||
|
||||
case ShipPosition.Island:
|
||||
this.ships.push({ id: player.ship.piece.id, x: 800, y: 410 + pi * 44, rotate: 90, color, containers: player.ship.containers, owner: pi });
|
||||
this.ships.push({ id: player.ship.piece.id, x: 800, y: 410 + pi * 44, rotate: 90, color, containers: player.ship.containers, owner: pi, position: player.ship.shipPosition });
|
||||
break;
|
||||
|
||||
case ShipPosition.Player0:
|
||||
this.ships.push({ id: player.ship.piece.id, x: 26 + 62 * (pi - 1), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
|
||||
break;
|
||||
|
||||
case ShipPosition.Player1:
|
||||
this.ships.push({ id: player.ship.piece.id, x: 276 + 62 * (pi > 1 ? pi - 1 : pi), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
|
||||
break;
|
||||
|
||||
case ShipPosition.Player2:
|
||||
this.ships.push({ id: player.ship.piece.id, x: 526 + 62 * (pi > 2 ? pi - 1 : pi), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
|
||||
break;
|
||||
|
||||
case ShipPosition.Player3:
|
||||
this.ships.push({ id: player.ship.piece.id, x: 776 + 62 * (pi > 3 ? pi - 1 : pi), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
|
||||
break;
|
||||
|
||||
case ShipPosition.Player4:
|
||||
this.ships.push({ id: player.ship.piece.id, x: 1026 + 62 * (pi > 4 ? pi - 1 : pi), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
|
||||
default:
|
||||
const otherPlayer = Number.parseInt(player.ship.shipPosition[12]);
|
||||
const harbor = Number.parseInt(player.ship.shipPosition[13]);
|
||||
this.ships.push({ id: player.ship.piece.id, x: 26 + 250 * otherPlayer + 62 * (harbor - 1), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi, position: player.ship.shipPosition });
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
@ -379,9 +434,11 @@ export default class Game extends Vue {
|
|||
}
|
||||
} else if (container.state == ContainerState.OnFactoryStore) {
|
||||
if (d.type == DropZoneType.FactoryStore) {
|
||||
const player = this.G!.players[this.G!.currentPlayer!];
|
||||
if (player.containersOnFactoryStore.find(c => c.piece.id == e.pieceId)!.price !== d.price)
|
||||
this.sendMove({ name: MoveName.ArrangeFactory, data: { id: container.pieceId, color: container.color }, extraData: { price: d.price } });
|
||||
if (this.G!.players[this.G!.currentPlayer!].containersOnFactoryStore.find(c => c.piece.id == e.pieceId)!.price === d.price) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendMove({ name: MoveName.ArrangeFactory, data: { id: container.pieceId, color: container.color }, extraData: { price: d.price } });
|
||||
} else if (d.type == DropZoneType.WarehouseStore) {
|
||||
this.sendMove({ name: MoveName.BuyFromFactory, data: { player: container.owner, piece: { id: container.pieceId, color: container.color } }, extraData: { price: d.price } });
|
||||
} else if (d.type == DropZoneType.Supply) {
|
||||
|
|
@ -389,6 +446,10 @@ export default class Game extends Vue {
|
|||
}
|
||||
} else if (container.state == ContainerState.OnWarehouseStore) {
|
||||
if (d.type == DropZoneType.WarehouseStore) {
|
||||
if (this.G!.players[this.G!.currentPlayer!].containersOnWarehouseStore.find(c => c.piece.id == e.pieceId)!.price === d.price) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendMove({ name: MoveName.ArrangeWarehouse, data: { id: container.pieceId, color: container.color }, extraData: { price: d.price } });
|
||||
} else if (d.type == DropZoneType.Ship) {
|
||||
this.sendMove({ name: MoveName.BuyFromWarehouse, data: { player: container.owner, piece: { id: container.pieceId, color: container.color } } });
|
||||
|
|
@ -401,9 +462,9 @@ export default class Game extends Vue {
|
|||
|
||||
case PieceType.Ship:
|
||||
const player = this.G!.players[this.G!.currentPlayer!];
|
||||
if (d.type === DropZoneType.PlayerHarbour) {
|
||||
if (player.ship.shipPosition !== 'player' + d.owner)
|
||||
this.sendMove({ name: MoveName.Sail, data: 'player' + d.owner });
|
||||
if (d.type.startsWith('playerHarbor')) {
|
||||
if (!player.ship.shipPosition.startsWith('playerHarbor'))
|
||||
this.sendMove({ name: MoveName.Sail, data: d.type });
|
||||
} else if (d.type === DropZoneType.OpenSea) {
|
||||
if (player.ship.shipPosition !== ShipPosition.OpenSea)
|
||||
this.sendMove({ name: MoveName.Sail, data: ShipPosition.OpenSea });
|
||||
|
|
@ -425,11 +486,15 @@ export default class Game extends Vue {
|
|||
break;
|
||||
}
|
||||
|
||||
// if (this.soundOn && e.pieceType != PieceType.Loan) {
|
||||
// (document.getElementById('piece-drop')!.cloneNode(true) as HTMLAudioElement).play();
|
||||
// }
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
getName(bidder) {
|
||||
return this.G!.players[bidder].name!.length > 8 ? this.G!.players[bidder].name?.substring(0, 5).concat('...') : this.G!.players[bidder].name;
|
||||
return this.G!.players[bidder].name;
|
||||
}
|
||||
|
||||
pass() {
|
||||
|
|
@ -471,12 +536,12 @@ export default class Game extends Vue {
|
|||
return ended(G);
|
||||
}
|
||||
|
||||
canDrag() {
|
||||
return this.G?.currentPlayer == this.player! && this.G.players[this.player!] && this.G.players[this.player!].availableMoves;
|
||||
canMove() {
|
||||
return this.G && this.G.currentPlayer == this.player! && this.G.players[this.player!] && this.G.players[this.player!].availableMoves;
|
||||
}
|
||||
|
||||
canDragContainer(container: Piece) {
|
||||
if (!this.canDrag())
|
||||
if (!this.canMove())
|
||||
return false;
|
||||
|
||||
const currentPlayer = this.G!.players[this.G!.currentPlayer!];
|
||||
|
|
@ -514,7 +579,7 @@ export default class Game extends Vue {
|
|||
}
|
||||
|
||||
canDragFactory(factory: Piece) {
|
||||
if (!this.canDrag())
|
||||
if (!this.canMove())
|
||||
return false;
|
||||
|
||||
const currentPlayer = this.G!.players[this.G!.currentPlayer!];
|
||||
|
|
@ -528,7 +593,7 @@ export default class Game extends Vue {
|
|||
}
|
||||
|
||||
canDragWarehouse(warehouse: Piece) {
|
||||
if (!this.canDrag())
|
||||
if (!this.canMove())
|
||||
return false;
|
||||
|
||||
const currentPlayer = this.G!.players[this.G!.currentPlayer!];
|
||||
|
|
@ -541,7 +606,7 @@ export default class Game extends Vue {
|
|||
}
|
||||
|
||||
canDragLoan(loanCard: Piece) {
|
||||
if (!this.canDrag())
|
||||
if (!this.canMove())
|
||||
return false;
|
||||
|
||||
const currentPlayer = this.G!.players[this.G!.currentPlayer!];
|
||||
|
|
@ -557,7 +622,7 @@ export default class Game extends Vue {
|
|||
}
|
||||
|
||||
canDragShip(ship: Piece) {
|
||||
if (!this.canDrag())
|
||||
if (!this.canMove())
|
||||
return false;
|
||||
|
||||
const currentPlayer = this.G!.players[this.G!.currentPlayer!];
|
||||
|
|
@ -566,6 +631,37 @@ export default class Game extends Vue {
|
|||
return availableMoves[MoveName.Sail] && this.isCurrentPlayer(ship.owner);
|
||||
}
|
||||
|
||||
canPass() {
|
||||
if (!this.canMove())
|
||||
return false;
|
||||
|
||||
const currentPlayer = this.G!.players[this.G!.currentPlayer!];
|
||||
const availableMoves = currentPlayer.availableMoves!;
|
||||
|
||||
return !!availableMoves[MoveName.Pass];
|
||||
}
|
||||
|
||||
canUndo() {
|
||||
if (!this.canMove())
|
||||
return false;
|
||||
|
||||
const currentPlayer = this.G!.players[this.G!.currentPlayer!];
|
||||
const availableMoves = currentPlayer.availableMoves!;
|
||||
|
||||
return !!availableMoves[MoveName.Undo];
|
||||
}
|
||||
|
||||
toggleSound() {
|
||||
this.soundOn = !this.soundOn;
|
||||
}
|
||||
|
||||
toggleHelp() {
|
||||
this.ui.helpOn = !this.ui.helpOn;
|
||||
}
|
||||
|
||||
showLog() {
|
||||
}
|
||||
|
||||
getStatusMessage() {
|
||||
if (this.G?.currentPlayer == undefined) {
|
||||
return 'Game ended!';
|
||||
|
|
@ -579,6 +675,118 @@ export default class Game extends Vue {
|
|||
isCurrentPlayer(player) {
|
||||
return this.G && this.G.currentPlayer === player;
|
||||
}
|
||||
|
||||
canBuyFactory(color) {
|
||||
return this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.BuyFactory] &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.BuyFactory]!.indexOf(color) != -1;
|
||||
}
|
||||
|
||||
canBuyWarehouse() {
|
||||
return this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.BuyWarehouse];
|
||||
}
|
||||
|
||||
canProduce(color) {
|
||||
return this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.Produce] &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.Produce]!.indexOf(color) != -1;
|
||||
}
|
||||
|
||||
canGetLoan() {
|
||||
return this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.GetLoan];
|
||||
}
|
||||
|
||||
canPayLoan() {
|
||||
return this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.PayLoan];
|
||||
}
|
||||
|
||||
canSail() {
|
||||
return this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.Sail];
|
||||
}
|
||||
|
||||
canArrangeFactory() {
|
||||
return this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.ArrangeFactory];
|
||||
}
|
||||
|
||||
canArrangeWarehouse() {
|
||||
return this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.ArrangeWarehouse];
|
||||
}
|
||||
|
||||
canBuyFromPlayerFactory(otherPlayer) {
|
||||
if (this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.BuyFromFactory]) {
|
||||
const buyable = this.G.players[this.player!].availableMoves![MoveName.BuyFromFactory]!.map(c => c.piece.id);
|
||||
const playerContainers = otherPlayer.containersOnFactoryStore.map(c => c.piece.id)
|
||||
return buyable.some(id => playerContainers.indexOf(id) !== -1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
canBuyFromPlayerWarehouse(otherPlayer) {
|
||||
if (this.G && this.G.currentPlayer == this.player! &&
|
||||
this.G.players[this.player!] &&
|
||||
this.G.players[this.player!].availableMoves &&
|
||||
this.G.players[this.player!].availableMoves![MoveName.BuyFromWarehouse]) {
|
||||
const buyable = this.G.players[this.player!].availableMoves![MoveName.BuyFromWarehouse]!.map(c => c.piece.id);
|
||||
const playerContainers = otherPlayer.containersOnWarehouseStore.map(c => c.piece.id)
|
||||
return buyable.some(id => playerContainers.indexOf(id) !== -1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
isDragging(pieceType) {
|
||||
return this.ui && this.ui.dragged != null && this.ui.dragged.pieceType == pieceType;
|
||||
}
|
||||
|
||||
draggedContainerType() {
|
||||
if (this.ui && this.ui.dragged != null && this.ui.dragged.pieceType == 'container') {
|
||||
const container = this.ui.dragged as Container;
|
||||
|
||||
if (container.owner == this.player) {
|
||||
if (container.state == ContainerState.OnFactoryStore) {
|
||||
return 'ownFactoryContainer'
|
||||
} else if (container.state == ContainerState.OnWarehouseStore) {
|
||||
return 'ownWarehouseContainer'
|
||||
}
|
||||
} else {
|
||||
if (container.state == ContainerState.OnBoard) {
|
||||
return 'boardContainer'
|
||||
} else if (container.state == ContainerState.OnFactoryStore) {
|
||||
return 'factoryContainer'
|
||||
} else if (container.state == ContainerState.OnWarehouseStore) {
|
||||
return 'warehouseContainer'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -599,11 +807,14 @@ export default class Game extends Vue {
|
|||
text-align: center;
|
||||
line-height: 40px;
|
||||
font-size: 20px;
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
#scene {
|
||||
margin-top: 40px;
|
||||
max-height: 100%;
|
||||
flex-grow: 1;
|
||||
margin: 40px auto auto auto;
|
||||
}
|
||||
|
||||
body,
|
||||
|
|
@ -633,13 +844,65 @@ text {
|
|||
&.canDrag {
|
||||
cursor: pointer;
|
||||
|
||||
& > circle,
|
||||
& > rect,
|
||||
& > path {
|
||||
&:hover {
|
||||
&:hover {
|
||||
& > circle,
|
||||
& > rect,
|
||||
& > path {
|
||||
stroke: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.button {
|
||||
&.enabled {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
rect {
|
||||
fill: silver;
|
||||
stroke: white;
|
||||
}
|
||||
|
||||
circle {
|
||||
fill: silver;
|
||||
stroke: white;
|
||||
}
|
||||
|
||||
line {
|
||||
stroke: white;
|
||||
}
|
||||
|
||||
image {
|
||||
filter: invert(1);
|
||||
}
|
||||
|
||||
text {
|
||||
fill: white;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:not(.enabled) {
|
||||
rect {
|
||||
stroke: silver;
|
||||
}
|
||||
|
||||
circle {
|
||||
stroke: silver;
|
||||
}
|
||||
|
||||
line {
|
||||
stroke: silver;
|
||||
}
|
||||
|
||||
image {
|
||||
filter: invert(0.75);
|
||||
}
|
||||
|
||||
text {
|
||||
fill: silver;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
<template>
|
||||
<g class="player-board">
|
||||
<rect width="250" height="20" x="0" y="0" :fill="color" />
|
||||
<text x="5" y="10" font-weight="600" fill="black" :text-decoration="currentPlayer ? 'underline' : ''">{{ getPlayerName() }}</text>
|
||||
<text x="5" y="10" font-weight="600" fill="black" :text-decoration="isCurrentPlayer ? 'underline' : ''">{{ getPlayerName() }}</text>
|
||||
|
||||
<rect width="250" height="180" x="0" y="20" fill="gray" />
|
||||
|
||||
<DropZone :transform="`translate(35, 200)`" :width="199" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor', owner: owner }" />
|
||||
<rect width="20" height="80" x="0" y="200" fill="gray" />
|
||||
<DropZone :transform="`translate(20, 200)`" :width="42" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '1', owner: owner }" />
|
||||
<rect width="20" height="80" x="62" y="200" fill="gray" />
|
||||
<DropZone :transform="`translate(82, 200)`" :width="42" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '2', owner: owner }" />
|
||||
<rect width="20" height="80" x="124" y="200" fill="gray" />
|
||||
<DropZone :transform="`translate(144, 200)`" :width="42" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '3', owner: owner }" />
|
||||
<rect width="20" height="80" x="186" y="200" fill="gray" />
|
||||
<DropZone :transform="`translate(206, 200)`" :width="43" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '4', owner: owner }" />
|
||||
|
||||
<DropZone :transform="`translate(200, 25)`" :width="40" :height="70" :enabled="currentPlayer" :accepts="'loan'" :data="{ type: 'getLoan' }" />
|
||||
<DropZone :transform="`translate(200, 23)`" :width="47" :height="77" :enabled="isCurrentPlayer" :accepts="'loan'" :data="{ type: 'getLoan' }" />
|
||||
|
||||
<DropZone :transform="`translate(13, 25)`" :width="174" :height="30" :enabled="currentPlayer" :accepts="'factory'" />
|
||||
<circle r="14" cx="28" cy="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="28" y="40" fill="lightgray">-</text>
|
||||
<circle r="14" cx="76" cy="40" fill="none" stroke="lightgray" />
|
||||
|
|
@ -22,47 +24,48 @@
|
|||
<text text-anchor="middle" x="124" y="40" fill="lightgray">9</text>
|
||||
<circle r="14" cx="172" cy="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="171" y="40" fill="lightgray">12</text>
|
||||
<DropZone :transform="`translate(13, 25)`" :width="174" :height="30" :enabled="isCurrentPlayer" :accepts="'factory'" :data="{ type: 'factory' }" />
|
||||
|
||||
<DropZone :transform="`translate(12, 64)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 1 }" />
|
||||
<rect x="8" y="60" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="28" y="90" fill="lightgray">1</text>
|
||||
<DropZone :transform="`translate(60, 64)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 2 }" />
|
||||
<DropZone :transform="`translate(8, 60)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 1 }" />
|
||||
<rect x="56" y="60" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="76" y="90" fill="lightgray">2</text>
|
||||
<DropZone :transform="`translate(108, 64)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 3 }" />
|
||||
<DropZone :transform="`translate(56, 60)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 2 }" />
|
||||
<rect x="104" y="60" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="124" y="90" fill="lightgray">3</text>
|
||||
<DropZone :transform="`translate(156, 64)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 4 }" />
|
||||
<DropZone :transform="`translate(104, 60)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 3 }" />
|
||||
<rect x="152" y="60" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="172" y="90" fill="lightgray">4</text>
|
||||
<DropZone :transform="`translate(152, 60)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 4 }" />
|
||||
|
||||
<DropZone :transform="`translate(7, 104)`" :width="234" :height="42" :enabled="currentPlayer" :accepts="'warehouse'" />
|
||||
<rect x="8" y="105" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="28" y="125" fill="lightgray">-</text>
|
||||
<rect x="56" y="105" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="76" y="125" fill="lightgray">4</text>
|
||||
<rect x="104" y="105" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="124" y="125" fill="lightgray">5</text>
|
||||
<rect x="152" y="105" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="172" y="125" fill="lightgray">6</text>
|
||||
<rect x="200" y="105" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="220" y="125" fill="lightgray">7</text>
|
||||
<g transform="translate(8, 105)"><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray" /></g>
|
||||
<text text-anchor="middle" x="28" y="128" fill="lightgray">-</text>
|
||||
<g transform="translate(56, 105)"><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray" /></g>
|
||||
<text text-anchor="middle" x="76" y="128" fill="lightgray">4</text>
|
||||
<g transform="translate(104, 105)"><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray" /></g>
|
||||
<text text-anchor="middle" x="124" y="128" fill="lightgray">5</text>
|
||||
<g transform="translate(152, 105)"><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray" /></g>
|
||||
<text text-anchor="middle" x="172" y="128" fill="lightgray">6</text>
|
||||
<g transform="translate(200, 105)"><path d="M20 0 L40 13 L40 40 L0 40 L0 13Z" fill="none" stroke="lightgray" /></g>
|
||||
<text text-anchor="middle" x="220" y="128" fill="lightgray">7</text>
|
||||
<DropZone :transform="`translate(7, 104)`" :width="234" :height="42" :enabled="isCurrentPlayer" :accepts="'warehouse'" :data="{ type: 'warehouse' }" />
|
||||
|
||||
<DropZone :transform="`translate(12, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 2 }" />
|
||||
<rect x="8" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="28" y="180" fill="lightgray">2</text>
|
||||
<DropZone :transform="`translate(60, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 3 }" />
|
||||
<DropZone :transform="`translate(8, 150)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 2 }" />
|
||||
<rect x="56" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="76" y="180" fill="lightgray">3</text>
|
||||
<DropZone :transform="`translate(108, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 4 }" />
|
||||
<DropZone :transform="`translate(56, 150)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 3 }" />
|
||||
<rect x="104" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="124" y="180" fill="lightgray">4</text>
|
||||
<DropZone :transform="`translate(156, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 5 }" />
|
||||
<DropZone :transform="`translate(104, 150)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 4 }" />
|
||||
<rect x="152" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="172" y="180" fill="lightgray">5</text>
|
||||
<DropZone :transform="`translate(204, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 6 }" />
|
||||
<DropZone :transform="`translate(152, 150)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 5 }" />
|
||||
<rect x="200" y="150" width="40" height="40" fill="none" stroke="lightgray" />
|
||||
<text text-anchor="middle" x="220" y="180" fill="lightgray">6</text>
|
||||
<DropZone :transform="`translate(200, 150)`" :width="40" :height="40" :enabled="isCurrentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 6 }" />
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
|
|
@ -83,7 +86,7 @@ export default class PlayerBoard extends Vue {
|
|||
player!: Player;
|
||||
|
||||
@Prop()
|
||||
currentPlayer?: boolean;
|
||||
isCurrentPlayer?: boolean;
|
||||
|
||||
@Prop()
|
||||
owner?: number;
|
||||
|
|
@ -97,7 +100,7 @@ export default class PlayerBoard extends Vue {
|
|||
|
||||
getPlayerName() {
|
||||
let name = '';
|
||||
if (this.currentPlayer) {
|
||||
if (this.isCurrentPlayer) {
|
||||
name += '• ';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['piece', {dragging}, {canDrag}]" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 10, 5)`">
|
||||
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 10, 5)`">
|
||||
<filter id="my-filter">
|
||||
<feComponentTransfer>
|
||||
<feFuncR type="linear" slope="0.5" />
|
||||
<feFuncG type="linear" slope="0.5" />
|
||||
<feFuncB type="linear" slope="0.5" />
|
||||
</feComponentTransfer>
|
||||
</filter>
|
||||
|
||||
<rect width="20" height="10" :fill="color" stroke="black" />
|
||||
|
||||
<title>Container</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['piece', {dragging}, {canDrag}]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<circle r="10" :fill="color" stroke="black" />
|
||||
|
||||
<title>Factory</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['loan', {dragging}, {canDrag}]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<g :id="elId" :class="['loan', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<rect width="30" height="60" fill="royalblue" stroke="white" stroke-width="2" rx="2" />
|
||||
<g transform="translate(33, -10) rotate(280, 15, 30)">
|
||||
<text text-anchor="middle" fill="white">Loan</text>
|
||||
</g>
|
||||
<title v-if="owner == -1">Get Loan</title>
|
||||
<title v-else-if="owner == player">Pay Loan</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['piece', {dragging}, {canDrag}]" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 15, 40)`">
|
||||
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 15, 40)`">
|
||||
<path d="M15 0 L30 10 L30 80 L0 80 L0 10Z" :fill="color" stroke="black" />
|
||||
<template v-for="(container, i) in containers">
|
||||
<Container :key="container.id"
|
||||
|
|
@ -8,13 +8,14 @@
|
|||
:canDrag="false"
|
||||
:color="container.color" />
|
||||
</template>
|
||||
<DropZone :width="30" :height="80" :enabled="true" :accepts="'container'" :data="{ type: 'ship' }" />
|
||||
<DropZone :width="30" :height="80" :enabled="player == owner" :accepts="'container'" :data="{ type: 'ship' }" />
|
||||
<title>{{ ownerName }}'s Ship</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { PieceType } from '@/types/ui-data';
|
||||
import { ContainerPiece } from 'container-engine/src/gamestate';
|
||||
import { Component, Mixins, Prop } from 'vue-property-decorator';
|
||||
import { ContainerPiece, ShipPosition } from 'container-engine/src/gamestate';
|
||||
import { Component, InjectReactive, Mixins, Prop } from 'vue-property-decorator';
|
||||
import Piece from './Piece.vue';
|
||||
import Container from './Container.vue';
|
||||
import DropZone from '../DropZone.vue';
|
||||
|
|
@ -29,11 +30,23 @@ import DropZone from '../DropZone.vue';
|
|||
}
|
||||
})
|
||||
export default class Ship extends Mixins(Piece) {
|
||||
@InjectReactive()
|
||||
readonly player!: number;
|
||||
|
||||
@Prop()
|
||||
color?: string;
|
||||
|
||||
@Prop()
|
||||
containers?: ContainerPiece[];
|
||||
|
||||
@Prop()
|
||||
owner?: number;
|
||||
|
||||
@Prop()
|
||||
ownerName?: string;
|
||||
|
||||
@Prop()
|
||||
position!: ShipPosition;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<template>
|
||||
<g :id="elId" :class="['piece', {dragging}, {canDrag}]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
|
||||
<path d="M15 0 L30 10 L30 30 L0 30 L0 10Z" fill="dimgray" stroke="black" />
|
||||
<title>Warehouse</title>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
|
|
|
|||
|
|
@ -14,36 +14,45 @@ function launchSelfContained(selector = '#app') {
|
|||
gameState.players[i].name = `Player ${i + 1}`;
|
||||
}
|
||||
|
||||
for (const player of gameState.players.slice(1)) {
|
||||
player.isAI = true;
|
||||
const playerIndex = 1;
|
||||
|
||||
for (const player of gameState.players) {
|
||||
if (player.id != playerIndex)
|
||||
player.isAI = true;
|
||||
}
|
||||
|
||||
emitter.on('move', async (move: Move) => {
|
||||
gameState = execMove(gameState, move, 0);
|
||||
console.log('move received', move);
|
||||
gameState = execMove(gameState, move, playerIndex);
|
||||
console.log('new game state', gameState);
|
||||
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, 0) : gameState));
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
||||
|
||||
let delay = 800;
|
||||
while (gameState.players.some(pl => pl.isAI && pl.availableMoves)) {
|
||||
gameState = moveAI(gameState, gameState.players.findIndex(pl => pl.isAI && pl.availableMoves));
|
||||
let newState = cloneDeep(strip ? stripSecret(gameState, 0) : gameState);
|
||||
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
||||
setTimeout(() => emitter.emit('state', newState), delay);
|
||||
delay += 800;
|
||||
}
|
||||
|
||||
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
||||
});
|
||||
|
||||
emitter.on('fetchSate', () => emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, 0) : gameState)));
|
||||
emitter.on('fetchSate', () => emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState)));
|
||||
|
||||
emitter.emit('player', { index: 0 });
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, 0) : gameState));
|
||||
emitter.emit('player', { index: playerIndex });
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
|
||||
|
||||
let delay = 800;
|
||||
while (gameState.players.some(pl => pl.isAI && pl.availableMoves)) {
|
||||
gameState = moveAI(gameState, gameState.players.findIndex(pl => pl.isAI && pl.availableMoves));
|
||||
let newState = cloneDeep(strip ? stripSecret(gameState, 0) : gameState);
|
||||
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
|
||||
setTimeout(() => emitter.emit('state', newState), delay);
|
||||
delay += 800;
|
||||
}
|
||||
|
||||
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
||||
}
|
||||
|
||||
export default launchSelfContained;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { ContainerPiece } from 'container-engine/src/gamestate';
|
||||
import { ContainerPiece, ShipPosition } from 'container-engine/src/gamestate';
|
||||
import PieceComponent from '../components/pieces/Piece.vue';
|
||||
|
||||
export interface UIData {
|
||||
dragged?: PieceComponent | null;
|
||||
waitingAnimations: number;
|
||||
helpOn: boolean;
|
||||
}
|
||||
|
||||
export interface Piece {
|
||||
|
|
@ -18,6 +19,7 @@ export interface Piece {
|
|||
|
||||
export interface ShipType extends Piece {
|
||||
containers: ContainerPiece[];
|
||||
position: ShipPosition;
|
||||
}
|
||||
|
||||
export enum PieceType {
|
||||
|
|
@ -30,7 +32,22 @@ export enum PieceType {
|
|||
|
||||
export enum DropZoneType {
|
||||
Ship = 'ship',
|
||||
PlayerHarbour = 'playerHarbor',
|
||||
PlayerHarbor11 = 'playerHarbor11',
|
||||
PlayerHarbor12 = 'playerHarbor12',
|
||||
PlayerHarbor13 = 'playerHarbor13',
|
||||
PlayerHarbor14 = 'playerHarbor14',
|
||||
PlayerHarbor21 = 'playerHarbor21',
|
||||
PlayerHarbor22 = 'playerHarbor22',
|
||||
PlayerHarbor23 = 'playerHarbor23',
|
||||
PlayerHarbor24 = 'playerHarbor24',
|
||||
PlayerHarbor31 = 'playerHarbor31',
|
||||
PlayerHarbor32 = 'playerHarbor32',
|
||||
PlayerHarbor33 = 'playerHarbor33',
|
||||
PlayerHarbor34 = 'playerHarbor34',
|
||||
PlayerHarbor41 = 'playerHarbor41',
|
||||
PlayerHarbor42 = 'playerHarbor42',
|
||||
PlayerHarbor43 = 'playerHarbor43',
|
||||
PlayerHarbor44 = 'playerHarbor44',
|
||||
Factory = 'factory',
|
||||
FactoryStore = 'factoryStore',
|
||||
Warehouse = 'warehouse',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue