public class RowGame { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String pro="Please enter the number of spaces for the game (1-40): "; int space=promptNumberReadLine(scanner,pro,40); int[] game=new int[space]; System.out.println(rowToString(game)); int count=0; int p1; int p2; String pp1="X, please enter your move (1-"+space+"): "; String pp2="O, please enter your move (1-"+space+"): "; int win=0; while(win==0){ if(count%2==0){ p1=promptNumberReadLine(scanner,pp1,space); while(!makeMove(game,1,p1)){ System.out.println("That space is not available! Please try again."); p1=promptNumberReadLine(scanner,pp1,space); } System.out.println(rowToString(game)); }else{ p2=promptNumberReadLine(scanner,pp2,space); while(!makeMove(game,2,p2)){ System.out.println("That space is not available! Please try again."); p2=promptNumberReadLine(scanner,pp2,space); } System.out.println(rowToString(game)); } count++; win=winner(game); } if(win==1){ System.out.println("Game over! X wins."); }else if(win==2){ System.out.println("Game over! O wins."); }else if (win==-1){ System.out.println("Game over! Tie game!"); } } public static int promptNumberReadLine(Scanner s, String prompt, int max){ int num=1; String n=""; do { if(num < 1||num>max){ System.out.println("That was not a valid number! Please try again."); } System.out.print(prompt); while (!s.hasNextInt()) { s.nextLine(); System.out.println("That was not a valid number! Please try again."); System.out.print(prompt); } n= s.nextLine(); while(!isNumber(n)){ System.out.println("That was not a valid number! Please try again."); System.out.print(prompt); n= s.nextLine(); } int result = Integer.parseInt(n); num =result; }while (num < 1||num>max); return num; } public static boolean isNumber(String str) { int size = str.length(); for (int i = 0; i < size; i++) { if (!Character.isDigit(str.charAt(i))) { return false; } } return size > 0; } public static String rowToString(int[] game){ String row=""; for(int i=0;ip2){ return 1; }else if(p1game.length||position<1){ return false; }else{ if(game[position-1]==0){ game[position-1]=player; if(position==2){ if(game[0]!=player&&game[0]!=0&&game[0]!=3){ game[0]=3; } }else if(position==game.length-1){ if(game[game.length-1]!=player&&game[game.length-1]!=0&&game[game.length-1]!=3){ game[game.length-1]=3; } } int count=0; for(int i=0;i