Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: show correct answer after game over #9

Merged
merged 2 commits into from
Feb 3, 2023
Merged

feature: show correct answer after game over #9

merged 2 commits into from
Feb 3, 2023

Conversation

marsian83
Copy link

Overview

Added text in the game over splash screen after the player loses a game to show the correct answer to the question which they answered incorrectly

Screenshots

WhatsApp Image 2023-02-03 at 17 16 53
Before the new feature

WhatsApp Image 2023-02-03 at 17 10 28
Displaying correct answer after adding the feature

WhatsApp Image 2023-02-03 at 17 12 06
Displaying correct answer after adding the feature

WhatsApp Image 2023-02-03 at 17 14 40
Displaying correct answer after adding the feature

WhatsApp Image 2023-02-03 at 17 11 03
Displaying correct answer after adding the feature

Tests

I have tried all four possible operations as shown in the screenshots and played the game besides that with my commits as well and have not encountered any bugs.

Changes

def ggAnimation(strin, score, hscore, mainGame):

line 107 : strin was added as a parameter to use it to later evaluate and display the strin (strin holds the current question)

        texSurfaceObj = fontObj.render(
            _("The correct answer was %s %d" ) % 
            (strin[2:],eval(strin[2:-1])), True, RED)
        texRectObj = texSurfaceObj.get_rect()
        texRectObj.center = (ResX // 2, ResY // 2 - 100)
        DISPLAYSURF.blit(texSurfaceObj, texRectObj)

line 118 to 123 : implements the actual functionality of calculating and displaying the correct answer

                    ggAnimation(self.strin, self.score, self.hscore, self)

line 324 : Calls the ggAnimation function with the newly added strin parameter included

@quozl
Copy link

quozl commented Feb 3, 2023

Thanks. Would it be safer to use self.n rather than eval?

@marsian83
Copy link
Author

Hi @quozl You're right, I've changed it so that instead of evaluating the question again with eval, we use the precalculated self.n
I'm not so sure about the safety part but it definitely does make it less computational. Thanks for making me realize that
I've made the necessary changes and committed them

@quozl
Copy link

quozl commented Feb 3, 2023

Thanks.

@quozl quozl merged commit b7ea7bd into sugarlabs:master Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants