first commit
This commit is contained in:
300
client/src/components/Game.vue
Normal file
300
client/src/components/Game.vue
Normal file
@@ -0,0 +1,300 @@
|
||||
<template>
|
||||
<div class="game-container">
|
||||
<!-- Waiting Phase -->
|
||||
<div v-if="gamePhase === 'waiting'" class="waiting-screen">
|
||||
<div class="waiting-content">
|
||||
<h2>Esperando jugadores...</h2>
|
||||
<div class="player-count">
|
||||
{{ playerCount }}/{{ minPlayers }} jugadores conectados
|
||||
</div>
|
||||
<div class="spinner"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Playing Phase -->
|
||||
<div v-else-if="gamePhase === 'playing'" class="game-screen">
|
||||
<!-- Scoreboard -->
|
||||
<div class="scoreboard">
|
||||
<div
|
||||
v-for="player in players"
|
||||
:key="player.id"
|
||||
class="player-score"
|
||||
:class="{ 'current-player': player.id === currentPlayerId }"
|
||||
>
|
||||
<span class="player-name">{{ player.name }}</span>
|
||||
<span class="score">{{ player.score }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Click Button -->
|
||||
<div class="click-area">
|
||||
<button
|
||||
@click="handleClick"
|
||||
class="click-button"
|
||||
:class="{ 'clicked': isClicked }"
|
||||
>
|
||||
<span class="click-text">¡CLICK!</span>
|
||||
<div class="click-effect" v-if="showEffect"></div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Current Player Info -->
|
||||
<div class="player-info">
|
||||
<p>Tu puntaje: <strong>{{ currentPlayerScore }}</strong></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted, triggerRef } from 'vue'
|
||||
import { GameClient } from '@/services/gameClient'
|
||||
import { GameState, Player } from '@/types'
|
||||
import type { Room } from 'colyseus.js'
|
||||
import { logger } from '@/services/logger'
|
||||
|
||||
const props = defineProps<{
|
||||
gameClient: any
|
||||
}>()
|
||||
|
||||
const gameState = ref<GameState | null>(null)
|
||||
const isClicked = ref(false)
|
||||
const showEffect = ref(false)
|
||||
|
||||
// Computed properties
|
||||
const gamePhase = computed(() => {
|
||||
const phase = gameState.value?.gamePhase || 'waiting'
|
||||
logger.computedProperty('gamePhase', phase)
|
||||
return phase
|
||||
})
|
||||
const minPlayers = computed(() => gameState.value?.minPlayers || 2)
|
||||
const playerCount = computed(() => {
|
||||
const count = gameState.value?.players.size || 0
|
||||
logger.computedProperty('playerCount', count)
|
||||
return count
|
||||
})
|
||||
const players = computed(() => {
|
||||
if (!gameState.value) return []
|
||||
const playerList = Array.from(gameState.value.players.values())
|
||||
logger.computedProperty('players', playerList)
|
||||
return playerList
|
||||
})
|
||||
const currentPlayerId = computed(() => props.gameClient?.currentPlayerId || '')
|
||||
const currentPlayerScore = computed(() => {
|
||||
if (!gameState.value || !currentPlayerId.value) return 0
|
||||
const player = gameState.value.players.get(currentPlayerId.value)
|
||||
return player?.score || 0
|
||||
})
|
||||
|
||||
const handleClick = () => {
|
||||
if (!props.gameClient || gamePhase.value !== 'playing') return
|
||||
|
||||
// Send click through gameClient
|
||||
props.gameClient.sendClick()
|
||||
|
||||
// Visual feedback
|
||||
isClicked.value = true
|
||||
showEffect.value = true
|
||||
|
||||
setTimeout(() => {
|
||||
isClicked.value = false
|
||||
}, 150)
|
||||
|
||||
setTimeout(() => {
|
||||
showEffect.value = false
|
||||
}, 400)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (!props.gameClient) return
|
||||
|
||||
logger.gameMounted()
|
||||
|
||||
// Subscribe to state changes
|
||||
const unsubscribeStateChange = props.gameClient.onStateChange((state: GameState) => {
|
||||
logger.gameComponentUpdate({
|
||||
gamePhase: state.gamePhase,
|
||||
playerCount: state.players.size,
|
||||
gameStarted: state.gameStarted
|
||||
})
|
||||
|
||||
// Force Vue reactivity by assigning new reference and triggering update
|
||||
gameState.value = state
|
||||
triggerRef(gameState)
|
||||
|
||||
logger.info('Reactive gameState updated and triggered:', gameState.value)
|
||||
})
|
||||
|
||||
// Subscribe to phase changes for debugging
|
||||
const unsubscribePhaseChange = props.gameClient.onGamePhaseChange((phase: string) => {
|
||||
logger.info('Game component detected phase change:', phase)
|
||||
})
|
||||
|
||||
// Cleanup on unmount
|
||||
onUnmounted(() => {
|
||||
logger.gameUnmounted()
|
||||
unsubscribeStateChange()
|
||||
unsubscribePhaseChange()
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.game-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
/* Waiting Screen */
|
||||
.waiting-screen {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.waiting-content h2 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.player-count {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 2rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border: 4px solid rgba(255, 255, 255, 0.3);
|
||||
border-top: 4px solid white;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* Game Screen */
|
||||
.game-screen {
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.scoreboard {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 2rem;
|
||||
margin-bottom: 3rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.player-score {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
padding: 1rem 1.5rem;
|
||||
border-radius: 12px;
|
||||
text-align: center;
|
||||
backdrop-filter: blur(10px);
|
||||
border: 2px solid transparent;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.player-score.current-player {
|
||||
border-color: #ffd700;
|
||||
background: rgba(255, 215, 0, 0.2);
|
||||
}
|
||||
|
||||
.player-name {
|
||||
display: block;
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.score {
|
||||
display: block;
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* Click Button */
|
||||
.click-area {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.click-button {
|
||||
position: relative;
|
||||
width: 250px;
|
||||
height: 250px;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background: linear-gradient(45deg, #ff6b6b, #ff8e53);
|
||||
color: white;
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
transition: all 0.1s ease;
|
||||
box-shadow: 0 8px 25px rgba(255, 107, 107, 0.4);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.click-button:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 12px 35px rgba(255, 107, 107, 0.6);
|
||||
}
|
||||
|
||||
.click-button.clicked {
|
||||
transform: scale(0.95);
|
||||
background: linear-gradient(45deg, #ff8e53, #ff6b6b);
|
||||
}
|
||||
|
||||
.click-text {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.click-effect {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
animation: clickRipple 0.4s ease-out;
|
||||
}
|
||||
|
||||
@keyframes clickRipple {
|
||||
0% {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
100% {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.player-info {
|
||||
text-align: center;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.player-info strong {
|
||||
color: #ffd700;
|
||||
}
|
||||
</style>
|
||||
150
client/src/components/Home.vue
Normal file
150
client/src/components/Home.vue
Normal file
@@ -0,0 +1,150 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<div class="branding">
|
||||
<img src="/assets/logo.svg" alt="Snatch Game Logo" class="logo" />
|
||||
<h1>Snatch Game</h1>
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button @click="onJoin" :disabled="isConnecting">
|
||||
{{ isConnecting ? 'Conectando...' : 'Unirse a partida' }}
|
||||
</button>
|
||||
<button @click="onSettings">Configuración</button>
|
||||
<button @click="onLogin">Iniciar sesión</button>
|
||||
</div>
|
||||
|
||||
<div v-if="connectionStatus" class="connection-status">
|
||||
{{ connectionStatus }}
|
||||
</div>
|
||||
|
||||
<div class="footer">NucleoServices</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { GameClient } from '@/services/gameClient'
|
||||
import { logger } from '@/services/logger'
|
||||
|
||||
const emit = defineEmits<{
|
||||
'join-game': [client: any]
|
||||
'show-settings': []
|
||||
}>()
|
||||
|
||||
const gameClient = ref<GameClient | null>(null)
|
||||
const isConnecting = ref(false)
|
||||
const connectionStatus = ref('')
|
||||
|
||||
onMounted(() => {
|
||||
gameClient.value = new GameClient()
|
||||
logger.info('GameClient initialized:', gameClient.value);
|
||||
})
|
||||
|
||||
const onJoin = async () => {
|
||||
if (isConnecting.value || !gameClient.value) return
|
||||
|
||||
isConnecting.value = true
|
||||
connectionStatus.value = 'Conectando...'
|
||||
|
||||
try {
|
||||
await gameClient.value.joinGame('Jugador Test', 'classic')
|
||||
connectionStatus.value = 'Conectado exitosamente!'
|
||||
logger.info('Conectado al servidor')
|
||||
|
||||
// Emit the join-game event to transition to game screen
|
||||
emit('join-game', gameClient.value)
|
||||
} catch (error) {
|
||||
connectionStatus.value = 'Error de conexión: ' + (error as Error).message
|
||||
logger.error('Error connecting:', error)
|
||||
} finally {
|
||||
isConnecting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const onSettings = () => {
|
||||
emit('show-settings')
|
||||
}
|
||||
|
||||
const onLogin = () => {
|
||||
logger.info('Iniciar sesión clicked')
|
||||
// TODO: lógica para iniciar sesión
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.branding {
|
||||
text-align: center;
|
||||
margin-bottom: 3rem;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 1rem 2rem;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
color: #333;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
button:hover:not(:disabled) {
|
||||
background: white;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.connection-status {
|
||||
margin-top: 1rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 2rem;
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
246
client/src/components/Settings.vue
Normal file
246
client/src/components/Settings.vue
Normal file
@@ -0,0 +1,246 @@
|
||||
<template>
|
||||
<div class="settings-container">
|
||||
<div class="settings-header">
|
||||
<h2>Configuración</h2>
|
||||
<button @click="$emit('close')" class="close-button">
|
||||
<span>✕</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<div class="setting-section">
|
||||
<h3>Desarrollo</h3>
|
||||
|
||||
<div class="setting-item">
|
||||
<label class="checkbox-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="debugLoggingEnabled"
|
||||
@change="toggleDebugLogging"
|
||||
/>
|
||||
<span class="checkmark"></span>
|
||||
<span class="label-text">Activar logs de depuración</span>
|
||||
</label>
|
||||
<p class="setting-description">
|
||||
Muestra información detallada en la consola del navegador.
|
||||
Útil para depuración pero puede afectar el rendimiento.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-section">
|
||||
<h3>Información</h3>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Versión:</span>
|
||||
<span class="info-value">0.0.1-alpha</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">Entorno:</span>
|
||||
<span class="info-value">{{ environment }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-footer">
|
||||
<button @click="$emit('close')" class="button-primary">
|
||||
Cerrar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { logger } from '@/services/logger'
|
||||
|
||||
defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
|
||||
const debugLoggingEnabled = ref(false)
|
||||
const environment = import.meta.env.MODE
|
||||
|
||||
onMounted(() => {
|
||||
debugLoggingEnabled.value = logger.isDebugEnabled()
|
||||
})
|
||||
|
||||
const toggleDebugLogging = (event: Event) => {
|
||||
const target = event.target as HTMLInputElement
|
||||
debugLoggingEnabled.value = target.checked
|
||||
logger.setDebugEnabled(target.checked)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.settings-container {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
z-index: 1000;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1.5rem;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.settings-header h2 {
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.close-button {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
background: #f5f5f5;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.close-button:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
padding: 1.5rem;
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.setting-section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.setting-section h3 {
|
||||
margin: 0 0 1rem 0;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
cursor: pointer;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.checkbox-label input[type="checkbox"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.checkmark {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 4px;
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
margin-top: 1px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.checkbox-label input[type="checkbox"]:checked + .checkmark {
|
||||
background: #667eea;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 6px;
|
||||
top: 2px;
|
||||
width: 6px;
|
||||
height: 10px;
|
||||
border: solid white;
|
||||
border-width: 0 2px 2px 0;
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
.label-text {
|
||||
font-weight: 500;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
margin: 0.5rem 0 0 2.75rem;
|
||||
font-size: 0.9rem;
|
||||
color: #666;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0.5rem 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.info-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-weight: 500;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #333;
|
||||
font-family: 'Monaco', 'Consolas', monospace;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.settings-footer {
|
||||
padding: 1.5rem;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.button-primary {
|
||||
padding: 0.75rem 1.5rem;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.button-primary:hover {
|
||||
background: #5a6fd8;
|
||||
}
|
||||
|
||||
/* Overlay */
|
||||
.settings-container::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: -1;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user