class WalkingTask extends React.Component { constructor(props) { super(props); this.state = { rightSide: "instruction", rightSideHeader:"Your instruction at the pulsing ball", imagePathOutcome: '/static/img/coin_questionmark.png', imagePathGuess: '/static/img/coin.png', winningSide: "", payment: [], keyNum: 0, modal: false, } this.submitCoin = this.submitCoin.bind(this); this.nextBall = this.nextBall.bind(this); this.winningSideUpdate = this.winningSideUpdate.bind(this); this.calculateEarnings = this.calculateEarnings.bind(this); this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); this.submitNodeInstruction = this.submitNodeInstruction.bind(this); this.cardClickAnimation = this.cardClickAnimation.bind(this); this.submitCard = this.submitCard.bind(this); this.nextCoin = this.nextCoin.bind(this); this.afterBonusBall = this.afterBonusBall.bind(this); } componentDidMount() { // Disable ball clicks var balls = document.getElementsByClassName("ball") for(var i=0;i { document.getElementById("confirm_btn").disabled = false; }, 1000) } else if (!this.props.practiceRound) { this.openModal(); // Add costly text if necessary if (this.props.costly && !this.props.practiceRound) { document.getElementById("decoloringCostInfo").classList.add("d-none") document.getElementById("costlyDecoloring").innerHTML = ` less the cost for using numbered balls of £${this.props.decoloringCosts}, ` } // Hide risk info document.getElementById("riskInfo").classList.add("d-none") } else { document.getElementById("confirm_btn").classList.remove("d-none") document.getElementById("confirm_btn").disabled = false; document.getElementById("remainingRounds").classList.add("d-none") document.getElementById("nextScreen").classList.remove("d-none") document.getElementById("accumulatedEarningsDiv").style.visibility = "hidden" document.getElementById("task").classList.add("d-none") if ( ! this.props.cardOutcome.slice(0,this.props.roundNumber).includes("Stop")){ // Only stop in last round // Include information about five risks for all Walking Tasks document.getElementById("fiveRisks").classList.remove("d-none") } } } else if (this.props.type == "nodeChoice") { // Last decision was instruction // Card drawing must be next this.setState({ rightSide: "card", }) } else if (this.props.type == "card") { // Card was clicked before, show animation const cardID = "virtualCard_" + (this.props.previousValue - 1).toString() const lastOutcome = this.props.cardOutcome[this.props.roundNumber] let stopCard = (lastOutcome == "Stop") if (this.props.roundNumber > 0 && this.props.cardOutcome.slice(0, this.props.roundNumber).includes("Stop")){ stopCard = false } this.setState({ rightSide: "card", }, () => { 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 }) } afterBonusBall() { document.getElementById("risksToTake").classList.remove("d-none") if (this.props.practiceRound) { $('#moreRisks').collapse('show') document.getElementById("task").classList.add("d-none") } else { document.getElementById("riskInfo").classList.add("d-none") if (this.props.costly) { document.getElementById("decoloringCostInfo").classList.add("d-none") } } document.getElementById("accumulatedEarningsDiv").style.visibility = "hidden" if (this.props.type == "coin") { this.setState({ imagePathGuess: this.props.imagePathGuess, imagePathOutcome: '/static/img/coin_questionmark.png', }, () => { document.getElementById("placeholderFooter").classList.add("d-none"); document.getElementById("noFeedback").classList.remove("d-none"); // Hide Feedback sections document.getElementById("coinTossLost").classList.add("d-none"); document.getElementById("moveDown").classList.add("d-none"); document.getElementById("coinTossWon").classList.add("d-none"); document.getElementById("moveUp").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 { // Enable buttons after animation end if (stopCard) { this.openModal(); } 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." } } submitCard(cardID) { // Submitted after button click post animation liveSend({ 'type': "card", 'value': parseInt(cardID.slice(-1)) + 1, }) } 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 { this.afterBonusBall(); if (this.props.practiceRound) { // Disable coin click for (let radio of document.querySelectorAll('input[type=radio]')) { radio.disabled = true; } document.getElementById("pickWinningSide").classList.remove("alert-warning") document.getElementById("pickWinningSide").classList.add("alert-secondary") setTimeout( () => { for (let radio of document.querySelectorAll('input[type=radio]')) { radio.disabled = false; } document.getElementById("pickWinningSide").classList.remove("alert-secondary") document.getElementById("pickWinningSide").classList.add("alert-warning") }, 5000) } }) } nextCoin() { this.setState({ rightSide:"coin" }) } 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]]) } // Write payment to main page if (! this.props.practiceRound) { document.getElementById("finPay1").innerHTML = payment.toFixed(2) } return( <>
{/* Left column showing stopping strategy */}
Your decoloring
Your current accumulated earnings are £{payment.toFixed(2)}.
{ (! this.state.modal) ? <> : <> }
{/* Footer */}
{ !(this.props.continuationDec.slice(0,5).includes("Stop")) ?
You moved up.
: <>}
{ !(this.props.continuationDec.slice(0,5).includes("Stop")) ?
You moved down.
: <>}
{/* Right column */} {this.state.rightSide == "instruction" ? : (this.state.rightSide == "coin") ?
: (this.state.rightSide == "card") ?
: <> }
) } } class BonusModal extends React.Component { constructor(props) { super(props); this.state = { keyForTriangle: 0, } } componentDidMount() { this.setState({keyForTriangle: 5}, () => { if (this.props.show) { const balls = document .getElementById("cardBodyModal") .getElementsByClassName("ball") for (let i=0; i < balls.length; i++){ balls[i].style.cursor = 'not-allowed'; balls[i].setAttribute("disabled", "disabled"); } } }) } voidFunction() { return; } render() { if(!this.props.show){ return null; } else { $('#staticBackdrop').modal("show") } return ( <> )} }