2013-03-20 100 views
-1

好的,這是我第一次在這裏提出問題,所以如果這不是一個好問題,請不要生氣。我有6個函數代表正在滾動的骰子的圖像。我必須爲編程做一個胡扯遊戲。遊戲本身是完美的執行,但我必須把骰子並排顯示,而不是在彼此頂部。 例如:2功能並排執行

I have this: 
+------+ 
| * | 
| * | 
+======+ 
+------+ 
| * | 
| * | 
+------+ 

I need this: 
+------+ +------+ 
| * | | * | 
| * | | * | 
+------+ +------+ 

Here is my program so far: 

import random 

def roll_dice1(): 
    print "+-------+" 
    print "|  |" 
    print "| * |" 
    print "|  |" 
    print "+-------+" 
def roll_dice2(): 
    print "+-------+" 
    print "| *  |" 
    print "|  |" 
    print "|  * |" 
    print "+-------+"  

def roll_dice3(): 
    print "+-------+" 
    print "| *  |" 
    print "| * |" 
    print "|  * |" 
    print "+-------+"  

def roll_dice4(): 
    print "+-------+" 
    print "| * * |" 
    print "|  |" 
    print "| * * |" 
    print "+-------+"  

def roll_dice5(): 
    print "+-------+" 
    print "| * * |" 
    print "| * |" 
    print "| * * |" 
    print "+-------+" 

def roll_dice6(): 
    print "+-------+" 
    print "| * * * |" 
    print "|  |" 
    print "| * * * |" 
    print "+-------+"  

def dice_roll(): 
    counter = 0 
    dice = [] 
    while counter < int(2): 
     dice += [random.randint(1,6)] 
     counter += 1  
    i = 0 
    while i < 2: 
     if dice[i] == 1: 
      roll_dice1() 
     elif dice [i] == 2: 
      roll_dice2() 
     elif dice [i] == 3: 
      roll_dice3() 
     elif dice [i] == 4: 
      roll_dice4() 
     elif dice [i] == 5: 
      roll_dice5() 
     elif dice [i] == 6: 
      roll_dice6()  
     i += 1  
    roll = dice 
    return roll 

def point_cycle(): 
    raw_input("Press <Enter> to roll the dice") 
    roll = dice_roll() 
    total1 = int(roll[0]) + int (roll[1]) 
    if total1 == 7: 
     print "You rolled a 7." 
     print "You lose!" 
    elif total1 == total: 
     print "You rolled a " + str(total1) 
     print "You win!" 
    else: 
     print "You rolled a " + str(total1) 
     point_cycle() 


def main(): 
    print "Craps: A Popular Dice Game" 
    raw_input("Press <Enter> to roll the dice") 
    roll = dice_roll() 
    total = int(roll[0]) + int (roll[1]) 
    if total == 7 or total == 11: 
     print "You rolled a " + str(total) + " on your first roll." 
     print "You win!" 
    elif total == 2 or total == 3 or total == 12: 
     print "You rolled a " + str(total) + " on your first roll." 
     print "You lose!" 
    else: 
     print "You rolled a " + str(total) + " on your first roll." 
     print " " 
     print "Thats your point. Roll it again before you roll a 7 and lose!" 
     point_cycle() 
    global total  

main() 

回答

0

假設你使用python,一個快速和骯髒的解決方案讓你開始可能是這一個:

# Save the dices in a way that allows you to access each line separatedly 
DICES = (None, 
     ("+-------+", "|  |", "| * |", "|  |", "+-------+"), # dice 1 
     ("+-------+", "| *  |", "|  |", "|  * |", "+-------+"), # dice 2 
     <put here the tuples with the other lines of each dice>) 

和使用功能像這樣的:

def print_dices(diceslist): 
    for i in range(5): 
     for dicenum in dicelist: 
      print DICES[dice][i] + " ", 
     print 

打印您想要的骰子,其中diceslist是結果列表,如:(1,3,4)

當然還有更優雅/優化的解決方案,但是這個方法很簡單,可能會讓您接受一個可接受的方向