@@ -197,6 +206,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
+ isLoggingOut: {
+ type: Boolean,
+ default: false,
+ },
})
const emit = defineEmits(['close', 'play-again'])
diff --git a/frontend/src/components/layout/NavBar.vue b/frontend/src/components/layout/NavBar.vue
index 90fa378..817c530 100644
--- a/frontend/src/components/layout/NavBar.vue
+++ b/frontend/src/components/layout/NavBar.vue
@@ -15,14 +15,16 @@
+
Login
+
- Logout
+ Logout
Profile
@@ -34,6 +36,8 @@
+
\ No newline at end of file
diff --git a/frontend/src/pages/game/SinglePlayerGamePage.vue b/frontend/src/pages/game/SinglePlayerGamePage.vue
index ec6a4d6..bd93057 100644
--- a/frontend/src/pages/game/SinglePlayerGamePage.vue
+++ b/frontend/src/pages/game/SinglePlayerGamePage.vue
@@ -1,27 +1,43 @@
-
-
+
+
+
+
+
+
A preparar baralho...
+
+
+
-
diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js
index 983f8fd..2dc88cd 100644
--- a/frontend/src/router/index.js
+++ b/frontend/src/router/index.js
@@ -15,10 +15,12 @@ const router = createRouter({
routes: [
{
path: '/',
+ name: 'home',
component: HomePage,
},
{
path: '/login',
+ name: 'login',
component: LoginPage,
},
{
@@ -68,15 +70,13 @@ const router = createRouter({
})
router.beforeEach((to, from, next) => {
- if (to.meta.requiresAuth) {
- const token = localStorage.getItem('token') // Ou useAuthStore().token
+ const requiresAuth = to.matched.some((record) => record.meta.requiresAuth)
+
+ if (requiresAuth) {
+ const token = localStorage.getItem('token')
if (!token) {
- toast.error('Acesso Negado', {
- description: 'Precisas de fazer login para aceder ao jogo.',
- duration: 4000,
- })
- return next({ name: 'home' })
+ return next({ name: 'login' })
}
}
next()
diff --git a/frontend/src/stores/bisca.js b/frontend/src/stores/bisca.js
index 49a7c79..37a5903 100644
--- a/frontend/src/stores/bisca.js
+++ b/frontend/src/stores/bisca.js
@@ -4,7 +4,9 @@ import { ref } from 'vue'
export const useBiscaStore = defineStore('bisca', () => {
const isDealing = ref(false)
const isGameRunning = ref(false)
+ const isGameOver = ref(false)
const gameType = ref(3)
+ const isLoggingOut = ref(false)
const deck = ref([])
const playerHand = ref([])
@@ -15,6 +17,11 @@ export const useBiscaStore = defineStore('bisca', () => {
const currentTurn = ref('player')
+ const playerTricks = ref(0)
+ const opponentTricks = ref(0)
+
+ const winner = ref(null)
+
const table = ref({
playerCard: null,
opponentCard: null,
@@ -27,9 +34,13 @@ export const useBiscaStore = defineStore('bisca', () => {
isDealing.value = true
isGameRunning.value = true
gameType.value = type
+ isGameOver.value = false
+ isLoggingOut.value = false
playerScore.value = 0
opponentScore.value = 0
+ playerTricks.value = 0
+ opponentTricks.value = 0
deck.value = []
playerHand.value = []
@@ -55,6 +66,66 @@ export const useBiscaStore = defineStore('bisca', () => {
isDealing.value = false
}
+ const resolveTrick = () => {
+ const pCard = table.value.playerCard
+ const oCard = table.value.opponentCard
+ const trumpSuit = trumpCard.value.suit
+ let trickWinner = ''
+
+ if (pCard.suit === trumpSuit && oCard.suit !== trumpSuit) trickWinner = 'player'
+ else if (oCard.suit === trumpSuit && pCard.suit !== trumpSuit) trickWinner = 'opponent'
+ else if (pCard.suit === oCard.suit) {
+ trickWinner = getStrength(pCard.rank) > getStrength(oCard.rank) ? 'player' : 'opponent'
+ } else {
+ trickWinner = table.value.firstToPlay
+ }
+
+ const points = pCard.points + oCard.points
+
+ if (trickWinner === 'player') {
+ playerScore.value += points
+ playerTricks.value++
+ } else {
+ opponentScore.value += points
+ opponentTricks.value++
+ }
+
+ table.value = { playerCard: null, opponentCard: null, firstToPlay: null }
+
+ if (
+ deck.value.length === 0 &&
+ playerHand.value.length === 0 &&
+ opponentHand.value.length === 0
+ ) {
+ endGame()
+ return
+ }
+
+ if (deck.value.length > 0) {
+ if (trickWinner === 'player') {
+ playerHand.value.push(deck.value.pop())
+ opponentHand.value.push(deck.value.pop())
+ } else {
+ opponentHand.value.push(deck.value.pop())
+ playerHand.value.push(deck.value.pop())
+ }
+ }
+
+ currentTurn.value = trickWinner
+ if (trickWinner === 'opponent') {
+ setTimeout(botPlayCard, 1000)
+ }
+ }
+
+ const endGame = () => {
+ isGameRunning.value = false
+ isGameOver.value = true
+
+ if (playerScore.value > opponentScore.value) winner.value = 'player'
+ else if (opponentScore.value > playerScore.value) winner.value = 'opponent'
+ else winner.value = 'draw'
+ }
+
const dealInitialCards = async () => {
const cardsToDeal = gameType.value === 9 ? 9 : 3
@@ -108,6 +179,16 @@ export const useBiscaStore = defineStore('bisca', () => {
return strengthMap[rank] || 0
}
+ const quitGame = () => {
+ if (!isGameRunning.value) return
+ opponentScore.value = 120
+ playerScore.value = 0
+ winner.value = 'opponent'
+
+ isGameRunning.value = false
+ isGameOver.value = true
+ }
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
return {
@@ -117,11 +198,18 @@ export const useBiscaStore = defineStore('bisca', () => {
deck,
playerHand,
opponentHand,
+ isLoggingOut,
trumpCard,
playerScore,
opponentScore,
currentTurn,
table,
+ playerTricks,
+ opponentTricks,
+ isGameOver,
+ winner,
startGame,
+ quitGame,
+ resolveTrick,
}
})