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 @@ ...@@ -2,8 +2,8 @@
const io = require("socket.io-client"); const io = require("socket.io-client");
//Connect http://localhost:3000 //Connect http://localhost:3000
//let game = io.connect("https://mangala-server.herokuapp.com/game"); let game = io.connect("https://mangala-server.herokuapp.com/game");
let game = io.connect("http://localhost:3000/game"); //let game = io.connect("http://localhost:3000/game");
const username = "Kerim"; const username = "Kerim";
......
...@@ -31,7 +31,7 @@ function tikla(id) { ...@@ -31,7 +31,7 @@ function tikla(id) {
// tiklanan kuyunun html' deki id sini alır // tiklanan kuyunun html' deki id sini alır
// Paramaters: // Paramaters:
// id --> tiklanan kuyunun html' deki id sini alır ex.("user1hole5") // 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) { if (user1hole[Number(id[9]) - 1].value != 0) {
player = 2; player = 2;
dagit(Number(id[4]), Number(id[9])); dagit(Number(id[4]), Number(id[9]));
...@@ -40,16 +40,20 @@ function tikla(id) { ...@@ -40,16 +40,20 @@ function tikla(id) {
document.getElementById("user1").style.backgroundColor = waitcolor; document.getElementById("user1").style.backgroundColor = waitcolor;
document.getElementById("user2").style.backgroundColor = playercolor; document.getElementById("user2").style.backgroundColor = playercolor;
} }
//sendMessage(Number(id[9]));
} }
} else if (Number(id[4]) == 2 && player == Number(id[4])) { } else if (Number(id[4]) == 2 && player == Number(id[4])) {
// player 2
if (user2hole[Number(id[9]) - 1].value != 0) { if (user2hole[Number(id[9]) - 1].value != 0) {
player = 1; player = 1;
dagit(Number(id[4]), Number(id[9])); dagit(Number(id[4]), Number(id[9]));
boncukCiz(); boncukCiz();
if (player == 1) { if (player == 1) {
document.getElementById("user1").style.backgroundColor = playercolor; document.getElementById("user1").style.backgroundColor = playercolor;
document.getElementById("user2").style.backgroundColor = waitcolor; document.getElementById("user2").style.backgroundColor = waitcolor;
} }
sendMessage(Number(id[9]));
} }
} }
} }
...@@ -377,10 +381,10 @@ function overlayOda() { ...@@ -377,10 +381,10 @@ function overlayOda() {
document.getElementById("overlayOda").style.display = "block"; document.getElementById("overlayOda").style.display = "block";
//ODA OLUSTURMA //ODA OLUSTURMA
randomKey = Math.random().toString(36).substr(2, 5); // odalar için random key
const odaOlusturContainer = document.getElementById("odaOlustur"); const odaOlusturContainer = document.getElementById("odaOlustur");
const odaOlusturBtn = document.getElementById("odaOlusturBtn"); const odaOlusturBtn = document.getElementById("odaOlusturBtn");
odaOlusturBtn.onclick = () => { odaOlusturBtn.onclick = () => {
randomKey = Math.random().toString(36).substr(2, 5); // odalar için random key
let elemt = document.createElement("p"); let elemt = document.createElement("p");
//Server kısmında key adında oda olustur. //Server kısmında key adında oda olustur.
console.log("girdi"); console.log("girdi");
...@@ -416,18 +420,21 @@ function overlayOda() { ...@@ -416,18 +420,21 @@ function overlayOda() {
let odayaKatilInput = document.getElementById("odayaKatilInput"); let odayaKatilInput = document.getElementById("odayaKatilInput");
odayaKatilBtn.onclick = () => { odayaKatilBtn.onclick = () => {
let roomKey = odayaKatilInput.value; let roomKey = odayaKatilInput.value;
randomKey = roomKey;
game.emit("joinRoom", roomKey, "Muaz"); //username dinamik olmalı!!!! game.emit("joinRoom", roomKey, "Muaz"); //username dinamik olmalı!!!!
let elemt = document.createElement("p"); let elemt5 = document.createElement("p");
game.on("success", (roomKey) => { game.on("success", (roomKey) => {
elemt.textContent = roomKey + " odasına giriş yapıldı."; elemt5.textContent = "Oda numarası: " + roomKey;
createNotification(roomKey + " odasına giriş yapıldı."); createNotification(roomKey + " odasına giriş yapıldı.");
}); });
game.on("err", (roomKey) => { 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ı."); createNotification(roomKey + " odasına giriş yapılamadı.");
}); });
//odaGirisi.appendChild(elemt); //odaGirisi.appendChild(elemt);
odaOlusturContainer.appendChild(elemt5);
overlayOdaOff(); overlayOdaOff();
player = 1;
}; };
} }
...@@ -445,3 +452,26 @@ const createNotification = (mesaj) => { ...@@ -445,3 +452,26 @@ const createNotification = (mesaj) => {
toasts.appendChild(notif); toasts.appendChild(notif);
setTimeout(() => notif.remove(), 3000); 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