Stacking Coloured Blocks Game

How can I get to draw my main_stack in the correct way, and with the conditional - only add to the scoring_stack if the last item of main_stack is the same color as last item of scoring_stack - and, the scoring_stack should be drawn correctly, always from the bottom towards the top (never leaving a gap). I don’t need any import, only simple coding

 #list with values of blocks which will be 0 for red, 1 for green, 2 for blue
 
main_stack = []
#first 3 blocks randomnly drawn
main_stack.append(int(random(0,3)))
main_stack.append(int(random(0,3)))
main_stack.append(int(random(0,3)))
scoring_stack = []
score = 0

x = 0
y = 0


def setup():
    size(500,500)

def draw():
    """conditionals with drawings so it'll draw the right block according to random value originated by b key
    main_stack: have blocks added with random colors or blocks destroyed
    scoring_stack: only blocks of same colors can go to the scoring_stack
    """
    background(255)
    print(main_stack)
    print(scoring_stack)
    global x,y, main_stack, scoring_stack, score
    x = 150
    y = 500
    fill(0)
    textSize(25)
    text("Score:  " + str(score), 300, 50)
    

    for i in scoring_stack:
        x= 150
        if i == int("0"):
            y -= 50
            fill(255,0,0)
            rect(300,y, 50, 50)
        elif i == int("1"):
            y -= 50
            fill(0, 255, 0)
            rect(300,y, 50, 50)
        elif i == int("2"):
            y -= 50
            fill(0, 0, 255)
            rect(300,y, 50, 50)
            
    for i in main_stack:
        if i == int("0"):
            y -= 50
            fill(255,0,0)
            rect(x,y, 50, 50)
        elif i == int("1"):
            y -= 50
            fill(0, 255, 0)
            rect(x,y, 50, 50)
        elif i == int("2"):
            y -= 50
            fill(0, 0, 255)
            rect(x,y, 50, 50)


def keyPressed():
    """b key is for adding new random blocks(costs 1 point), d is to destroy a block(costs 1 point), s is to move to the scoring stack the blocks that match colors(3 blocks of same color gives 5 points)
    """
    global x,y, main_stack, scoring_stack, score
    if key == "b":
       score -= 1
       main_stack.append(int(random(0,3)))
                         
    if key== "d" and len(main_stack)> 0:
        #nothing should happen if there's no blocks on scoring_stack
        score -= 1
        main_stack.pop()
        
    if key == "s" :
        #nothing should happen if colors don't match
        if scoring_stack = [
        score += 5
        score = main_stack.pop()
        scoring_stack.append(score)
    else:
        return
            
    
1 Like

It’ hard to say

which line numbers are relevant?

I already solved it! Thank you though!

1 Like