1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
////////////////////////////////////////////////////////////
public void startGame() {
// set action on team A buttons click
for (int i = 0; i < TA_ImageButtons.length ; i++) {
final ImageButton myButton = TA_ImageButtons[i];
myButton.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
//create a dialog with question
if (PlayersOrder[whosTurn].getName() == myButton.getTag()) {
removeDialog(myButton.getId());
showDialog(myButton.getId());
}
else {
for (int i=0; i < PlayersOrder.length; i++) {
if (PlayersOrder[i].getName() == myButton.getTag())
otherPlayer = PlayersOrder[i];
}
isAnotherPlayerAnswering = true;
removeDialog(myButton.getId());
showDialog(myButton.getId());
}
}
});
}
// set action on team B buttons click
for (int i = 0; i < TB_ImageButtons.length ; i++) {
final ImageButton myButton = TB_ImageButtons[i];
myButton.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
//create a dialog with question
if (PlayersOrder[whosTurn].getName() == myButton.getTag()) {
removeDialog(myButton.getId());
showDialog(myButton.getId());
}
else {
for (int i=0; i < PlayersOrder.length; i++) {
if (PlayersOrder[i].getName() == myButton.getTag())
otherPlayer = PlayersOrder[i];
}
isAnotherPlayerAnswering = true;
removeDialog(myButton.getId());
showDialog(myButton.getId());
}
}
});
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Create the dialog
public Dialog onCreateDialog(int id) {
Dialog dialog = null;
if (!isAnotherPlayerAnswering) {
String title = PlayersOrder[whosTurn].getName()+", "+PlayersOrder[whosTurn].getTeam();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(question[qnumber])
.setTitle(title)
.setCancelable(true)
.setPositiveButton("2 points", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
PlayersOrder[whosTurn].setScore1( PlayersOrder[whosTurn].getScore1()+2 );
if (PlayersOrder[whosTurn].getTeam() == "Team A" ) {
ScoresRound.setScoreTeamA(ScoresRound.getScoreTeamA()+2);
ScoresMatch.setScoreTeamA(ScoresMatch.getScoreTeamA()+2);
teamAhouse++;
}
else {
ScoresRound.setScoreTeamB(ScoresRound.getScoreTeamB()+2);
ScoresMatch.setScoreTeamB(ScoresMatch.getScoreTeamB()+2);
teamBhouse++;
}
updateGame();
}
})
.setNeutralButton("1 point", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
PlayersOrder[whosTurn].setScore2( PlayersOrder[whosTurn].getScore2()+1 );
if (PlayersOrder[whosTurn].getTeam() == "Team A" ){
ScoresRound.setScoreTeamA(ScoresRound.getScoreTeamA()+1);
ScoresMatch.setScoreTeamA(ScoresMatch.getScoreTeamA()+1);
}
else {
ScoresRound.setScoreTeamB(ScoresRound.getScoreTeamB()+1);
ScoresMatch.setScoreTeamB(ScoresMatch.getScoreTeamB()+1);
}
updateGame();
}
})
.setNegativeButton("No point!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
updateGame();
}
});
dialog = builder.create();
}
else {
String title2 = otherPlayer.getName()+", "+otherPlayer.getTeam();
AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
builder2.setMessage(question[qnumber])
.setTitle(title2)
.setCancelable(false)
.setPositiveButton("1 point", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
otherPlayer.setScore2( otherPlayer.getScore2()+1 );
if (otherPlayer.getTeam() == "Team A" ){
ScoresRound.setScoreTeamA(ScoresRound.getScoreTeamA()+1);
ScoresMatch.setScoreTeamA(ScoresMatch.getScoreTeamA()+1);
}
else {
ScoresRound.setScoreTeamB(ScoresRound.getScoreTeamB()+1);
ScoresMatch.setScoreTeamB(ScoresMatch.getScoreTeamB()+1);
}
updateGame();
}
})
.setNegativeButton("No point!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
updateGame();
}
});
dialog = builder2.create();
}
return dialog;
}// end of onCreateDialog |
Partager