予期しない「]」式で私が正常に動作するコードの最初の部分を取得するために管理し、現在保存されたインデックスを使用してプレイヤー本当のスコアを見つけたいき三項演算子は、Arrayインデックスを選択する
メンバーの中に。私はplayersTurn
を使用していて、その奇数かそれともプレイヤーが変わったかをチェックしています。
私は今、次のコード行でスコアを取得するために三項演算子を使用しているが午前問題:
let score = this.scoring[this.playersTurn % 2 = 0 ? this.playerOneScore : this.playerTwoScore]
すべてのヘルプは素晴らしいだろう、ここでは完全なコードは次のとおりです。
open System
type Game(playerOne, playerTwo) =
member this.playersTurn = 0
member this.playerOneName = playerOne
member this.playerOneScore = 0
member this.playerTwoName = playerTwo
member this.playerTwoScore = 0
member this.scoring = [|0; 15; 30; 40|]
member this.takeTurn() =
let name = this.playersTurn % 2 = 0 ? this.playerOneName : this.playerTwoName
let score = this.scoring[this.playersTurn % 2 = 0 ? this.playerOneScore : this.playerTwoScore]
printfn name |> "%d is now taking their turn."
if((new System.Random()).Next(0, 15) > 8) then
if (this.playersTurn % 2 = 0) then incr this.playerOneScore
else incr this.playerTwoScore
printfn name |> "%d scored a point!"
else
printfn name |> "%d did not score a point!"
incr this.playersTurn
let tennis = new Game("Player1", "Player2")
tennis.takeTurn()
tennis.takeTurn()
クイックルック。 1つは配列 '[| |] '、リストは' [] 'です。 –
このコメントにJustin Niessnerの答えを組み合わせると、 'this.scoring [| index |] '? @GuyCoder – KDOT
ええ、私はそれを仮定しました。私はF#の男ではなく、ただハハを学ぼうとしています。それは有り難いです。 @GuyCoder – KDOT