Skip to content

Commit

Permalink
n players can join the game!
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Mar 16, 2017
1 parent 952249e commit e3fb689
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 67 deletions.
67 changes: 1 addition & 66 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,7 @@
<script src="./bootstrap.min.js"></script>
</head>
<body>
<div id="players">
<div class="col-xs-3 col-sm-3 col-md-3" id="p1">
<div class="thumbnail">
<img alt="Icon of Player 1">
<div class="caption">
<h3>Player 1</h3>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text"
class="form-control"
placeholder="GitHub ID"
aria-describedby="basic-addon1"
onchange="game.players[0].updateName(this.value)">
</div>
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3" id="p2">
<div class="thumbnail">
<img alt="Icon of Player 2">
<div class="caption">
<h3>Player 2</h3>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text"
class="form-control"
placeholder="GitHub ID"
aria-describedby="basic-addon1"
onchange="game.players[1].updateName(this.value)">
</div>
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3" id="p3">
<div class="thumbnail">
<img alt="Icon of Player 3">
<div class="caption">
<h3>Player 3</h3>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text"
class="form-control"
placeholder="GitHub ID"
aria-describedby="basic-addon1"
onchange="game.players[2].updateName(this.value)">
</div>
</div>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3" id="p4">
<div class="thumbnail">
<img alt="Icon of Player 4">
<div class="caption">
<h3>Player 4</h3>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text"
class="form-control"
placeholder="GitHub ID"
aria-describedby="basic-addon1"
onchange="game.players[3].updateName(this.value)">
</div>
</div>
</div>
</div>
</div>
<div id="players"></div>

<div style="clear: both;"></div>

Expand Down
29 changes: 28 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,37 @@ class Player {

class Game {
constructor() {
this.players = [0, 1, 2, 3].map(i => new Player(i, this));
this.players = [];
for (var i = 0; i < navigator.getGamepads().length; i++) {
if (navigator.getGamepads()[i]) {
this.addPlayer(i);
}
}
this.enter();
}

addPlayer(index) {
$('#players').append(`
<div class="col-xs-3 col-sm-3 col-md-3" id="p${index + 1}">
<div class="thumbnail">
<img alt="Icon of Player ${index + 1}">
<div class="caption">
<h3>Player ${index + 1}</h3>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="text"
class="form-control"
placeholder="GitHub ID"
aria-describedby="basic-addon1"
onchange="game.players[${index}].updateName(this.value)">
</div>
</div>
</div>
</div>
`);
this.players.push(new Player(index, this));
}

enter() {
this.waiting = false;
this.entering = true;
Expand Down

0 comments on commit e3fb689

Please sign in to comment.