class DecoloringBonus extends React.Component { constructor(props) { super(props); this.state = { imagePathOutcome: '/static/img/coin_questionmark.png', imagePathGuess: '/static/img/coin.png', winningSide: "", payment: [], key: 0, modal: false, rightSide: "card", } this.submitCoin = this.submitCoin.bind(this); this.winningSideUpdate = this.winningSideUpdate.bind(this); this.calculateEarnings = this.calculateEarnings.bind(this); this.submitCard = this.submitCard.bind(this); this.cardClickAnimation = this.cardClickAnimation.bind(this); this.nextCoin = this.nextCoin.bind(this); this.nextCard = this.nextCard.bind(this); } componentDidMount() { this.calculateEarnings(); // Disable clicks in ball var balls = document.getElementsByClassName("ball") for(var i=0;i { this.cardClickAnimation(cardID, lastOutcome, stopCard) }) } else if (this.props.type == "coin"){ this.setState({ rightSide: "coin", imagePathGuess: this.props.imagePathGuess, imagePathOutcome: this.props.imagePathOutcome, }, () => { if (this.props.imagePathGuess == this.props.imagePathOutcome) { document.getElementById("coinTossWon").classList.remove("d-none"); document.getElementById("moveUp").classList.remove("d-none"); document.getElementById("placeholderFooter").classList.add("d-none"); } else { document.getElementById("coinTossLost").classList.remove("d-none"); document.getElementById("moveDown").classList.remove("d-none"); document.getElementById("placeholderFooter").classList.add("d-none"); } // Grey background for selection section document.getElementById("pickWinningSide").classList.remove("alert-warning"); document.getElementById("pickWinningSide").classList.add("alert-secondary"); var ele = document.getElementsByName("winningSideInput"); for(var i=0;i { const indArray = [ [0], [1, 2], [3, 4, 5], [6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20] ] let upTick = js_vars.upTick let payment = [] let j = 0 for (let i in indArray) { for (let k in indArray[i]) { payment[j] = upTick * i - 2 * k * upTick; j++ } } this.setState({payment}) return payment } // Submit coin toss submitCoin() { liveSend({ 'type': "coin", 'value': this.state.winningSide }) } winningSideUpdate(chosenSide) { // Disable winning side buttons var ele = document.getElementsByName("winningSideInput"); for(var i=0;i {this.submitCoin()}) } else if (chosenSide == "T") { this.setState({ winningSide: chosenSide, imagePathGuess: '/static/img/coin_t.png' }, () => {this.submitCoin()}) } // Grey background for selection section document.getElementById("pickWinningSide").classList.remove("alert-warning"); document.getElementById("pickWinningSide").classList.add("alert-secondary"); var ele = document.getElementsByName("winningSideInput"); for(var i=0;i { // Enable buttons after animation end if (stopCard) { const drawn = this.props.drawn || [0] const roundNumber = this.props.roundNumber || [0] const currentNode = drawn[roundNumber] const payment = this.state.payment[currentNode] liveSend({ 'type': "payment", 'value': payment }) // Show payment information document.getElementById("nextCoinBtn").classList.add("d-none") document.getElementById("continueSection").classList.remove("d-none") document.getElementById("confirm_btn").removeAttribute('disabled'); } else { for (let i=0; i < visibleBtns.length; i++) { visibleBtns[i].removeAttribute('disabled'); } } } ) } } // Show feedback in card display document.getElementById("cardFeedbackPlaceholder").classList.add("d-none") document.getElementById("cardFeedback").classList.remove("d-none") if (cardOutcome == "Stop") { document.getElementById("cardFeedbackText").innerHTML = "You drew a black card." } else { document.getElementById("cardFeedbackText").innerHTML = "You drew a white card." } } nextCoin() { this.setState({ rightSide:"coin" }) } nextCard() { document.getElementById("moveUp").classList.add("d-none") document.getElementById("moveDown").classList.add("d-none") document.getElementById("placeholderFooter").classList.remove("d-none") this.setState({ rightSide:"card" }) } voidFunction(){ return } render() { // Find stop decision let submittedContinuation = this.props.continuationDec.slice(0,this.props.roundNumber + 1) let submittedStop = submittedContinuation.findIndex(element => element == "Stop") // Calculate accumulated earning to show let payment = 0 if (submittedStop >= 0) { payment = parseFloat(this.state.payment[this.props.drawn[submittedStop]]) } else { payment = parseFloat(this.state.payment[this.props.drawn[this.props.roundNumber]]) } return( <>
{/* Left column showing stopping strategy */}
Your decoloring
Your current accumulated earnings are £{payment.toFixed(2)}.
{/* Footer */}
You moved up.
You moved down.
{/* Right column */}
{ (this.state.rightSide == "coin") ? : (this.state.rightSide == "card") ? : <> }
) } }