All pastes #2824228 Raw Edit

Miscellany

public unlisted text v1 · immutable
#2824228 ·published 2014-07-22 06:12 UTC
rendered paste body
import time
import random

bone = " - "
btwo = " - "
bthree = " - "
bfour = " - "
bfive = " - "
bsix = " - "
bseven = " - "
beight = " - "
bnine = " - "

randno = random.choice([" 2 "," 2 "," 2 "," 4 "])

#Here we set the basics for the game, and each variable represents a different formation of the board, where a random number can be placed.
slotone = (str(randno) + " " + str(btwo) + " " + str(bthree) + '''
''' + str(bfour) + " " + str(bfive) + " " + str(bsix) + '''
''' + str(bseven) + " " + str(beight) + " " + str(bnine))
slottwo = (str(bone) + " " + (str(randno) + " " + str(bthree) + '''
''' + str(bfour) + " " + str(bfive) + " " + str(bsix) + '''
''' + str(bseven) + " " + str(beight) + " " + str(bnine)))
slotthree = (str(bone) + " " + str(btwo) + " " + (str(randno)) + '''
''' + str(bfour) + " " + str(bfive) + " " + str(bsix) + '''
''' + str(bseven) + " " + str(beight) + " " + str(bnine))
slotfour = (str(bone) + " " + str(btwo) + " " + str(bthree) + '''
''' + (str(randno) + " " + str(bfive) + " " + str(bsix) + '''
''' + str(bseven) + " " + str(beight) + " " + str(bnine)))
slotfive = (str(bone) + " " + str(btwo) + " " + str(bthree) + '''
''' + str(bfour) + " " + (str(randno) + " " + str(bsix) + '''
''' + str(bseven) + " " + str(beight) + " " + str(bnine)))
slotsix = (str(bone) + " " + str(btwo) + " " + str(bthree) + '''
''' + str(bfour) + " " + str(bfive) + " " + (str(randno)) + '''
''' + str(bseven) + " " + str(beight) + " " + str(bnine))
slotseven = (str(bone) + " " + str(btwo) + " " + str(bthree) + '''
''' + str(bfour) + " " + str(bfive) + " " + str(bsix) + '''
''' + (str(randno) + " " + str(beight) + " " + str(bnine)))
sloteight = (str(bone) + " " + str(btwo) + " " + str(bthree) + '''
''' + str(bfour) + " " + str(bfive) + " " + str(bsix) + '''
''' + str(bseven) + " " + (str(randno) + " " + str(bnine)))
slotnine = (str(bone) + " " + str(btwo) + " " + str(bthree) + '''
''' + str(bfour) + " " + str(bfive) + " " + str(bsix) + '''
''' + str(bseven) + " " + str(beight) + " " + (str(randno)))


#set some variable for the tutorial only
firstleft = False
firstright = False
firstup = False
firstdown = False

randno = random.choice([2,4])

if randno == 2 or 4:

    #Start
    welcome = input("Welcome to 2048! Would you like to take the tutorial?(y/n) ")
    if welcome == "y":
        time.sleep(2)
        print("Here's how the game works. You have a board, which will be represented by")
        print("A series of numbers. There are 9 spaces on this board. It will look like this:")
        time.sleep(4)
        print("-  -  -")
        print("2  -  -")
        print("-  -  -")
        print()
        print("Notice there are blank spaces, shown as '-', and full spaces, shown as numbers.")
        print("To move the board, type 'left', 'right', 'up' or 'down', respectively.")
        time.sleep(5)
        print("Try this now.")

        

        #First Move (It's basically linear, except for the random number. Which appears in the same place every time. Oops.)
        firstmove = input()
        if firstmove == "left":
            print("-  -  " + str(randno))
            print("2  -  -")
            print("-  -  -")
            print("You'll notice the board didn't move. That's because you can't move a 2")
            print("into a wall. Funny that.")
          

        if firstmove == "right":
            firstright = True
            print("-  -  " + str(randno))
            print("-  -  2")
            print("-  -  -")
            print("You'll notice the 2 moved to the other side of the board.")
            print("You did that, congrats.")
        if firstmove == "up":
            firstup = True
            print("2  -  " + str(randno))
            print("-  -  -")
            print("-  -  -")
            print("You'll notice the 2 moved to the top of the first column")
            print("You did that, congrats.")

        if firstmove == "down":
            firstdown = True
            print("-  -  " + str(randno))
            print("-  -  -")
            print("2  -  -")
            print("You'll notice the 2 moved to the bottom of the first column")
            print("You did that, congrats.")


        #More talking, sorry.
        print("But hold on! What's that other number doing there??")
        print("You see, whenever you make a move, a number appears.")
        time.sleep(3)
        print("Your objective is to make the number 16.")
        print("You do this by moving the board so that pairs of")
        print("numbers are joined together, to create a double.")
        print("E.g 2 joined with 2 = 4")
        time.sleep(2)
        print("Time to start the real game. Good luck!")


    
        #Set up default slots. "sone" stands for slot one, et cetera. Remember, each one of these variables is a slot on the board. I'm sure there is an easier way to do
        #this, but I am yet to think of it. I think I've done an okay job, as it is.
        sone = " - "
        stwo = " - "
        sthree = " - "
        sfour = " - "
        sfive = " - "
        ssix = " - "
        sseven = " - "
        seight = " - "
        snine = " - "


        two = "2"
        four = "4"
        randno = random.choice([ two, two, two, four])

        print("Begin - Now!")
        #Now, we print the default board, with a single random number, determined by the little equation underneath. It also picks which slot the number will be in.
        whichslot = random.randint(1,9)
        
        if whichslot == 1:
            print(slotone)
        if whichslot == 2:
            print(slottwo)
        if whichslot == 3:
            print(slotthree)
        if whichslot == 4:
            print(slotfour)
        if whichslot == 5:
            print(slotfive)
        if whichslot == 6:
            print(slotsix)
        if whichslot == 7:
            print(slotseven)
        if whichslot == 8:
            print(sloteight)
        if whichslot == 9:
            print(slotnine)

        #These are the functions of the movements. We'll start with the Left function
       
        def moveleft():
            #adding functions
            if bone == btwo:
                bone * 2
                if bthree == " - ":
                    btwo = " - "
            else:
                if bone ==" - " and btwo == randno:
                    bone = btwo

            if bfour == bfive:
                bfour * 2
                if bsix == " - ":
                    bfive = " - "
            else:
                if bfour == " - " and bfive == randno:
                    bfour = bfive

            if bseven == beight:
                bseven * 2
                if bnine == " - ":
                    beight = " - "
            else:
                if bseven == " - " and beight == randno:
                    bseven = beight
            #movement & addition if the other slot is empty
            if btwo == bthree and bone == " - ":
                bone = btwo * 2
                btwo = " - "
                bthree = " - "


        
            #next horizontal column (4 through 6)
            
            #movement & addition if the other slot is empty
            if bfive == bsix and bfour == " - ":
                bfour = bfive * 2
                bfive = " - "
                bsix = " - "

            #next horizontal column (7 through 9)
            
            #movement & addition if the other slot is empty
            if beight == bnine and bseven == " - ":
                bseven = beight * 2
                beight = " - "
                bnine = " - "

        #input

        moveme = input()
        
        if moveme == "left":
            moveleft()
            print("yes")