Rename the game

This commit is contained in:
Andrea Cavalli 2024-05-24 11:59:08 +02:00
parent 8ef2658255
commit 75aaeaaaa9
6 changed files with 22 additions and 25 deletions

View File

@ -19,7 +19,7 @@
<vertx.version>4.5.7</vertx.version> <vertx.version>4.5.7</vertx.version>
<junit-jupiter.version>5.10.2</junit-jupiter.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> <launcher.class>io.vertx.core.Launcher</launcher.class>
</properties> </properties>

View File

@ -1,4 +1,4 @@
package it.cavallium.connect4x4; package it.cavallium.connect2x;
import io.vertx.core.DeploymentOptions; import io.vertx.core.DeploymentOptions;
import io.vertx.core.ThreadingModel; import io.vertx.core.ThreadingModel;

View File

@ -1,4 +1,4 @@
package it.cavallium.connect4x4; package it.cavallium.connect2x;
import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Single; import io.reactivex.rxjava3.core.Single;
@ -19,25 +19,19 @@ public class MainVerticle extends AbstractVerticle {
@Override @Override
public Completable rxStart() { public Completable rxStart() {
vertx.eventBus().consumer("connect4x4.move") vertx.eventBus().consumer("connect2x.move")
.handler(event -> System.out.println("Received: " + event.body())); .handler(event -> System.out.println("Received: " + event.body()));
var server = vertx.createHttpServer(); var server = vertx.createHttpServer();
SockJSHandler sockJSHandler = SockJSHandler.create(vertx); SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
SockJSBridgeOptions sockJSBridgeOptions = new SockJSBridgeOptions() SockJSBridgeOptions sockJSBridgeOptions = new SockJSBridgeOptions()
.addInboundPermitted(new PermittedOptions().setAddress("connect4x4.move")) .addInboundPermitted(new PermittedOptions().setAddress("connect2x.move"))
.addOutboundPermitted(new PermittedOptions().setAddress("connect4x4.moved")); .addOutboundPermitted(new PermittedOptions().setAddress("connect2x.moved"));
Router router = Router.router(vertx); Router router = Router.router(vertx);
router router
.get("/*") .get("/*")
.handler(ctx -> {
System.out.println(ctx.request().uri());
System.out.println(ctx.request().absoluteURI());
System.out.println(ctx.normalizedPath());
ctx.next();
})
.handler(StaticHandler .handler(StaticHandler
.create(FileSystemAccess.RELATIVE,"webroot") .create(FileSystemAccess.RELATIVE,"webroot")
//.setDirectoryListing(true) //.setDirectoryListing(true)

View File

@ -26,7 +26,7 @@ document.addEventListener("DOMContentLoaded", e => {
}; };
const connect4x4 = document.connect4x4 = { const connect2x = document.connect2x = {
clientId: randomID(), clientId: randomID(),
gameId: null gameId: null
} }
@ -44,7 +44,7 @@ document.addEventListener("DOMContentLoaded", e => {
hash = ""; hash = "";
} }
if (hash.length === 0) { if (hash.length === 0) {
if (connect4x4.gameId == null) { if (connect2x.gameId == null) {
onGameIdChange(randomID()); onGameIdChange(randomID());
} else { } else {
console.warn("Game hash unchanged."); console.warn("Game hash unchanged.");
@ -58,8 +58,8 @@ document.addEventListener("DOMContentLoaded", e => {
setTimeout(() => { setTimeout(() => {
document.location.href = redirectLink; document.location.href = redirectLink;
}, 5000); }, 5000);
} else if (connect4x4.gameId !== hash) { } else if (connect2x.gameId !== hash) {
if (connect4x4.gameId != null) { if (connect2x.gameId != null) {
console.log("Game id changed, reloading..."); console.log("Game id changed, reloading...");
document.location.reload(); document.location.reload();
} else { } else {
@ -71,7 +71,7 @@ document.addEventListener("DOMContentLoaded", e => {
} }
function onGameIdChange(gameId) { function onGameIdChange(gameId) {
connect4x4.gameId = gameId; connect2x.gameId = gameId;
console.info("Game ID", gameId); console.info("Game ID", gameId);
gameCode.innerText = gameId; gameCode.innerText = gameId;
const gameLink = `${document.location.origin}#${gameId}`; const gameLink = `${document.location.origin}#${gameId}`;
@ -81,8 +81,8 @@ document.addEventListener("DOMContentLoaded", e => {
if (navigator.share !== undefined) { if (navigator.share !== undefined) {
e.preventDefault(); e.preventDefault();
await navigator.share({ await navigator.share({
title: "Connect 4x4", title: "Connect 2x",
text: "Play Connect 4x4 game with me", text: "Play Connect 2x game with me",
url: gameLink url: gameLink
}).then(() => console.log("Shared!")).catch(err => { }).then(() => console.log("Shared!")).catch(err => {
console.error("Share failed", err); console.error("Share failed", err);
@ -106,12 +106,12 @@ document.addEventListener("DOMContentLoaded", e => {
eb.onopen = () => { eb.onopen = () => {
// set a handler to receive a message // 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)); console.log('received a message: ' + JSON.stringify(message));
}); });
// send a message // send a message
eb.send('connect4x4.move', {name: 'tim', age: 587}); eb.send('connect2x.move', {name: 'tim', age: 587});
} }
}) })

View File

@ -1,17 +1,20 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Connect 4x4</title> <title>Connect 2x</title>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/static/style.css"> <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/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='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> </head>
<body> <body>
<div id="main-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> <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> </div>
</body> </body>
</html> </html>

View File

@ -1,4 +1,4 @@
package it.cavallium.connect4x4; package it.cavallium.connect2x;
import io.vertx.core.Vertx; import io.vertx.core.Vertx;
import io.vertx.junit5.VertxExtension; import io.vertx.junit5.VertxExtension;