Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 holdCodeName;

protected static ArrayList codename;

protected static ArrayList player;

public CodeNames() {

}

// create a list of 25 codenames

// still need more tweaks to it, not sure where

public ArrayList getName() throws FileNotFoundException {

codename = new ArrayList(25);

ArrayList chosenName = new ArrayList(25);

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 ok, int i, int change) {

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 Shufflecodenames() {

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 getPlayers() throws FileNotFoundException {

player = new ArrayList(25);

ArrayList chosenPlayer = new ArrayList(25);

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 ok, int i, int change) {

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 ShufflePlayer() {

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 createTeams() {

holdCodeName = new ArrayList(25);

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

What is the relationship between humans and nature?

Answered: 1 week ago