Save the file as JLottery2.java . 3. a. Create a game called Last Man Standing i
ID: 3842882 • Letter: S
Question
Save the file as JLottery2.java.
3.
a. Create a game called Last Man Standing in which the objective is to select the last remaining JCheckBox. The game contains 10 JCheckBoxes. The player can choose one, two, or three boxes, and then click a JButton to indicate the turn is complete. The computer then randomly selects one, two, or three JCheckBox objects. When the last JCheckBox is selected, display a message indicating the winner. Save the game as LastManStanding.java.
b. In the current version of the Last Man Standing game, the computer might seem to make strategic mistakes because of its random selections. For example, when only two JCheckBox objects are left, the computer might randomly choose to check only one, allowing the player to check the last one and win. Modify the game to make it as smart as possible, using a random value for the number of the computer's selections only when there is no superior alternative. Save the improved game as SmarterLastManStanding.java.
Explanation / Answer
package uk.co.mobsoc.MobsGames.Game;
import java.util.ArrayList;
import uk.co.mobsoc.MobsGames.MobsGames;
import uk.co.mobsoc.MobsGames.Player.AbstractPlayerClass;
import uk.co.mobsoc.MobsGames.Player.LastManStandingCombatant;
public class LastManStanding extends AbstractGame{
int count;
boolean hasStarted;
@Override
public void onStartCountdown(){
MobsGames.announce("A game of Last Man standing has been called. Join before 20 seconds!");
}
@Override
public AbstractPlayerClass getDefaultClassForPlayer(String player){
return new LastManStandingCombatant(player);
}
public void onStart(){
count=0;
}
public ArrayList<String> playersLeft(){
ArrayList<String> list = new ArrayList<String>();
for(AbstractPlayerClass apc : getParticipants()){
if(apc instanceof LastManStandingCombatant){
list.add(apc.getPlayerName());
}
}
return list;
}
public void onEnd(){
if(playersLeft().size()==1){
MobsGames.announce("We have a winner!");
MobsGames.announce(playersLeft().get(0)+" has won this round!");
}else{
MobsGames.announce("The game has been ended without a winner!");
}
}
public boolean checkGameOver(){
return playersLeft().size()==1;
}
public void onTick(){
if(count==0){
//MobsGames.announce("A game of Last Man Standing has been started. Join in the next 20 seconds!");
}
count++;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.