Simple minigames (Screen Language only).

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
Max987r
Newbie
Posts: 11
Joined: Fri May 13, 2022 10:28 am
Contact:

Re: Simple minigames (Screen Language only).

#121 Post by Max987r » Wed May 18, 2022 8:53 am

Alex wrote:
Tue May 17, 2022 2:26 pm
Max987r wrote:
Tue May 17, 2022 1:58 pm
...I need your help to figure out how to make even some card ie trap cards remain on screen game ends?
This will end the game if only trap cards are remain onscreen - viewtopic.php?f=51&t=18047&p=552135&sid ... f9#p552110
thanks alex actually i am dumb i forgot i changed the name of loop thats why it was not working

Max987r
Newbie
Posts: 11
Joined: Fri May 13, 2022 10:28 am
Contact:

Re: Simple minigames (Screen Language only).

#122 Post by Max987r » Tue May 31, 2022 9:48 am

Hey Alex sorry to bother you again :cry:

But can you help me to make that if trap cards are matched only then time will be reduced other wise not

Ex: trap card A is matched time will reduce.
Non trap card B is matched no time will be reduced.

Thanks and again sorry for causing you problem 🙇

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#123 Post by Alex » Tue May 31, 2022 11:19 am

Max987r wrote:
Tue May 31, 2022 9:48 am
Hey Alex sorry to bother you again :cry:

But can you help me to make that if trap cards are matched only then time will be reduced other wise not

Ex: trap card A is matched time will reduce.
Non trap card B is matched no time will be reduced.

Thanks and again sorry for causing you problem 🙇
Hm, I'm not quite get it...
Trap cards are not matched (they are unique) and if player open such card - he get time penalty (5 sec. in this sample) - viewtopic.php?f=51&t=18047&start=105#p552128

And if player open ordinary card (matched or not) he get no penalty at all.

Max987r
Newbie
Posts: 11
Joined: Fri May 13, 2022 10:28 am
Contact:

Re: Simple minigames (Screen Language only).

#124 Post by Max987r » Wed Jun 01, 2022 1:10 am

Alex wrote:
Tue May 31, 2022 11:19 am
Max987r wrote:
Tue May 31, 2022 9:48 am
Hey Alex sorry to bother you again :cry:

But can you help me to make that if trap cards are matched only then time will be reduced other wise not

Ex: trap card A is matched time will reduce.
Non trap card B is matched no time will be reduced.

Thanks and again sorry for causing you problem 🙇
Hm, I'm not quite get it...
Trap cards are not matched (they are unique) and if player open such card - he get time penalty (5 sec. in this sample) - viewtopic.php?f=51&t=18047&start=105#p552128

And if player open ordinary card (matched or not) he get no penalty at all.

My question is can we make if certain cards are matched time will be reduced?

Let's say for ex:

There are cards A,B,C,D,T (in pair)
If you match card A,B,C,D no time penalty
But if you match card T time will be dropped

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#125 Post by Alex » Wed Jun 01, 2022 6:38 am

Max987r wrote:
Wed Jun 01, 2022 1:10 am
My question is can we make if certain cards are matched time will be reduced?

Let's say for ex:

There are cards A,B,C,D,T (in pair)
If you match card A,B,C,D no time penalty
But if you match card T time will be dropped
Mmm, try to add one more key to describe card, like "c_penalty" that will store the number of seconds.

Code: Select all

    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            time_penalty = 0.0
            if values_list[i] == 'T':
                time_penalty = 5.0
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False, "c_penalty":time_penalty} )
So, later you can use its value

Code: Select all

            # If cards are matched, will check if player has opened all the cards
            else:
                $ renpy.pause (1.0, hard = True)

                # time penalty for card type <---
                $ time -= cards_list[turned_cards_numbers[0]]["c_penalty"]

                python: 
                    
                    # Let's remove opened cards from game field
                    # But if you prefere to let them stay - just comment out next 2 lines
                    for i in range (0, len(turned_cards_numbers) ):
                        cards_list[turned_cards_numbers[i]]["c_value"] = Null()
                        
                        
                    for j in cards_list:
                        if j["c_chosen"] == False and j["c_value"] not in trap_cards: # <---
                            renpy.jump ("memo_game_loop")
                    renpy.jump ("memo_game_win")   

