I am working on an AI project and am trying to build a Video Game Selector. The user would input what genre, mode, rating and platform of a game they would like to play. Then the program would take that input, and then select games within the gameList array that match that criteria. Then, it would randomly select a game from the gameList array matching the criteria and output the randomly selected game as a suggestion for the user to play. I'm not as experienced in Java, done more C++ coding before, but my professor suggested we do this project in Java so figured I'd give it a go since I'm graduating at the end of this semester and wanted more experience in Java when applying for jobs/internships.
I'm having an issue trying to come up with the best way to use the user input to assign or check it against elements within each array (I have an array for genre, mode, rating and platform) to then have games that would match that criteria be able to be randomly selected to suggest to the user of which game to play.
If anyone has any ideas on a better approach then I currently have or a better and easier way to go about doing this that would be hugely helpful!
Here is the code I currently have (some of from a previous assignment so ignore the printPeas() and other stuff that isn't revenant to the arrays. The code currently isn't working unfortunately:
package Games;
import java.util.Scanner;
public class Games
{
String _gameType;
String _genreType;
String _gameMode;
String _gameRating;
String _tType;
public static Scanner input = new Scanner(System.in);
public Games(String type)
{
_gameType = type;
System.out.println("Suggested type of game is: " + _gameType);
}
public Games()
{
_gameType = "Sports";
System.out.println("Suggested type of game is: " + _gameType);
}
public void typeInput(String tType)
{
_tType = tType;
System.out.println("Type of Game selected: " + _tType);
}
public void genreInput(String gType)
{
_genreType = gType;
System.out.println("Type of Genre selected: " + _genreType);
}
public void modeInput(String gMode)
{
_gameMode = gMode;
System.out.println("Type of Game Mode selected: " + _gameMode);
}
public void ratingInput(String gRating)
{
_gameRating = gRating;
System.out.println("Type of Rating selected: " + _gameRating);
}
public void printPeas()
{
String agent = "Agent = Video Game Seletor.";
String perfmeasure = "P = If it meets the users information being input.";
String environment = "E = All games within a certain location.";
String actuators = "A = Library of games to select from, and the display of which game was selected.";
String sensors = "S = Keyboard input.";
System.out.println(agent);
System.out.println(perfmeasure);
System.out.println(environment);
System.out.println(actuators);
System.out.println(sensors);
}
}
package Games;
import java.util.ArrayList;
import java.util.Random;
public class Game
{
public static String _genreType;
public static String _gameMode;
public static String _gameRating;
public static String _gameName;
public void setGame(String genre, String mode, String rating)
{
_genreType = genre;
_gameMode = mode;
_gameRating = rating;
_gameName = "";
Random random = new Random();
String gameList[] = {"NHL '18", "Madden '18", "Call of Duty: WW2", "GTA V", "Counter-Strike: Global Offsnsive",
"World of Warcrat", "PUBG", "Assassin's Creed Origins", "Hearthstone", "Battlefield 4"};
String genreList[] = {"Action", "Sports", "Racing", "MMORPG", "Strategy", "Fighting", "Fantasy"};
String modeList[] = {"Multiplayer", "Online", "Campaign"};
String ratingList[] = {"Everyone", "E10+", "Teen", "Mature"};
String platformList[] = {"PC", "PS4", "Xbox"};
for(int i=0; i<gameList.length; i++) //trying to have it pull a random game name matching type, genre, mode and rating
{
if(genre == genreList[i])
{
_genreType = genre;
}
if(mode == modeList[i])
{
_gameMode = mode;
}
System.out.println(gameList[random.nextInt(gameList.length)]);
}
}
}
package Games;
import java.util.Scanner;
public class StartSelector
{
public static String _gameType;
public static String _genreType;
public static String _gameMode;
public static String _gameRating;
public static Scanner userInput = new Scanner(System.in);
public static void main(String[] args)
{
String gameType = _gameType, genreType = _genreType, gameMode = _gameMode, gameRating = _gameRating;
Games gameType1 = new Games();
gameType1.printPeas();
Games gameType2 = new Games("Action");
gameType2.printPeas();
Games gameSelect = new Games();
System.out.println("Please enter the Genre Type: ");
genreType = userInput.next();
gameSelect.genreInput(genreType);
System.out.println("Please enter the Game Type: ");
gameType = userInput.next();
gameSelect.typeInput(gameType);
System.out.println("Please enter the Game Mode: ");
gameMode = userInput.next();
gameSelect.modeInput(gameMode);
System.out.println("Please enter the Game Rating: ");
gameRating = userInput.next();
gameSelect.ratingInput(gameRating);
userInput.close();
System.out.println("You have selected a " + genreType + " "
+ gameType + " " + gameMode + " " + gameRating
+ " game to play.");
gameType1.setGame("Action", "Online", "Mature", "GTA V");
}
}