Create Task
Create Task
// Diamonds
"1D", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "11D", "12D", "13D",
// Hearts
"1H", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "11H", "12H", "13H",
// Clubs
"1C", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "11C", "12C", "13C",
// Spades
"1S", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "11S", "12S", "13S"];
//Used AI to create this list of values
ar times = 0;
v
onEvent("infobutton", "click", function( ) {
setScreen('screen2');
});
onEvent("backinfobutton", "click", function( ) {
setScreen('screen1');
});
setText("winLabel","Press War to start");
ar wincountp1 = 0;
v
var wincountp2 = 0;
var tiesout = 0;
function compare(card1,card2) {
var valuep1 = parseInt(card1.substring(0,card1.length-1));
var valuep2 = parseInt(card2.substring(0,card2.length-1));
//used AI to figure out how to take integer value from string
//compare the 2 values from the cards
if (valuep1 > valuep2) {
wincountp1++;
console.log('Player 1 wins this round with ' + card1);
}
else if (valuep2 > valuep1) {
wincountp2++;
console.log('Player 2 wins this round with ' + card2);
}
if(valuep1 == valuep2){
console.log('this round was a tie');
tiesout++;
}
//update the labels
if (wincountp1 > wincountp2) {
setText("winLabel","Player 1 is Winning!");
}
else if (wincountp2 > wincountp1){
setText("winLabel","Player 2 is Winning");
}
else{
setText("winLabel","It's A Tie!");
}
var personalwincountp1 = '';
var personalwincountp2 = '';
var ties = '';
//set the textboxes for win counts
personalwincountp1 = 'P1: ' + wincountp1;
setText("p1winlabel",personalwincountp1);
personalwincountp2 = 'P2: ' + wincountp2;
setText("p2winlabel",personalwincountp2);
ties = 'Ties: ' + tiesout;
setText("tielabel",ties);
}
function runcard(times) {
//create the final rounds text
var roundsText = '';
for (var i = 0; i < times; i++) {
times = getNumber("roundsinput");
//create the cards
var playercard1 = deck[randomNumber(0, deck.length - 1)];
var playercard2 = deck[randomNumber(0, deck.length - 1)];
var index = i + 1;
//update the final rounds text
roundsText += "Round: " + index + "|" + playercard1 + " vs " + playercard2 + "\n";
compare(playercard1, playercard2);
setText("Rounds",roundsText);
}
}