Max987r
Newbie
Posts: 11
Joined: Fri May 13, 2022 10:28 am
Contact:

Re: Simple minigames (Screen Language only).

#126 Post by Max987r » Sat Jun 04, 2022 12:17 pm

Alex wrote:
Wed Jun 01, 2022 6:38 am
Max987r wrote:
Wed Jun 01, 2022 1:10 am
My question is can we make if certain cards are matched time will be reduced?

Let's say for ex:

There are cards A,B,C,D,T (in pair)
If you match card A,B,C,D no time penalty
But if you match card T time will be dropped
Mmm, try to add one more key to describe card, like "c_penalty" that will store the number of seconds.

Code: Select all

    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            time_penalty = 0.0
            if values_list[i] == 'T':
                time_penalty = 5.0
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False, "c_penalty":time_penalty} )
So, later you can use its value

Code: Select all

            # If cards are matched, will check if player has opened all the cards
            else:
                $ renpy.pause (1.0, hard = True)

                # time penalty for card type <---
                $ time -= cards_list[turned_cards_numbers[0]]["c_penalty"]

                python: 
                    
                    # Let's remove opened cards from game field
                    # But if you prefere to let them stay - just comment out next 2 lines
                    for i in range (0, len(turned_cards_numbers) ):
                        cards_list[turned_cards_numbers[i]]["c_value"] = Null()
                        
                        
                    for j in cards_list:
                        if j["c_chosen"] == False and j["c_value"] not in trap_cards: # <---
                            renpy.jump ("memo_game_loop")
                    renpy.Jump ("memo_game_win")   

it worked but got a new problem


1st: how can I add multiple values?

Code: Select all

 if values_list[i] == 'T':
 
2nd: after you match all card even the trap cards not removed(matched) i want game to end ?

I will add my code as well, so you can see it

Code: Select all


##### The game screen
screen memo_scr_h:
    add "bbg.png"
    ##### Timer
    timer 1.0 action If (memo_timer > 1, SetVariable("memo_timer", memo_timer - 1), Jump("memoria_game_lose_hard") ) repeat True

    text str(memo_timer) xalign 0.5 yalign 0.05 size 60 color "#61048D"


    ##### Cards
    #
    # To use images, just comment out lines that show text and uncomment lines that show images
    grid 6 4:
        xalign 0.2
        yalign 0.5

        for card in cards_list:
            button:
                padding (2, 2, 2, 2)
                xsize 130
                ysize 185

                if card["c_chosen"]:        # shows the face of the card
                    #text card["c_value"]    # will show text
                    add card["c_value"]    # will show image

                else:                       # shows the back of the card
                    #text "X"                # will show text
                    add "y"                # will show image

                action If ( (card["c_chosen"] or not can_click), None, [SetDict(cards_list[card["c_number"]], "c_chosen", True), Return(card["c_number"]) ] )









init:
    python:
        def cards_shuffle(x):
            renpy.random.shuffle(x)
            return x

    ##### Images
    image a = "1.png"         # different card images
    image b = "2.png"
    image c = "3.png"
    image d = "4.png"
    image e = "5.png"
    image f = "6.png"
    image g = "7.png"
    image h = "8.png"
    image i = "9.png"
    image j = "10.png"
    image k = "11.png"
    image l = "12.png"
    image y = "back.png"          # back of the card




