2016-04-13 14 views
0
#branchID pool 
branch0 = "This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text." 
branch1 = "This is a second wall of text." 
branch2 = "This is a third wall of text." 

#classes section 
    #pulls text from pools above. 
branch = (name, branchid)-> 
    stringID = String(branchid) 
    document.write("<h1 id=\'#{stringID}\'>#{name}</h1>") 
    document.getElementById(stringID).onclick = -> 
    document.write(branchid) 

#This is where the game goes. It will be built with conditionals 
window.onload = -> 
    branch('Start', branch0) 

CoffeeScriptを使用してブラウザベースの「自分で冒険を選んで」ゲームを作成しています。上記は私がこれまでに持っていたコードです。 HTML要素が作成され、クリックされると、1つの巨大なブロックのページにテキスト文字列が書き込まれます。大きな文字列を一度に1クリックで表示する

私の質問は、どのようにして一度に文章だけが読み込まれ、クリックされると次の文章が読み込まれ、次に文字列に何も残らなくなるまで次の文章が読み込まれます。

答えて

1

私はあなたが私が(うまくいけば)は何をしたいないこと拠点としてあなたのコードを使用して、あなたのためのデモを作っ達成しようとしていること、それが何であるか、本当にわからないものの:

https://jsfiddle.net/Exinferis/qhr7wjmu/

#branchID pool 
firstBranch = [ 
    "This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text." 
    "This is a second wall of text." 
    "This is a third wall of text." 
] 

currentStep = 0 

#classes section 
    #pulls text from pools above. 
branch = (event)-> 
    if firstBranch[currentStep]? 
    document.getElementById("text").innerHTML = firstBranch[currentStep] 
    currentStep++ 

#This is where the game goes. It will be built with conditionals 
window.onload = -> 
    document.getElementById("nextbtn").onclick = branch 
+0

どうもありがとうございました。これは非常に役に立ちます。 – bryanwillis7

関連する問題