diff --git a/backend/database.db b/backend/database.db index 0942c92..07c5f38 100644 Binary files a/backend/database.db and b/backend/database.db differ diff --git a/backend/server.js b/backend/server.js index 2694ca3..990caac 100644 --- a/backend/server.js +++ b/backend/server.js @@ -63,7 +63,6 @@ app.post('/register', async (req, res) => { // Login route app.post('/login', (req, res) => { const { username, password } = req.body; - console.log("Trying to Login: ", username); db.get('SELECT * FROM users WHERE username = ?', [username], async (err, row) => { if (err) { return res.status(500).json({ error: 'Internal server error' }); @@ -198,23 +197,28 @@ app.get('/games/:userId/characters', (req, res) => { if (err) { return res.status(500).json({ error: 'Internal server error' }); } - // Directly return the array of characters - console.log("Characters: ", rows); res.json(rows); }); }); // Fetch Player Character -app.get('/games/:gameId/:playerId/character', (req, res) => { +app.get('/games/:gameId/:userId/character', (req, res) => { const gameId = req.params.gameId; - const playerId = req.params.playerId; - db.get('SELECT * FROM PlayerCharacter WHERE GameID = ? AND PlayerID = ?', [gameId, playerId], (err, row) => { + const userId = req.params.userId; + console.log(`Fetching character for gameId: ${gameId}, userId: ${userId}`); // Debug output + db.get('SELECT * FROM PlayerCharacter WHERE GameID = ? AND PlayerID = ?', [gameId, userId], (err, row) => { if (err) { + console.error('Database error:', err); // Debug output return res.status(500).json({ error: 'Internal server error' }); } + if (!row) { + console.log('No character found'); // Debug output + return res.status(404).json({ error: 'No character found' }); + } + console.log('Character found:', row); // Debug output res.json(row); }); -}) +}); // Fetch Player Items app.get('/games/:charId/items', (req, res) => { diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 5438270..89a2f43 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -9,6 +9,7 @@ import Register from './pages/register'; import JoinGame from './pages/joinGame'; import StartGame from './pages/startGame'; import Profile from './pages/profile'; +import Games from './pages/games.jsx'; import { UserProvider } from './context/UserContext.jsx'; function App() { @@ -59,6 +60,10 @@ function App() { path="/profile" element={} /> + } + /> diff --git a/frontend/src/pages/games.jsx b/frontend/src/pages/games.jsx index e69de29..7574d36 100644 --- a/frontend/src/pages/games.jsx +++ b/frontend/src/pages/games.jsx @@ -0,0 +1,114 @@ +import { useState, useEffect, useContext } from 'react'; +import { Link, useParams } from 'react-router-dom'; +import axios from 'axios'; +import { UserContext } from '../context/UserContext'; +import { Box, Typography, Grid, Card, CardContent, CardMedia, Button } from '@mui/material'; +import defaultCharacterImage from '../assets/default-character.png'; + +const GamesPage = () => { + const { userId } = useContext(UserContext); + const { gameId } = useParams(); + const [character, setCharacter] = useState(null); + + useEffect(() => { + const fetchCharacter = async () => { + try { + const response = await axios.get(`http://localhost:5000/games/${gameId}/${userId}/character`); + setCharacter(response.data); + } catch (error) { + console.error('Error fetching character:', error); + } + }; + + if (userId) { + fetchCharacter(); + } + }, [userId, gameId]); + + if (!character) { + return ( + + No Character Found + + + ); + } + + return ( + + + {/* Character Info Section */} + + {character.CharName} + + {/* Health Bar */} + + + Health + {character.CurrentHealth}/{character.MaxHealth} + + + + + + {/* Mana Bar */} + + + Mana + {character.CurrentMana}/{character.MaxMana} + + + + + + + + {/* Character Description */} + + Description + {character.Looks} + + + {/* Inventory */} + + Inventory + + {character.Items?.map((item, index) => ( + + + + {item.name} + Quantity: {item.quantity} + + + + ))} + + + + + {/* Character Image and Details */} + + + + + Age: {character.Age} + Race: {character.Race} + Sex: {character.Sex} + Job: {character.Job} + + + + + + ); +}; + +export default GamesPage; \ No newline at end of file