label memoria_game_hard:

    #####
    #
    # At first, let's set the cards to play (the amount should match the grid size - in this example 16)
    $ values_list = ["a", "a", "b", "b", "c", "c", "d", "d", "e", "e", "f", "f", "h", "h", "g", "g", "i", "i", "j", "j" , "k", "l", "k", "l"]
    #trap card
    #$ trap_card = ["k", "l"]
    # Then - shuffle them
    $ values_list = cards_shuffle(values_list)

    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            time_penalty = 0.0
            if values_list[i] == 'j':
                time_penalty = 5.0
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False, "c_penalty":time_penalty} )


    # Before start the game, let's set the timer
    $ memo_timer = 50

    # Shows the game screen
    show screen memo_scr_h

    # The game loop
    label memo_game_loop_h:
        $ can_click = True
        $ turned_cards_numbers = []
        $ turned_cards_values = []

        # Let's set the amount of cards that should be opened each turn (all of them should match to win)
        $ turns_left = 2

        label turns_loop_h:
            if turns_left > 0:
                $ result = ui.interact()
                $ memo_timer = memo_timer
                $ turned_cards_numbers.append (cards_list[result]["c_number"])
                $ turned_cards_values.append (cards_list[result]["c_value"])
                $ turns_left -= 1
                jump turns_loop_m

        # To prevent further clicking befor chosen cards will be processed
        $ can_click = False
        # If not all the opened cards are matched, will turn them face down after pause
        if turned_cards_values.count(turned_cards_values[0]) != len(turned_cards_values):
            $ renpy.pause (1.0, hard = True)
            python:
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_chosen"] = False

        # If cards are matched, will check if player has opened all the cards
        else:
            $ renpy.pause (1.0, hard = True)
            # time penalty for card type <---
            $ memo_timer -= cards_list[turned_cards_numbers[0]]["c_penalty"]
            python:

                # Let's remove opened cards from game field
                # But if you prefere to let them stay - just comment out next 2 lines
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_value"] = Null()


                for j in cards_list:
                    if j["c_chosen"] == False:
                        renpy.jump ("memo_game_loop_h")
                renpy.jump ("memoria_game_win_hard")


            jump memo_game_loop_h

label memoria_game_lose_hard:
    hide screen memo_scr_h
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    "You lose! Try again."
    jump memoria_game_hard

label memoria_game_win_hard:
    hide screen memo_scr_h
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    "You win!"
    jump VNmode1


User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Simple minigames (Screen Language only).

#127 Post by Alex » Sat Jun 04, 2022 2:45 pm

Max987r wrote:
Sat Jun 04, 2022 12:17 pm
...1st: how can I add multiple values?

Code: Select all

 if values_list[i] == 'T':
 
...
Like this

Code: Select all

    # And make the cards_list that describes all the cards
    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            time_penalty = 0.0
            if values_list[i] == 'j':
                time_penalty = 5.0
            elif values_list[i] == 'k':
                time_penalty = 7.0
            elif values_list[i] == 'l':
                time_penalty = 15.0
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False, "c_penalty":time_penalty} )
Max987r wrote:
Sat Jun 04, 2022 12:17 pm
...2nd: after you match all card even the trap cards not removed(matched) i want game to end ?...
Check your code once again - it should be

Code: Select all

            # If cards are matched, will check if player has opened all the cards
            else:
                $ renpy.pause (1.0, hard = True)

                # time penalty for card type
                $ time -= cards_list[turned_cards_numbers[0]]["c_penalty"]

                python: 
                    
                    # Let's remove opened cards from game field
                    # But if you prefere to let them stay - just comment out next 2 lines
                    for i in range (0, len(turned_cards_numbers) ):
                        cards_list[turned_cards_numbers[i]]["c_value"] = Null()
                        
                        
                    for j in cards_list:
                        if j["c_chosen"] == False and j["c_value"] not in trap_cards: # <--- !!!
                            renpy.jump ("memo_game_loop")
                    renpy.Jump ("memo_game_win")  

And check the typo in label's name

Code: Select all

        label turns_loop_h:
            if turns_left > 0:
                $ result = ui.interact()
                $ memo_timer = memo_timer
                $ turned_cards_numbers.append (cards_list[result]["c_number"])
                $ turned_cards_values.append (cards_list[result]["c_value"])
                $ turns_left -= 1
                jump turns_loop_h # <--- not turns_loop__m

Max987r
Newbie
Posts: 11
Joined: Fri May 13, 2022 10:28 am
Contact:

Re: Simple minigames (Screen Language only).

#128 Post by Max987r » Mon Jun 06, 2022 10:44 am

Thanks Alex it works i found out a line from past edit causing not to work i fixed it thanks you very much.

Post Reply

Who is online

Users browsing this forum: No registered users