Rename the game
This commit is contained in:
parent
8ef2658255
commit
75aaeaaaa9
2
pom.xml
2
pom.xml
@ -19,7 +19,7 @@
|
||||
<vertx.version>4.5.7</vertx.version>
|
||||
<junit-jupiter.version>5.10.2</junit-jupiter.version>
|
||||
|
||||
<main.verticle>it.cavallium.connect4x4.MainVerticle</main.verticle>
|
||||
<main.verticle>it.cavallium.connect2x.MainVerticle</main.verticle>
|
||||
<launcher.class>io.vertx.core.Launcher</launcher.class>
|
||||
</properties>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.connect4x4;
|
||||
package it.cavallium.connect2x;
|
||||
|
||||
import io.vertx.core.DeploymentOptions;
|
||||
import io.vertx.core.ThreadingModel;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.connect4x4;
|
||||
package it.cavallium.connect2x;
|
||||
|
||||
import io.reactivex.rxjava3.core.Completable;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
@ -19,25 +19,19 @@ public class MainVerticle extends AbstractVerticle {
|
||||
@Override
|
||||
public Completable rxStart() {
|
||||
|
||||
vertx.eventBus().consumer("connect4x4.move")
|
||||
vertx.eventBus().consumer("connect2x.move")
|
||||
.handler(event -> System.out.println("Received: " + event.body()));
|
||||
|
||||
var server = vertx.createHttpServer();
|
||||
|
||||
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
|
||||
SockJSBridgeOptions sockJSBridgeOptions = new SockJSBridgeOptions()
|
||||
.addInboundPermitted(new PermittedOptions().setAddress("connect4x4.move"))
|
||||
.addOutboundPermitted(new PermittedOptions().setAddress("connect4x4.moved"));
|
||||
.addInboundPermitted(new PermittedOptions().setAddress("connect2x.move"))
|
||||
.addOutboundPermitted(new PermittedOptions().setAddress("connect2x.moved"));
|
||||
|
||||
Router router = Router.router(vertx);
|
||||
router
|
||||
.get("/*")
|
||||
.handler(ctx -> {
|
||||
System.out.println(ctx.request().uri());
|
||||
System.out.println(ctx.request().absoluteURI());
|
||||
System.out.println(ctx.normalizedPath());
|
||||
ctx.next();
|
||||
})
|
||||
.handler(StaticHandler
|
||||
.create(FileSystemAccess.RELATIVE,"webroot")
|
||||
//.setDirectoryListing(true)
|
@ -26,7 +26,7 @@ document.addEventListener("DOMContentLoaded", e => {
|
||||
};
|
||||
|
||||
|
||||
const connect4x4 = document.connect4x4 = {
|
||||
const connect2x = document.connect2x = {
|
||||
clientId: randomID(),
|
||||
gameId: null
|
||||
}
|
||||
@ -44,7 +44,7 @@ document.addEventListener("DOMContentLoaded", e => {
|
||||
hash = "";
|
||||
}
|
||||
if (hash.length === 0) {
|
||||
if (connect4x4.gameId == null) {
|
||||
if (connect2x.gameId == null) {
|
||||
onGameIdChange(randomID());
|
||||
} else {
|
||||
console.warn("Game hash unchanged.");
|
||||
@ -58,8 +58,8 @@ document.addEventListener("DOMContentLoaded", e => {
|
||||
setTimeout(() => {
|
||||
document.location.href = redirectLink;
|
||||
}, 5000);
|
||||
} else if (connect4x4.gameId !== hash) {
|
||||
if (connect4x4.gameId != null) {
|
||||
} else if (connect2x.gameId !== hash) {
|
||||
if (connect2x.gameId != null) {
|
||||
console.log("Game id changed, reloading...");
|
||||
document.location.reload();
|
||||
} else {
|
||||
@ -71,7 +71,7 @@ document.addEventListener("DOMContentLoaded", e => {
|
||||
}
|
||||
|
||||
function onGameIdChange(gameId) {
|
||||
connect4x4.gameId = gameId;
|
||||
connect2x.gameId = gameId;
|
||||
console.info("Game ID", gameId);
|
||||
gameCode.innerText = gameId;
|
||||
const gameLink = `${document.location.origin}#${gameId}`;
|
||||
@ -81,8 +81,8 @@ document.addEventListener("DOMContentLoaded", e => {
|
||||
if (navigator.share !== undefined) {
|
||||
e.preventDefault();
|
||||
await navigator.share({
|
||||
title: "Connect 4x4",
|
||||
text: "Play Connect 4x4 game with me",
|
||||
title: "Connect 2x",
|
||||
text: "Play Connect 2x game with me",
|
||||
url: gameLink
|
||||
}).then(() => console.log("Shared!")).catch(err => {
|
||||
console.error("Share failed", err);
|
||||
@ -106,12 +106,12 @@ document.addEventListener("DOMContentLoaded", e => {
|
||||
eb.onopen = () => {
|
||||
|
||||
// set a handler to receive a message
|
||||
eb.registerHandler('connect4x4.moved', (error, message) => {
|
||||
eb.registerHandler('connect2x.moved', (error, message) => {
|
||||
console.log('received a message: ' + JSON.stringify(message));
|
||||
});
|
||||
|
||||
// send a message
|
||||
eb.send('connect4x4.move', {name: 'tim', age: 587});
|
||||
eb.send('connect2x.move', {name: 'tim', age: 587});
|
||||
|
||||
}
|
||||
})
|
@ -1,17 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Connect 4x4</title>
|
||||
<title>Connect 2x</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
<script src="https://unpkg.io/sockjs-client@1.5.0/dist/sockjs.min.js"></script>
|
||||
<script src='https://unpkg.io/@vertx/eventbus-bridge-client.js@1.0.0-1/vertx-eventbus.js'></script>
|
||||
<script src='/static/connect4x4.js'></script>
|
||||
<script src='/static/connect2x.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main-body">
|
||||
<h1>Connect 4x4</h1>
|
||||
<h1>Connect 2x</h1>
|
||||
<p>Game code: <span id="game-code"></span> <a id="game-code-link" href="#">[share]</a> <a id="new-game" href="/">[new game]</a></p>
|
||||
<main id="board">
|
||||
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.connect4x4;
|
||||
package it.cavallium.connect2x;
|
||||
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.junit5.VertxExtension;
|
Loading…
Reference in New Issue
Block a user