Skip to content

Commit

Permalink
feat: Add increasing score by getting bouns
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
MohammadHossein committed May 27, 2021
1 parent d45d27e commit 2fad091
Show file tree
Hide file tree
Showing 26 changed files with 244 additions and 1,590 deletions.
328 changes: 217 additions & 111 deletions backend/index.js

Large diffs are not rendered by default.

File renamed without changes.
4 changes: 2 additions & 2 deletions backend/src/setup/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const production = process.env.NODE_ENV === 'production'
const defaultConfig = {
server: {
host: production ? 'localhost' : undefined, // all IPs
port: 3000,
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
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion frontend/7475741651600002657.svg

This file was deleted.

5 changes: 0 additions & 5 deletions frontend/GameAnalytics.js

This file was deleted.

Binary file removed frontend/Vazir-FD.ttf
Binary file not shown.
Binary file removed frontend/assets/123.png
Binary file not shown.
Binary file removed frontend/assets/i-demand-attention-244.mp3
Binary file not shown.
Binary file removed frontend/assets/line2.mp3
Binary file not shown.
Binary file not shown.
Binary file removed frontend/assets/what-302.mp3
Binary file not shown.
80 changes: 0 additions & 80 deletions frontend/data.js

This file was deleted.

25 changes: 17 additions & 8 deletions frontend/game/src/components/rectangle/rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import useStyle from './rectangle.style'
// localiztion
import t from './rectangle.local'
import {
addNewLine,
elementColorView,
getPlayerHasPermission,
increaseOpponentScore,
increasePlayerScore,
playerColorView,
} from '../../scenes/_slice/game.slice'
import { useSelector } from 'react-redux'
import { requestGift, sendBouns } from '../../services/backend/backend.service'
import { dispatch } from '../../setup/store/store'

export default function Rectangle({ i, j, lastMove }) {
const classes = useStyle()
Expand All @@ -29,14 +33,16 @@ export default function Rectangle({ i, j, lastMove }) {
if (i + 1 === lastI && j === lastJ) lastLineColor = downLineColor || ''
if (i === lastI && j - 1 === lastJ) lastLineColor = leftLineColor || ''
if (i === lastI && j + 1 === lastJ) lastLineColor = rightLineColor || ''
// if (i === 2 && j === 10) console.log(lastLineColor)

const backgroundColor = background
? `dark${background}`
? background
: !!topLineColor && !!rightLineColor && !!leftLineColor && !!downLineColor
? `dark${lastLineColor}`
? lastLineColor
: ''

if (!background && backgroundColor) {
console.log({ backgroundColor })
dispatch(addNewLine({ i, j, color: backgroundColor }))
}
if (
((i - 1 === lastI && j === lastJ) ||
(i + 1 === lastI && j === lastJ) ||
Expand All @@ -47,18 +53,21 @@ export default function Rectangle({ i, j, lastMove }) {
!!rightLineColor &&
!!leftLineColor &&
!!downLineColor &&
playerColor === lastColor
!playerHasPermission
) {
// console.log({ playerColor, lastColor, lastLineColor })
sendBouns(i, j, playerColor)
console.log({ playerColor, lastColor, background })
if (playerColor === lastColor) {
dispatch(increasePlayerScore())
sendBouns(i, j, playerColor)
} else dispatch(increaseOpponentScore())
}
return (
<div
className={classes.root}
style={{
gridColumn: `${j - 1} / ${j + 2}`,
gridRow: `${i - 1} / ${i + 2}`,
backgroundColor,
backgroundColor: `dark${backgroundColor}`,
}}
>
<span></span>
Expand Down
8 changes: 8 additions & 0 deletions frontend/game/src/scenes/_slice/game.slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
})

Expand All @@ -109,6 +115,8 @@ export const {
setPlayerLastMove,
setOpponentLastMove,
setRoomLastMove,
increasePlayerScore,
increaseOpponentScore,
} = actions
export default reducer

Expand Down
Loading

0 comments on commit 2fad091

Please sign in to comment.