Kaydet (Commit) ba62ebb6 authored tarafından Abdülkerim AKSAK's avatar Abdülkerim AKSAK

Kullanıcıların mesaj yollama ve alma kısmı tamamlandı.

üst 165f08d4
......@@ -2,8 +2,8 @@
const io = require("socket.io-client");
//Connect http://localhost:3000
//let game = io.connect("https://mangala-server.herokuapp.com/game");
let game = io.connect("http://localhost:3000/game");
let game = io.connect("https://mangala-server.herokuapp.com/game");
//let game = io.connect("http://localhost:3000/game");
const username = "Kerim";
......
......@@ -31,7 +31,7 @@ function tikla(id) {
// tiklanan kuyunun html' deki id sini alır
// Paramaters:
// id --> tiklanan kuyunun html' deki id sini alır ex.("user1hole5")
if (Number(id[4]) == 1 && player == Number(id[4])) {
if (Number(id[4]) == 1 && player == Number(id[4]) && id[10] == "x") {
if (user1hole[Number(id[9]) - 1].value != 0) {
player = 2;
dagit(Number(id[4]), Number(id[9]));
......@@ -40,16 +40,20 @@ function tikla(id) {
document.getElementById("user1").style.backgroundColor = waitcolor;
document.getElementById("user2").style.backgroundColor = playercolor;
}
//sendMessage(Number(id[9]));
}
} else if (Number(id[4]) == 2 && player == Number(id[4])) {
// player 2
if (user2hole[Number(id[9]) - 1].value != 0) {
player = 1;
dagit(Number(id[4]), Number(id[9]));
boncukCiz();
if (player == 1) {
document.getElementById("user1").style.backgroundColor = playercolor;
document.getElementById("user2").style.backgroundColor = waitcolor;
}
sendMessage(Number(id[9]));
}
}
}
......@@ -377,10 +381,10 @@ function overlayOda() {
document.getElementById("overlayOda").style.display = "block";
//ODA OLUSTURMA
randomKey = Math.random().toString(36).substr(2, 5); // odalar için random key
const odaOlusturContainer = document.getElementById("odaOlustur");
const odaOlusturBtn = document.getElementById("odaOlusturBtn");
odaOlusturBtn.onclick = () => {
randomKey = Math.random().toString(36).substr(2, 5); // odalar için random key
let elemt = document.createElement("p");
//Server kısmında key adında oda olustur.
console.log("girdi");
......@@ -416,18 +420,21 @@ function overlayOda() {
let odayaKatilInput = document.getElementById("odayaKatilInput");
odayaKatilBtn.onclick = () => {
let roomKey = odayaKatilInput.value;
randomKey = roomKey;
game.emit("joinRoom", roomKey, "Muaz"); //username dinamik olmalı!!!!
let elemt = document.createElement("p");
let elemt5 = document.createElement("p");
game.on("success", (roomKey) => {
elemt.textContent = roomKey + " odasına giriş yapıldı.";
elemt5.textContent = "Oda numarası: " + roomKey;
createNotification(roomKey + " odasına giriş yapıldı.");
});
game.on("err", (roomKey) => {
elemt.textContent = roomKey + " odasına giriş yapılamadı.";
elemt5.textContent = roomKey + " odasına giriş yapılamadı.";
createNotification(roomKey + " odasına giriş yapılamadı.");
});
//odaGirisi.appendChild(elemt);
odaOlusturContainer.appendChild(elemt5);
overlayOdaOff();
player = 1;
};
}
......@@ -445,3 +452,26 @@ const createNotification = (mesaj) => {
toasts.appendChild(notif);
setTimeout(() => notif.remove(), 3000);
};
// MESAJ YOLLAMA <OdayaKatıl>
function sendMessage(userHoleID) {
//let odayaKatilInput = document.getElementById("odayaKatilInput");
//let roomKey = odayaKatilInput.value; // Odaya katıl alanı için etkin
//let input = document.getElementById("mesajGonderOdayaKatilInput");
//let msg = input.value;
let msg = userHoleID;
//input.value = "";
game.emit("newMsg", "Muaz", msg, randomKey); // username dinamik olmalı!!!!
}
// MESAJI ALMA <OdaOlustur>
function addMessage(msg) {
let elemt = document.createElement("p");
elemt.textContent = `${username}:${msg}`;
container.appendChild(elemt);
}
game.on("newMessage", (msg) => {
console.log(`newMessage...: "${msg}" mesajı geldi.`);
tikla("user1hole" + msg + "x");
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment