Question
Create JUnit Test for the following: public class didjaWin extends CodeNames { //method defining if the board is in a winning state AND who won/lost
Create JUnit Test for the following:
public class didjaWin extends CodeNames {
//method defining if the board is in a winning state AND who won/lost
public didjaWin(Location a, CodeNamesBoard b) {
// if red team agents hit 0 blue team wins
// if blue team agents hit 0 red team wins
// if assassin is revealed, team that revealed it loses
Location x = new Location("", "assassin", true);
if (redAgent == "") {
// blue team wins
}
if (blueAgent == "") {
// red team wins
}
if (a == x && redTeamsTurn == true) {
// blue team wins
}
if (a == x && redTeamsTurn == false) {
// red team wins
}
}
}
Codenames.java
package edu.buffalo.cse116;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class CodeNames {
protected String assassin ;
protected String redAgent;
protected String blueAgent;
protected String bystander ;
protected boolean redTeamsTurn;
protected static ArrayList
protected static ArrayList
protected static ArrayList
public CodeNames() {
}
// create a list of 25 codenames
// still need more tweaks to it, not sure where
public ArrayList
codename = new ArrayList
ArrayList
try (BufferedReader file = new BufferedReader(new FileReader("gamename"))) {
String sCurrentLine;
while ((sCurrentLine = file.readLine()) != null) {
codename.add(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
}
return codename;
}
// call the variable codename and set it to shuffle the names in the list
public static void changeName(ArrayList
String set = codename.get(i);
codename.set(i, codename.get(change));
codename.set(change, set);
}
// it shuffles the name when codename is called
public ArrayList
int name = codename.size();
Random random = new Random();
random.nextInt();
for (int i = 0; i < name; i++) {
int change = i + random.nextInt(name - i);
changeName(codename, i, change);
}
return codename;
}
// create a list of 25 players
// still need more tweaks to it, not sure where
public ArrayList
player = new ArrayList
ArrayList
try (BufferedReader file = new BufferedReader(new FileReader("Players"))) {
String sCurrentLine;
while ((sCurrentLine = file.readLine()) != null) {
player.add(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
}
return player;
}
// call the variable player and set it to shuffle the names in the list
public static void changePlayer(ArrayList
String set = player.get(i);
player.set(i, player.get(change));
player.set(change, set);
}
// it shuffles the name when codename is called
// but don't know how to assign it to the players
public ArrayList
int name = player.size();
Random random = new Random();
random.nextInt();
for (int i = 0; i < name; i++) {
int change = i + random.nextInt(name - i);
changePlayer(player, i, change);
}
return player;
}
// creates code name for each team and return it has a arraylist.
public ArrayList
holdCodeName = new ArrayList
for(int i=0;i<9;i++){
redAgent=codename.get(i);
holdCodeName.add(redAgent);
}
for(int i=0;i<8;i++){
blueAgent=codename.get(i);
holdCodeName.add(blueAgent);
//System.out.println(blueAgent);
}
for(int i=0;i<7;i++){
bystander=codename.get(i);
holdCodeName.add(bystander);
//System.out.println(bystander);
}
for(int i=0;i<1;i++){
assassin=codename.get(i);
holdCodeName.add(assassin);
//System.out.println(assassin);
}
return holdCodeName;
}
// swap the name if two players have the same name
public static void switchname(int swap, int position) {
for(int i=0;i Collections.swap(holdCodeName, position,swap); } System.out.println(holdCodeName); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started