2023-12-17 12:17:08 +01:00

131 lines
5.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Scontland Yard</title>
</head>
<body>
<div id="app" class="container">
<h1>Starting Position</h1>
<form v-on:submit.prevent="gameStart" name="form_start">
<p>
Number of players
<input name="police_players" type="number" min="3" max="6" required v-model="police_players">
</p>
<p>
Position of the tief
<input name="tief_posistion" type="number" min="1" max="199" required v-model="tief_start">
</p>
<button type="submit" v-bind:disabled="isGameStarted == true">Start the hunting</button>
</form>
<h1>Game Moves</h1>
<div v-show="isGameStarted" v-for="r in rounds">
Tief:
<span class="border border-primary rounded-circle" v-for="pos in r.tief">{{ pos }}</span>
Police:
<span class="border border-primary rounded-circle" v-for="pos in r.police">{{ pos }}</span>
Transport:
<span>{{ r.transport }}</span>
</div>
<div v-show="isGameStarted">
<form v-on:submit.prevent="gameRound" name="form_move">
Tief:
<span class="border border-primary rounded-circle" v-for="pos in round.tief">{{ pos }}</span>
Police:
<input v-for="(police, index) in round.police" v-model="round.police[index]" type="number" min="1" max="199" required name="police">
Transport:
<select v-model="round.transport" name="transport" required>
<option disabled value="">Please select one</option>
<option v-for="transport in listPossibleTransports(round)">{{ transport }}</option>
<option>hidden</option>
</select>
<button type="submit">Move</button>
</form>
</div>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
const app = Vue.createApp({
data() {
return {
police_players: 3,
tief_start: 0,
rounds: [],
round: {
tief: null,
police: null,
transport: null
},
graph: null
}
},
mounted() {
axios.get("data/graph.json")
.then(response => { this.graph = response.data })
.catch(err => console.log("Axios err: ", err))
},
methods: {
gameStart(e) {
console.log(this.tief_start)
this.round.police = new Array(this.police_players).fill(0);
this.round.transport = null;
this.round.tief = [this.tief_start];
},
gameRound(e) {
this.rounds.push({
'tief': this.round.tief.slice(),
'transport': this.round.transport,
'police': this.round.police.slice(),
})
// clear values
let tief = new Array()
for (vertex in this.round.tief) {
let tief_pos = this.round.tief[vertex]
// iterate edges
for (edge in this.graph[tief_pos].siblings) {
let sibbling = this.graph[tief_pos].siblings[edge]
if (this.round.police.includes(sibbling.vertex)) {
console.log("skip vertex, police there")
} else if (sibbling.edge == this.round.transport) {
tief.push(sibbling.vertex)
} else if (this.round.transport == 'hidden') {
tief.push(sibbling.vertex)
}
}
}
this.round.police = new Array(this.police_players).fill(0);
this.round.transport = null
this.round.tief = new Set(tief)
},
listPossibleTransports(round) {
let values = []
for (let item in round.tief) {
let tief_pos = round.tief[item].toString()
let vertex = this.graph[tief_pos]
values = values.concat(vertex['transport'])
}
values = new Set(values);
return values
}
},
computed: {
isGameStarted() {
return this.round.tief !== null
},
}
})
app.mount('#app')
</script>
</body>
</html>