Skip to content

Instantly share code, notes, and snippets.

@asidiali
Created September 20, 2016 19:34
Show Gist options
  • Save asidiali/b567bcb4782d85b064ce9b030978d8d2 to your computer and use it in GitHub Desktop.
Save asidiali/b567bcb4782d85b064ce9b030978d8d2 to your computer and use it in GitHub Desktop.
Demo for Lawn Love
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo Project</title>
</head>
<body>
<button class="play">Play</button>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
var state = {
currentTeam: 1,
score: {
red: 0,
blue: 0,
},
currentPlayer: 1,
};
var teams = [
{
name: 'blue',
players: [
'adam',
'justin',
'eric',
],
},
{
name: 'red',
players: [
'jeremy',
],
},
];
var options = {
rounds: 5,
};
$(document).ready(function () {
// renderGameboard();
});
$('.play').on('click', function () {
for (var count = 0; count < options.rounds; count++) {
var team = teams[state.currentTeam - 1];
console.log(team.name);
var player = (team.players.length >= state.currentPlayer) ? team.players[state.currentPlayer - 1] : team.players[0];
if (state.currentTeam >= teams.length) {
console.log('last team');
var opponentTeam = teams[0];
var opponent = (opponentTeam.players.length >= state.currentPlayer) ? opponentTeam.players[state.currentPlayer - 1] : opponentTeam.players[0];
console.log(player + ' vs ' + opponent);
if (player.length > opponent.length) {
state.score[team.name] += 1;
} else if (player.length < opponent.length) {
state.score[opponentTeam.name] += 1;
} else if (player.length == opponent.length) {
state.score[opponentTeam.name] += 1;
state.score[team.name] += 1;
}
console.log(state);
state.currentTeam = 1;
if (state.currentTeam % 2 == 0) state.currentPlayer += 1;
} else {
var opponentTeam = teams[state.currentTeam];
var opponent = (opponentTeam.players.length >= state.currentPlayer) ? opponentTeam.players[state.currentPlayer - 1] : opponentTeam.players[0];
console.log(player + ' vs ' + opponent);
if (player.length > opponent.length) {
state.score[team.name] += 1;
} else if (player.length < opponent.length) {
state.score[opponentTeam.name] += 1;
} else if (player.length == opponent.length) {
state.score[opponentTeam.name] += 1;
state.score[team.name] += 1;
}
console.log(state);
state.currentTeam += 1;
if (state.currentTeam % 2 == 0) state.currentPlayer += 1;
}
}
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment