Skip to content

Commit

Permalink
Merge pull request #257 from caxewsh/mvp-ranking-system
Browse files Browse the repository at this point in the history
feat: add ranking system @coderabbitai
  • Loading branch information
caxewsh authored Oct 10, 2024
2 parents e6c6601 + 6eae853 commit 6105e5a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 26 deletions.
5 changes: 1 addition & 4 deletions .maestro/launchGame.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ appId: com.axe.l.r.drinkup
- tapOn: "ON EST PRET !"

- repeat:
times: 10
while:
notVisible: "Fin de Partie"
commands:
- tapOn: "TOUR SUIVANT"

- tapOn:
id: "homeButton"
- stopApp

36 changes: 25 additions & 11 deletions components/endscreen/EndscreenCard.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import React from "react";
import { View, Text } from "react-native";
import { View, Text, ScrollView } from "react-native";

const EndscreenCard = ({ players }) => {
const sortedPlayers = [...players].sort((a, b) => b.score - a.score);

const EndscreenCard = () => {
return (
<View
style={{ backgroundColor: "rgba(255, 255, 255, 0.1)" }}
className="flex-1 justify-center w-78 m-10 mx-4 p-10 rounded-lg"
>
<Text className=" text-white font-semibold text-center text-sm">
Merci d'avoir participé à la beta. Faites nous part de vos retour
via le lien ci-dessous :
</Text>
</View>
style={{ backgroundColor: "rgba(255, 255, 255, 0.1)" }}
className="flex-1 justify-center w-78 m-10 mx-4 p-10 rounded-lg"
>
<Text className="text-white font-semibold text-center text-sm mb-4">
Plus tu prends chères, plus tu accumules les points ! Voici les scores :
</Text>

<ScrollView className="mt-4">
{sortedPlayers.map((player, index) => (
<View key={index} className="flex-row justify-between my-2 p-2 bg-gray-800 rounded-lg">
<Text className="text-white font-semibold">
{player.name}
</Text>
<Text className="text-white font-semibold">
Score: {player.score}
</Text>
</View>
))}
</ScrollView>
</View>
);
};

export default EndscreenCard;
export default EndscreenCard;
2 changes: 1 addition & 1 deletion components/endscreen/EndscreenHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const EndscreenHeader = ({ onPress }) => {
<HomeIcon color="white" size="30" className="" testID="homeButton" />
</TouchableOpacity>
<Text className="text-white absolute left-28 text-2xl font-black">
Fin de Partie
Classement
</Text>
</View>
)
Expand Down
13 changes: 10 additions & 3 deletions components/lobbyscreen/LobbyButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import Animated, { SlideInDown } from "react-native-reanimated";

const LobbyButton = ({ onPress, disabled }) => {
return (
<Animated.View className="flex-1 justify-center items-center " entering={SlideInDown.duration(800)}>
<Animated.View
className="flex-1 justify-center items-center"
entering={SlideInDown.duration(800)}
>
<TouchableOpacity
disabled={disabled}
onPress={onPress}
className=" bg-white absolute top-0 w-40 px-4 py-4 border-solid rounded-lg mt-4 justify-center align-items-center"
className={`absolute top-0 w-40 px-4 py-4 border-solid rounded-lg mt-4 justify-center items-center ${
disabled ? 'bg-gray-300' : 'bg-white'
}`}
>
<Text className="text-cyan-900 text-sm text-center font-bold">
<Text className={`text-sm text-center font-bold ${
disabled ? 'text-gray-500' : 'text-cyan-900'
}`}>
ON EST PRET !
</Text>
</TouchableOpacity>
Expand Down
1 change: 1 addition & 0 deletions components/lobbyscreen/PlayerNameInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const PlayerNameInput = ({ onChangeText, onSubmitEditing, value }) => {
value={value}
onChangeText={onChangeText}
onSubmitEditing={onSubmitEditing}
autoCorrect={false}
textAlign="center"
placeholder="Nom du joueur"
className=" bg-white font-semibold w-5/6 mx-4 h-10 px-4 py-1 rounded-md"
Expand Down
5 changes: 3 additions & 2 deletions screens/Endscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import EndscreenHeader from "../components/endscreen/EndscreenHeader";
import EndscreenButton from "../components/endscreen/EndscreenButton";
import EndscreenCard from "../components/endscreen/EndscreenCard";

export default function Endscreen() {
export default function Endscreen({ route }) {
const { backgroundImageSource } = useImage();
const navigation = useNavigation();
const { players } = route.params;
const goToHomescreen = () => {
navigation.navigate("Home");
};
Expand All @@ -30,7 +31,7 @@ export default function Endscreen() {
<SafeAreaView className="flex-1">
<StatusBar style="light" />
<EndscreenHeader onPress={goToHomescreen} />
<EndscreenCard />
<EndscreenCard players={players} />
<EndscreenButton onPress={restartGame} />
</SafeAreaView>
</View>
Expand Down
25 changes: 20 additions & 5 deletions screens/Gamescreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Gamescreen() {
const fetchQuestionsAndPlayers = async () => {
setIsLoading(true);
try {
let { data: questionsData, error } = await supabase.from("questions").select("*");
let { data: questionsData, error } = await supabase.from("questionsV3").select("*");
if (error) throw error;

if (!Array.isArray(questionsData)) {
Expand All @@ -41,8 +41,13 @@ export default function Gamescreen() {

// Fetch players from AsyncStorage
const playerData = await AsyncStorage.getItem("players");
const parsedPlayers = JSON.parse(playerData) || [];
let parsedPlayers = JSON.parse(playerData) || [];

parsedPlayers = parsedPlayers.map(player => ({
...player,
score: player.score || 0 // Initialize score if not present
}));

if (!Array.isArray(parsedPlayers)) {
throw new TypeError("Parsed players data is not an array");
}
Expand All @@ -68,11 +73,21 @@ export default function Gamescreen() {
};
const navigation = useNavigation();

const handleNextRound = () => {

const handleNextRound = async () => {
const currentQuestion = questions[currentQuestionIndex];
const currentPlayerIndex = currentQuestionIndex % players.length;
const currentPlayer = players[currentPlayerIndex];

currentPlayer.score += currentQuestion.severity || 1;
try {
await AsyncStorage.setItem("players", JSON.stringify(players));
} catch (error) {
console.error("Error updating scores:", error);
}

if (currentQuestionIndex + 1 >= questions.length) {
// No more questions, navigate to Endscreen or reset for a new game
navigation.navigate("End");
navigation.navigate("End", { players });
} else {
// Increment index to move to the next question
setCurrentQuestionIndex(currentQuestionIndex + 1);
Expand Down

0 comments on commit 6105e5a

Please sign in to comment.