Last active
October 15, 2016 19:08
-
-
Save brentonstrine/37253c9ba558892071b2ed125faaf723 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Student project: Rock Paper Scissors | |
// | |
// define score variables for however many players there are | |
var p1s = 0; | |
var p2s = 0; | |
// define variables that keep track of whatever the players choose, whether rock, paper, or scissors. | |
var p = { | |
one : { | |
choose : 0, | |
key1 : 0, | |
key2 : 0, | |
key3 : 0, | |
win : null | |
}, | |
two : { | |
choose : 0, | |
key1 : 0, | |
key2 : 0, | |
key3 : 0, | |
win : null | |
} | |
}; | |
var nwrnd = "n"; | |
// have something that defines what input chooses what option. | |
// I’m assuming here that keyboard inputs will be represented by 1 for ‘this key is being pressed’ and 0 for ‘this key is not being pressed.’ | |
// Also assuming that pressing the 1 on the keyboard sets the p1key1(or whatever) value to 1, and releasing it sets it back to 0. | |
if (p.one.key1 == 1) { | |
p.one.choose = "rck"; | |
} else if (p.one.key2 == 1) { | |
p.one.choose = "ppr"; | |
} else if (p.one.key3 == 1) { | |
p.one.choose = "scr"; | |
} else { | |
p.one.choose = "no"; | |
} | |
if (p.two.key1 == 1) { | |
p.two.choose = "rck"; | |
} else if (p.two.key2 == 1) { | |
p.two.choose = "ppr"; | |
} else if (p.two.key3 == 1) { | |
p.two.choose = "scr"; | |
} else { | |
p.two.choose = "no"; | |
} | |
if (p.one.choose == "no") { | |
p.one.win=0; | |
} | |
if (p.two.choose == "no") { | |
p.two.win=0; | |
} | |
if (p.one.choose == "rck" && p.two.choose == "rck"){ | |
debugger; | |
nwrnd = "y"; | |
} else if (p.one.choose == "rck" && p.two.choose == "ppr") { | |
p.one.win = 1; | |
} else if (p.one.choose == "rck" && p.two.choose == "scr") { | |
p.two.win = 1; | |
} | |
if (p.one.choose == "ppr" && p.two.choose == "rck") { | |
p.one.win = 1; | |
} else if (p.one.choose == "ppr" && p.two.choose == "ppr") { | |
nwrnd = "y"; | |
} else if (p.one.choose == "ppr" && p.two.choose == "scr") { | |
p.two.win = 1; | |
} | |
if (p.one.choose == "scr" && p.two.choose == "rck") { | |
p.two.win = 1; | |
} else if (p.one.choose == "scr" && p.two.choose == "ppr") { | |
p.one.win = 1; | |
} else if (p.one.choose == "scr" && p.two.choose == "scr") { | |
nwrnd = "y"; | |
} | |
// at the end of each session of ro sham bo, it changes the scores of the player variables based on who won. | |
var p1win; | |
var p2win; | |
var y; | |
if (p1win == 1) { | |
p1s = p1s+p1win; | |
} else if (p2win == 1) { | |
//then | |
p2s = p2s+p2win; | |
//then(and?) | |
p1win = 0; | |
//then(and?) | |
p2win = 0; | |
} else { | |
nrnd = y; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment