Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N人プレイ対応 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 1 addition & 64 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,7 @@
<script src="./bootstrap.min.js"></script>
</head>
<body>
<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 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