diff --git a/frontend/game/src/scenes/_slice/game.slice.js b/frontend/game/src/scenes/_slice/game.slice.js
index ed13e57..2acf7f4 100644
--- a/frontend/game/src/scenes/_slice/game.slice.js
+++ b/frontend/game/src/scenes/_slice/game.slice.js
@@ -91,6 +91,12 @@ const gameSlice = createSlice({
const { history } = action.payload
state.room.history = history
},
+ increasePlayerScore: (state, aciton) => {
+ state.player.score += 1
+ },
+ increaseOpponentScore: (state, aciton) => {
+ state.opponent.score += 1
+ },
},
})
@@ -109,6 +115,8 @@ export const {
setPlayerLastMove,
setOpponentLastMove,
setRoomLastMove,
+ increasePlayerScore,
+ increaseOpponentScore,
} = actions
export default reducer
diff --git a/frontend/gameRender.js b/frontend/gameRender.js
deleted file mode 100644
index 88987ba..0000000
--- a/frontend/gameRender.js
+++ /dev/null
@@ -1,365 +0,0 @@
-import { get, set, messages } from './data.js'
-import {
- addLineToSquare,
- checkCondition,
- findSpace,
- checkEnd,
- markLine,
- checkah,
- getNumberOfLine,
-} from './logic.js'
-import { send, requestGift, sendMessage } from './router.js'
-import { getUserFirstName } from './index.js'
-
-const oddScale = 1
-const evenScale = 4
-const paper = document.getElementById('paper')
-const header = document.getElementById('header')
-const xlines = document.getElementsByClassName('xline')
-const ylines = document.getElementsByClassName('yline')
-const input = document.getElementById('input')
-const sendButton = document.getElementsByClassName('send-button')[0]
-const sendPanel = document.getElementById('send-panel')
-const buttonContainer = document.getElementById('button-container')
-const yourMessage = document.getElementsByClassName('your-message')[0]
-const blue = document.getElementsByClassName('blue')[0]
-const red = document.getElementsByClassName('red')[0]
-const infoContainer = document.getElementById('info-container')
-const fullInformation = document.getElementsByClassName('full-information')[0]
-
-const audio = new Audio('./assets/line2.mp3')
-const sendAudio = new Audio('./assets/i-demand-attention-244.mp3')
-
-let timeout
-const sendMessageInitializer = () => {
- sendButton.addEventListener('click', () => {
- if (input.value) {
- clearTimeout(timeout)
- sendAudio.play()
- yourMessage.style.display = 'block'
- yourMessage.innerHTML = input.value
- sendMessage(input.value)
- input.value = ''
- setTimeout(() => (yourMessage.style.display = 'none'), 20000)
- }
- })
- input.addEventListener('keypress', (e) => {
- if (e.key === 'Enter') {
- if (input.value) {
- clearTimeout(timeout)
- sendAudio.play()
- yourMessage.style.display = 'block'
- yourMessage.innerHTML = input.value
- sendMessage(input.value)
- input.value = ''
- timeout = setTimeout(() => (yourMessage.style.display = 'none'), 20000)
- }
- }
- })
-}
-
-export const render = () => {
- createElements()
- stylePaperBy('row')
- stylePaperBy('column')
- lineInitializer(xlines, 'click')
- lineInitializer(ylines, 'click')
- lineInitializer(xlines, 'touch')
- lineInitializer(ylines, 'touch')
- changeLanguage('click')
- changeLanguage('touch')
- sendMessageInitializer()
- show('touch', header, infoContainer)
- show('click', header, infoContainer)
- show('touch', buttonContainer, sendPanel)
- show('click', buttonContainer, sendPanel)
- // show('click', red, fullInformation, 'red')
- // show('click', blue, fullInformation, 'blue')
-}
-
-const show = (event, key, value, className) => {
- key.addEventListener(event, () => {
- if (value.style.display === 'flex') value.style.display = 'none'
- else value.style.display = 'flex'
- if (className) {
- value.classList.remove(`${className === 'red' ? 'blue' : 'red'}-info`)
- value.classList.add(`${className}-info`)
- }
- })
-}
-
-const lineInitializer = (array, event) => {
- for (let i = 0; i < array.length; i++)
- array[i].addEventListener(event, () => {
- hitLine(array[i], get('color'))
- if (get('gift')) requestGift()
- set('gift', false)
- })
-}
-
-export const canHit = (line, color) => {
- return (
- (get('permission') || color === get('opponentColor')) &&
- get('role') !== 'subscriber' &&
- !get('waiting') &&
- !get('end') &&
- get('table').lines[getNumberOfLine(line)] !== 1
- )
-}
-
-export const helpLine = (line, color) => {
- colorLine(line, color)
- addLineToSquare(line)
- markLine(line)
- checkCondition(color)
- checkEnd()
-}
-
-export const hitLine = (line, color) => {
- if (canHit(line, color)) {
- helpLine(line, checkah())
- audio.play()
- send(line)
- set('permission', false)
- }
-}
-
-export const colorLine = (line, color) => {
- line.style.backgroundColor = color
-}
-
-const createElements = () => {
- for (let i = 1; i <= 2 * get('row') - 1; i++)
- for (let j = 1; j <= 2 * get('column') - 1; j++) {
- const div = document.createElement('div')
- div.setAttribute('class', 'grid-item')
- div.setAttribute('i', i)
- div.setAttribute('j', j)
- paper.appendChild(div)
- alignStyle(div, i, j)
- }
-}
-const stylePaperBy = (orientation) => {
- let template = ''
- for (let k = 0; k < 2 * get('row') - 1; k++)
- if (k % 2 === 0) template += oddScale + 'fr '
- else template += evenScale + 'fr '
- if (orientation === 'row') paper.style.gridTemplateRows = template
- else if (orientation === 'column') paper.style.gridTemplateColumns = template
-}
-
-const dotsData = {
- green: {
- count: 0,
- nextColor: 'orange',
- message: 'احسنت! یه مورد ویژگی جدید پیدا کردی',
- },
- orange: {
- count: 36,
- nextColor: 'rebeccapurple',
- message: 'رنگ تغییر یافت به بنفش',
- },
- rebeccapurple: {
- count: 0,
- nextColor: 'green',
- message: 'رنگ تغییر یافت به سبز',
- },
-}
-
-const clickDot = (div) => {
- const currentColor = div.style.backgroundColor
- console.log(currentColor)
- const { nextColor, message } = dotsData[currentColor]
- console.log(dotsData[currentColor])
- div.style.backgroundColor = nextColor
-
- dotsData[currentColor].count -= 1
- dotsData[nextColor].count += 1
- if (dotsData[nextColor].count === 36) {
- showMessage(message)
- buttonContainer.style.backgroundColor = nextColor
- header.style.backgroundColor = nextColor
- nextColor !== 'orange'
- ? (header.style.color = 'white')
- : (header.style.color = 'black')
- dotsData[nextColor].count = 0
- } else
- get('waiting')
- ? (header.innerHTML = 'در انتظار حریف...')
- : (header.innerHTML = 'نقطهبازی')
-}
-
-const initializeDot = (div) => {
- div.style.backgroundColor = 'orange'
- div.addEventListener('click', () => clickDot(div))
-}
-
-const alignStyle = (div, i, j) => {
- if ((i * j) % 2 === 1) setDivStyle(div, `${j}`, `${i}`, 'dot')
- else if (i % 2 === 1 && j % 2 !== 1)
- setDivStyle(div, `${j - 1} / ${j + 2}`, `${i}`, 'xline')
- else if (i % 2 !== 1 && j % 2 === 1)
- setDivStyle(div, `${j}`, `${i - 1} / ${i + 2}`, 'yline')
- else setDivStyle(div, `${j - 1} / ${j + 2}`, `${i - 1} / ${i + 2}`, 'space')
-}
-
-const setDivStyle = (div, col, row, styleClass) => {
- div.style.gridColumn = col
- div.style.gridRow = row
- div.setAttribute('class', styleClass)
- if (styleClass === 'space') div.setAttribute('line', 0)
- if (styleClass === 'dot') initializeDot(div)
-}
-
-export const updateScoreBoard = () => {
- const myElement = document.getElementsByClassName(get('color'))[0]
- const oppElement = document.getElementsByClassName(get('opponentColor'))[0]
- myElement.innerHTML = get('name') + ': ' + get('score')
- oppElement.innerHTML = get('opponentName') + ': ' + get('opponentScore')
-}
-
-export const updateScore = (color) => {
- if (get('color') === color) set('score', get('score') + 1)
- else if (get('opponentColor') === color)
- set('opponentScore', get('opponentScore') + 1)
- updateScoreBoard()
-}
-
-export const showTurn = () => {
- const isMyTurn = get('permission')
- const myColor = get('color')
- const oppColor = get('opponentColor')
- const myElement = document.getElementsByClassName(get('color'))[0]
- const oppElement = document.getElementsByClassName(get('opponentColor'))[0]
- myElement.classList.toggle(`active-${myColor}`, isMyTurn)
- oppElement.classList.toggle(`active-${oppColor}`, !isMyTurn)
- myElement.innerHTML = get('name') + ': ' + get('score')
- oppElement.innerHTML = get('opponentName') + ': ' + get('opponentScore')
-}
-
-export const showEnd = (winner) => {
- const myColor = get('color')
- document.body.style.backgroundColor = 'dark' + winner
- if (winner === myColor) {
- showMessage('winner')
- gameanalytics.GameAnalytics.addProgressionEvent(
- gameanalytics.EGAProgressionStatus.Fail,
- 'main',
- 'main',
- 'main',
- get('score')
- )
- gameanalytics.GameAnalytics.addProgressionEvent(
- gameanalytics.EGAProgressionStatus.Complete,
- 'main',
- 'main',
- 'main',
- get('opponentScore')
- )
- } else showMessage('loser')
- set('end', true)
-}
-
-export const colorBox = (i, j, color) => {
- const space = findSpace(i, j)
- space.style.backgroundColor = 'dark' + color
- if (color === 'red') space.innerHTML = 'ق'
- else space.innerHTML = 'آ'
-}
-
-export const getMesaageOfLanguge = (type) => {
- if (get('language') === 'english') {
- switch (type) {
- case 'waiting':
- header.innerHTML = messages.english.waiting
- break
- case 'header':
- header.innerHTML = messages.english.header
- break
- case 'winner':
- header.innerHTML = messages.english.winner
- break
- case 'loser':
- header.innerHTML = messages.english.loser
- break
- case 'resign':
- document.getElementById('resign').innerHTML = messages.english.resign
- break
- case 'language':
- document.getElementById('language').innerHTML =
- messages.english.language
- break
- case 'subscriber':
- header.innerHTML = messages.english.subscriber
- break
- }
- } else if (get('language') === 'persian') {
- switch (type) {
- case 'waiting':
- header.innerHTML = messages.persian.waiting
- break
- case 'header':
- header.innerHTML = messages.persian.header
- break
- case 'winner':
- header.innerHTML = messages.persian.winner
- break
- case 'loser':
- header.innerHTML = messages.persian.loser
- break
- case 'resign':
- document.getElementById('resign').innerHTML = messages.persian.resign
- break
- case 'language':
- document.getElementById('language').innerHTML =
- messages.persian.language
- break
- case 'subscriber':
- header.innerHTML = messages.persian.subscriber
- break
- default:
- header.innerHTML = type
- }
- }
-}
-
-export const showMessage = (message) => {
- if (message !== 'header') header.style.fontSize = '25px'
- else header.style.fontSize = '40px'
- getMesaageOfLanguge(message)
-}
-
-export const initializeTurn = () => {
- const myColor = get('color')
- if (myColor === 'red') {
- set('permission', true)
- set('opponentColor', 'blue')
- } else {
- set('permission', false)
- set('opponentColor', 'red')
- }
- set('name', getUserFirstName())
-}
-
-export const changeLanguage = (event) => {
- const language = document.getElementById('language')
- if (language !== null) {
- language.addEventListener(event, () => {
- if (get('language') === 'persian') {
- header.innerHTML = messages.english.header
- document.getElementById('resign').innerHTML =
- messages.english.resignButton
- document.getElementById('language').innerHTML =
- messages.english.languageButton
- set('language', 'english')
- } else {
- header.innerHTML = messages.persian.header
- document.getElementById('resign').innerHTML =
- messages.persian.resignButton
- document.getElementById('language').innerHTML =
- messages.persian.languageButton
- set('language', 'persian')
- }
- })
- }
-}
diff --git a/frontend/gameStyle.css b/frontend/gameStyle.css
deleted file mode 100644
index c8cc4a6..0000000
--- a/frontend/gameStyle.css
+++ /dev/null
@@ -1,295 +0,0 @@
-@font-face {
- font-family: Vazir;
- src: url('./Vazir-FD.ttf') format('truetype');
- font-weight: normal;
- font-style: normal;
-}
-* {
- font-family: Vazir;
-}
-body {
- width: 100vw;
- height: 100vh;
- margin: 0;
- background-color: gray;
- display: flex;
- flex-direction: column;
- user-select: none;
-}
-
-#root-container {
- margin: auto;
- display: flex;
- flex-direction: column;
- grid-template-columns: 1fr 1fr;
- box-shadow: 15px 10px 20px 0 #00000073;
- border-radius: 50px 50px 50px 50px;
-}
-#header {
- direction: rtl;
- display: flex;
- justify-content: center;
- align-items: center;
- color: black;
- cursor: pointer;
- grid-area: header;
- font-size: 40px;
- height: 80px;
- text-align: center;
- border-radius: 50px 50px 0 0;
- background-color: orange;
-}
-#info-container {
- grid-area: info-container;
- display: none;
- height: 40px;
- justify-content: center;
- align-items: center;
- background-color: wheat;
-}
-#github {
- height: 30px;
- margin-top: 10px;
-}
-#github:hover {
- height: 35px;
-}
-
-#paper {
- grid-area: paper;
- padding: 30px;
- display: grid;
- width: 65vmin;
- height: 65vmin;
- background-color: rgb(46, 46, 46);
-}
-
-.score-board {
- display: flex;
- width: 100%;
-}
-
-.score {
- text-align: center;
- text-shadow: thistle;
- color: white;
- font-size: 20px;
- margin-bottom: 0;
- width: 50%;
-}
-
-.blue {
- padding: auto;
-
- background-color: rgb(0, 0, 80);
- box-shadow: 0 5px rgb(0, 0, 80);
- transition: 2s;
-
- margin-bottom: 6px;
-}
-.active-blue {
- background-color: rgb(0, 0, 235) !important;
- box-shadow: 0 5px rgb(0, 0, 180) !important;
- transition: 2s;
-}
-
-.red {
- padding: auto;
-
- background-color: rgb(100, 0, 0);
- box-shadow: 0 5px rgb(100, 0, 0);
- transition: 2s;
-
- margin-bottom: 6px;
-}
-
-.active-red {
- background-color: red !important;
- box-shadow: 0 5px rgb(200, 0, 0) !important;
- transition: 2s;
-}
-
-.full-information {
- flex-grow: 1;
- width: 100%;
- height: 100px;
- display: none;
- color: white;
-}
-
-.red-info {
- background-color: rgb(100, 0, 0);
- direction: rtl;
-}
-
-.blue-info {
- background-color: rgb(0, 0, 100);
- direction: ltr;
-}
-
-.facts {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- padding: 5px;
- width: 100%;
-}
-
-.full-name {
- font-size: 20px;
-}
-
-.avatar {
- width: 80px;
- height: 80px;
- border-radius: 100%;
- padding: 10px;
- transition: all 0.35s ease;
-}
-
-.your-message {
- background-color: yellowgreen;
- position: absolute;
- right: 10px;
- top: 10px;
- padding: 5px;
- border-radius: 5px 5px 0 5px;
- transition: all 0.35s ease-in-out;
- display: none;
- direction: rtl;
-}
-.opponent-message {
- background-color: rgb(227, 255, 65);
- position: absolute;
- left: 10px;
- top: 10px;
- padding: 5px;
- border-radius: 5px 5px 5px 0;
- transition: all 0.35s ease-in-out;
- display: none;
- direction: rtl;
-}
-
-#send-panel {
- display: none;
- grid-area: message;
- width: 100%;
- height: 40px;
- background-color: wheat;
-}
-.send-button {
- background-color: orange;
- border: 2px solid wheat;
- width: 50px;
- cursor: pointer;
- border-radius: 10px;
-}
-
-#send:active {
- background-color: rgb(255, 145, 0);
-}
-
-.send-button > img {
- transform: scaleX(-1);
- height: 100%;
- width: 100%;
-}
-#input {
- direction: rtl;
- background-color: wheat;
- border: 2px solid wheat;
- flex-grow: 4;
-}
-
-#input:focus {
- outline: none;
-}
-
-#button-container {
- grid-area: buttons;
- height: 50px;
- display: flex;
- align-items: center;
- justify-content: center;
- background-color: orange;
- border-radius: 0 0 50px 50px;
- cursor: pointer;
-}
-#buttons {
- display: flex;
- flex-direction: row;
- justify-content: center;
- grid-area: area;
-}
-
-.button {
- color: black;
- font-size: 20px;
- cursor: pointer;
-
- margin: 5px;
- padding: 10px;
- border-radius: 30px;
- border-bottom: solid orangered;
- border-top: solid orangered;
-
- display: flex;
- justify-content: center;
- align-items: center;
-}
-.button:hover {
- font-size: 25px;
-}
-.grid-item {
- width: 100%;
- height: 100%;
- display: flex;
-}
-.xline {
- position: relative;
- height: 60%;
- width: 90%;
- transition: all 0.5s;
- border-radius: 15px;
- margin: auto;
-}
-.xline:hover {
- background-color: rgb(65, 65, 65);
-}
-.yline {
- position: relative;
- height: 90%;
- width: 60%;
- border-radius: 15px;
- margin: auto;
- transition: all 0.5s;
-}
-.yline:hover {
- background-color: rgb(65, 65, 65);
-}
-.dot {
- z-index: 1000;
- width: 100%;
- height: 100%;
- border-radius: 99999999px;
- background-color: yellow;
- margin: auto;
- box-shadow: 10px purple;
-}
-.dot:hover {
- background-color: orange;
-}
-.space {
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 180%;
- color: white;
- text-align: center;
- height: 90%;
- width: 90%;
- border-radius: 15px;
- margin: auto;
- transition: all 0.5s ease-in;
-}
diff --git a/frontend/icon.jpg b/frontend/icon.jpg
deleted file mode 100644
index 7e05c7c..0000000
Binary files a/frontend/icon.jpg and /dev/null differ
diff --git a/frontend/index.html b/frontend/index.html
deleted file mode 100644
index 237a963..0000000
--- a/frontend/index.html
+++ /dev/null
@@ -1,58 +0,0 @@
-
-
-
-
-
-
Dots and Boxes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
شما: چه حرکت خفنی! احسنت
-
محمدحسین: قربون شما!
-
-
-
-
diff --git a/frontend/index.js b/frontend/index.js
deleted file mode 100644
index bc0206f..0000000
--- a/frontend/index.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import { set } from './data.js'
-import { render } from './gameRender.js'
-
-const room =
- 'lsweaa123zenV34e.d5m361sskh91s1d0n4LnK383kJHiHgF8Nlj23esosdm1f45AXQwsl4dsw'
-
-gameanalytics.GameAnalytics.configureBuild('1.0.0')
-gameanalytics.GameAnalytics.initialize(
- 'e73000a93dcd27441dc06122212bcba0',
- '02cf80df151c71ff251b3e47e80bb29edbe2a87b'
-)
-
-const W = window.W
-if (W !== undefined) {
- W.setHooks({
- wappWillStart(start) {
- start()
- W.messages.sendMessageToCurrentChat('text', 'نقطه بازی کنیم؟')
- },
- })
-}
-
-export const roomId = () => {
- if (W !== undefined) {
- const roomId = W.wapp.getWisId()
- set('roomId', roomId)
- return roomId
- } else {
- set('roomId', room)
- return room
- }
-}
-export const getUserFirstName = () => {
- if (W !== undefined) return W.user.getFirstname()
- else return 'شما'
-}
-export const getUserId = () => {
- if (W !== undefined) {
- W.initializeAsync()
- const id = W.user.getId()
- set('userId', id)
- return id
- } else {
- const id = prompt('get number')
- set('userId', id)
- return id
- }
-}
-render()
diff --git a/frontend/logic.js b/frontend/logic.js
deleted file mode 100644
index bf041ef..0000000
--- a/frontend/logic.js
+++ /dev/null
@@ -1,93 +0,0 @@
-import { addCondition, get, set } from './data.js'
-import {
- colorBox,
- updateScore,
- showEnd,
- hitLine,
- helpLine,
-} from './gameRender.js'
-
-const spaces = document.getElementsByClassName('space')
-
-export const addLineToSquare = (line) => {
- const j = line.getAttribute('j')
- const i = line.getAttribute('i')
- if (line.className == 'yline') {
- if (j != 1) addCondition(i / 2, Math.floor(j / 2))
- if (j != 2 * get('row') - 1) addCondition(i / 2, Math.ceil(j / 2))
- } else if (line.className == 'xline') {
- if (i != 1) addCondition(Math.floor(i / 2), j / 2)
- if (i != 2 * get('column') - 1) addCondition(Math.ceil(i / 2), j / 2)
- }
-}
-
-export const checkah = () => {
- if (get('permission')) return get('color')
- else return get('opponentColor')
-}
-
-export const checkCondition = (color) => {
- const condition = get('table').squares
- for (let i = 0; i < condition.length; i++)
- for (let j = 0; j < condition[i].length; j++)
- if (condition[i][j] === 4) {
- colorBox(i, j, color)
- condition[i][j] = 100000
- updateScore(color)
- if (get('permission') && get('color') === color) set('gift', true)
- }
-}
-export const findSpace = (i, j) => {
- for (let k = 0; k < spaces.length; k++) {
- const x = spaces[k].getAttribute('i')
- const y = spaces[k].getAttribute('j')
- if (i == x / 2 && j == y / 2) return spaces[k]
- }
-}
-
-export const checkEnd = () => {
- if (
- get('opponentScore') + get('score') ==
- (get('row') - 1) * (get('row') - 1)
- ) {
- set('end', true)
- if (get('opponentScore') > get('score'))
- return showEnd(get('opponentColor'))
- else return showEnd(get('color'))
- }
-}
-
-export const recieve = (message, color) => {
- const audio = new Audio('./assets/line2.mp3')
- audio.play().then(console.log)
- helpLine(findLine(message), color)
-}
-
-export const getNumberOfLine = (line) => {
- let index
- const j = line.getAttribute('j')
- const i = line.getAttribute('i')
- if (i % 2 == 1) index = Math.floor(i / 2) * 11 + j / 2
- else index = (i - 1) * 5 + Math.floor(j / 2) + i / 2
- return index
-}
-
-export const markLine = (line) => {
- const index = getNumberOfLine(line)
- get('table').lines[index] = 1
-}
-
-export const findLine = (message) => {
- const i = message.x
- const j = message.y
- const type = message.kind
- const elements = document.getElementById('paper').childNodes
- for (let k = 0; k < elements.length; k++) {
- if (
- i === elements[k].getAttribute('i') &&
- j === elements[k].getAttribute('j') &&
- type === elements[k].getAttribute('class')
- )
- return elements[k]
- }
-}
diff --git a/frontend/router.js b/frontend/router.js
deleted file mode 100644
index e6ac20c..0000000
--- a/frontend/router.js
+++ /dev/null
@@ -1,137 +0,0 @@
-import { get, set } from './data.js'
-import { recieve } from './logic.js'
-import {
- initializeTurn,
- showMessage,
- showEnd,
- showTurn,
- updateScoreBoard,
-} from './gameRender.js'
-import { getUserFirstName, getUserId, roomId } from './index.js'
-
-const socket = io('https://noghteh-bazi.wapp.weblite.me/')
-// const socket = io('http://localhost:3000')
-
-socket.on('handshake', () => {
- socket.emit('handshake', roomId(), getUserId())
-})
-
-socket.on('color', (turn) => {
- set('color', turn)
- initializeTurn()
-})
-
-socket.on('wait', (type) => {
- if (type === 'wait') {
- showMessage('waiting')
- set('waiting', true)
- } else {
- gameanalytics.GameAnalytics.addProgressionEvent(
- gameanalytics.EGAProgressionStatus.Start,
- 'main',
- 'main',
- 'main'
- )
- showMessage('header')
- set('waiting', false)
- socket.emit('wait', get('userId'), get('roomId'), get('opponentColor'))
- socket.emit('name', get('userId'), get('roomId'))
- }
-})
-
-socket.on('watch', (history) => {
- if (history.length > 0) {
- for (let i = 0; i < history.length; i++) {
- recieve(history[i], history[i].color)
- }
- }
-})
-
-socket.on('introduce', () => {
- console.log('hello!')
- socket.emit('introduce', get('userId'), get('roomId'), getUserFirstName())
-})
-
-socket.on('name', (name) => {
- set('opponentName', name)
- showTurn()
- updateScoreBoard()
-})
-
-socket.on('role', (role, turn) => {
- if (turn === get('color')) set('permission', true)
- else set('permission', false)
- set('role', role)
- showMessage('subscriber')
- socket.emit('getname', get('roomId'))
-})
-
-socket.on('getname', (redName, blueName) => {
- if (get('role') === 'subscriber') {
- set('name', redName)
- set('opponentName', blueName)
- }
- showTurn()
- updateScoreBoard()
-})
-export const send = (line) => {
- const i = line.getAttribute('i')
- const j = line.getAttribute('j')
- const type = line.getAttribute('class')
- const message = {
- x: i,
- y: j,
- kind: type,
- }
- socket.emit('change', get('userId'), get('roomId'), message)
-}
-
-export const sendMessage = (message) => {
- socket.emit('message', get('roomId'), message)
-}
-
-let timeout
-
-socket.on('message', (message) => {
- clearTimeout(timeout)
- const opponentMessage = document.getElementsByClassName('opponent-message')[0]
- console.log(opponentMessage)
- opponentMessage.style.display = 'block'
- opponentMessage.innerHTML = message
- const sendAudio = new Audio('./assets/what-302.mp3')
- sendAudio.play()
- timeout = setTimeout(() => (opponentMessage.style.display = 'none'), 20000)
-})
-
-socket.on('change', (line, turn) => {
- if (get('role') === 'subscriber') {
- set('opponentColor', turn)
- if (turn === 'red') set('color', 'blue')
- else set('color', 'red')
- }
- if (get('opponentColor') === turn) set('permission', true)
- recieve(line, turn)
-})
-
-export const requestGift = () => {
- socket.emit('gift', get('userId'), get('roomId'))
-}
-socket.on('gift', () => {
- set('permission', !get('permission'))
-})
-
-export const resign = () => {
- showEnd(get('opponentColor'))
- socket.emit('resign', get('userId'), get('roomId'))
-}
-socket.on('resign', () => {
- showEnd(get('color'))
- socket.emit('disconnect', get('userId'), get('roomId'))
-})
-socket.on('permission', (permission) => {
- set('permission', permission)
-})
-
-socket.on('warning', (warning) => {
- console.log(warning)
-})
diff --git a/frontend/send-svgrepo-com.svg b/frontend/send-svgrepo-com.svg
deleted file mode 100644
index a7720fb..0000000
--- a/frontend/send-svgrepo-com.svg
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
diff --git a/frontend/weblite.manifest.json b/frontend/weblite.manifest.json
deleted file mode 100644
index 15a905a..0000000
--- a/frontend/weblite.manifest.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "name": "نقطهبازی",
- "id": "5f945d356cb1bf0d609c860a",
- "instantiable": true,
- "searchable": true,
- "fullscreen": true,
- "inline": false,
- "notifMessage": "نقطه به نقطه انتظار برای دیدن تو",
- "servIndexes": {
- "main": "index",
- "fullscreen": "index"
- },
- "version": "1.11.15"
-}
diff --git a/server/index.js b/server/index.js
deleted file mode 100644
index 61d3403..0000000
--- a/server/index.js
+++ /dev/null
@@ -1,298 +0,0 @@
-const app = require('express')()
-const http = require('http').createServer(app)
-const io = require('socket.io')(http, {
- cors: {
- origin: 'http://localhost:3000',
- methods: ['GET', 'POST'],
- },
-})
-const config = require('./src/setup/config')
-const rooms = []
-const users = []
-const createRoom = (roomId, socketId) => {
- const room = {
- id: roomId,
- userIds: [],
- subscriberIds: [],
- history: {},
- turn: 'red',
- isEnded: false,
- socketIds: [socketId],
- lastMove: {},
- }
- rooms.push(room)
- return room
-}
-
-const createUser = (userId, socketId) => {
- const user = {
- id: userId,
- score: '',
- roomIds: [],
- color: '',
- hasPermission: false,
- role: '',
- connection: false,
- socketId,
- }
- users.push(user)
- return user
-}
-
-// const getUserById = id =>
-
-const findRoomById = (roomId) => rooms.find((room) => room.id === roomId)
-const findUserById = (userId, roomId) =>
- users.find((user) => {
- const result = !!(user.id === userId && user.roomIds.includes(roomId))
- return result
- })
-
-const findUserBySocketId = (socketId) =>
- users.find((user) => user.socketId === socketId)
-const findRoomBySocketId = (socketId) =>
- rooms.find((room) => room.socketIds.includes(socketId))
-
-const configUser = ({
- user,
- room,
- color,
- hasPermission,
- role,
- connection,
- socketId,
-}) => {
- user.roomIds.push(room.id)
- user.color = color
- user.hasPermission = hasPermission
- user.role = role
- user.connection = connection
- user.socketId = socketId
-}
-
-const configRoom = {}
-
-const hostFirstUser = (room, user, socket) => {
- console.log(
- `hosting first user with userId: ${user.id} in room with roomId: ${room.id}`
- )
- configUser({
- user,
- room,
- color: 'red',
- hasPermission: true,
- role: 'player',
- connection: true,
- socketId: socket.id,
- })
- room.turn = 'red'
- room.userIds.push(user.id)
- room.socketIds.push(socket.id)
- socket.emit('hasPermission', user.hasPermission)
- socket.join(room.id)
- socket.emit('color', 'red')
- socket.emit('mustWait', true)
-}
-
-const hostSecondUser = (room, user, socket) => {
- console.log(
- `hosting second user with userId: ${user.id} in room with roomId: ${room.id}`
- )
-
- configUser({
- user,
- room,
- color: undefined,
- hasPermission: false,
- role: 'player',
- connection: true,
- socketId: socket.id,
- })
- const secondUser = findUserById(
- room.userIds[0] === user.id ? room.userIds[1] : room.userIds[0],
- room.id
- )
- console.log('roomTurn: ', room.turn)
- if (secondUser && secondUser.color === 'red') user.color = 'blue'
- else user.color = 'red'
- user.hasPermission = room.turn === user.color
- console.log('user has permission? ', user.hasPermission)
- if (!room.userIds.includes(user.id)) room.userIds.push(user.id)
- if (!room.socketIds.includes(socket.id)) room.socketIds.push(socket.id)
-
- socket.emit('color', user.color)
- socket.emit('hasPermission', user.hasPermission)
- socket.emit('watch', room.history)
- socket.join(room.id)
- io.to(room.id).emit('mustWait', false)
- io.to(room.id).emit('introduce', 'hello')
-}
-
-const hostSubscriber = (room, user, socket) => {
- console.log(
- `hosting subscriber with userId: ${user.id} in room with roomId: ${room.id}`
- )
- configUser({
- user,
- room,
- color: undefined,
- hasPermission: false,
- role: 'subscriber',
- connection: true,
- socketId: socket.id,
- })
- room.subscriberIds.push(user.id)
- socket.join(room.id)
- socket.emit('role', 'subscriber', room.turn)
- socket.emit('watch', room.history)
-}
-
-const directUserToRoom = (roomId, userId, socket) => {
- const room = findRoomById(roomId) || createRoom(roomId, socket.id)
- const user = findUserById(userId, roomId) || createUser(userId, socket.id)
- if (room.userIds.includes(user.id)) {
- console.log('direct to room', room, user)
- socket.emit('warning', 'multiple device')
- socket.disconnect(true)
- } else {
- switch (room.userIds.length) {
- case 0:
- hostFirstUser(room, user, socket)
- break
- case 1:
- hostSecondUser(room, user, socket)
- break
- default:
- if (!!findUserById(userId, roomId)) hostSecondUser(room, user, socket)
- else hostSubscriber(room, user, socket)
- break
- }
- }
-}
-
-const checkValidation = (room, user, type) => {
- const result =
- user && room && user.connection && !room.end && user.role === 'player'
- if (type === 'change') {
- console.log(
- `check validation user id: ${user.id} hasPermission is: ${user.hasPermission}`
- )
- return user.hasPermission && room.turn === user.color && result
- } else {
- console.log(
- `check validation user id: ${user.id}`,
- !user.hasPermission,
- room.turn !== user.color,
- result
- )
- return !user.hasPermission && room.turn !== user.color && result
- }
-}
-
-const changeTurn = (room, userId) => {
- if (room && room.turn === 'red') room.turn = 'blue'
- else if (room && room.turn === 'blue') room.turn = 'red'
- for (let i = 0; i < room.userIds.length; i++) {
- const user = findUserById(room.userIds[i], room.id)
- if (user.id === userId) user.hasPermission = false
- else user.hasPermission = true
- }
- return true
-}
-const check = (room, user, type) => {
- if (checkValidation(room, user, type)) return changeTurn(room, user.id)
- return false
-}
-
-io.on('connection', (socket) => {
- socket.emit('handshake', 'welcome! give me your room id!')
- socket.on('handshake', (input) => {
- const { roomId, userId } = input
- directUserToRoom(roomId, userId, socket)
- })
- socket.on('introduce', (userId, roomId) =>
- socket.broadcast.to(roomId).emit('name', userId)
- )
- socket.on('disconnect', () => {
- const user = findUserBySocketId(socket.id)
- const room = findRoomBySocketId(socket.id)
- console.log(
- `user with ${user ? 'user' : 'socket'}id ${
- user ? user.id : socket.id
- } disconnected`
- )
- if (user) user.connection = false
- if (user && user.role === 'player') {
- room.userIds.splice(room.userIds.indexOf(user.id), 1)
- socket.broadcast.to(room.id).emit('mustWait', true)
- }
- })
- socket.on('change', (userId, roomId, line) => {
- const room = findRoomById(roomId)
- const user = findUserById(userId, roomId)
- console.log('new line arrived: ', line)
- if (check(room, user, 'change')) {
- const { i, j, color } = line
- line.color = user.color
- room.lastMove = line
- room.history[i] = { ...room.history[i] }
- room.history[i][j] = color
- socket.broadcast.to(room.id).emit('change', line, color)
- } else socket.emit('warning', 'warning')
- })
- socket.on('bouns', (roomId, userId, bouns) => {
- const room = findRoomById(roomId)
- const user = findUserById(userId, roomId)
- if (user && user.color === bouns.color) {
- const { i, j, color } = bouns
- if (room.history[i] && room.history[i][j]) {
- } else {
- console.log(`new bouns arrived:`, bouns, `from user:`, user.id)
- room.history[i] = { ...room.history[i] }
- room.history[i][j] = color
-
- // sending gift!
- if (room) room.turn = user.color
- for (let i = 0; i < room.userIds.length; i++) {
- const user = findUserById(room.userIds[i], room.id)
- if (user.id === userId) user.hasPermission = true
- else user.hasPermission = false
- }
- io.to(roomId).emit('gift', userId)
- }
- }
- })
- socket.on('gift', (userId, roomId) => {
- const room = findRoomById(roomId)
- const user = findUserById(userId, roomId)
- console.log('new gift request arrived by user id:', userId)
-
- if (check(room, user, 'gift')) io.to(room.id).emit('gift')
- else socket.emit('warning', 'warning')
- })
-
- socket.on('resign', (userId, roomId) => {
- const room = findRoomById(roomId)
- const user = findUserById(userId, roomId)
- room.end = true
- user.connection = false
- socket.broadcast.to(room.id).emit('resign', 'salam')
- })
-
- socket.on('getname', (roomId) => {
- const room = findRoomById(roomId)
- let redName, blueName
- for (let i = 0; i < room.userIds.length; i++) {
- const element = room.userIds[i]
- if (element.color === 'red') redName = element.name
- else blueName = element.name
- }
- socket.emit('getname', redName, blueName)
- })
-
- socket.on('message', (roomId, message) => {
- const room = findRoomById(roomId)
- socket.broadcast.to(room.id).emit('message', message)
- })
-})
-http.listen(config.server.port, () => {})
diff --git a/server/src/setup/config.js b/server/src/setup/config.js
deleted file mode 100644
index 862877c..0000000
--- a/server/src/setup/config.js
+++ /dev/null
@@ -1,25 +0,0 @@
-const R = require('ramda')
-const fse = require('fs-extra')
-
-const production = process.env.NODE_ENV === 'production'
-
-const defaultConfig = {
- server: {
- host: production ? 'localhost' : undefined, // all IPs
- port: 13797,
- },
-}
-
-const getLocalConfig = () => {
- try {
- const config = fse.readJsonSync(process.env.WEBLITE_CONFIG_PATH)[
- 'dots-and-boxes'
- ]
- if (!R.is(Object, config) || R.is(Array, config)) throw new TypeError()
- return config
- } catch (e) {
- return {}
- }
-}
-
-module.exports = R.mergeDeepRight(defaultConfig, getLocalConfig())