this is the gameboard i created. it creates a 2 dimensional array with the first row as numbers and the first columns are Letters then everything else as tildas (~)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package battleship;
import java.util.*;
/**
*
* @author aschg3
*/
public class Test {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String enter;
Object[][] newgame = new Object[12][12];//[rows][columns]
newgame[0][0] = " ";
for(int i = 1; i < 11; i++)
{
for(int j = 1; j < 11; j++)
{
newgame[i][j] = "~ ";
}
}
for(int i = 0;i<11; i++)
{
newgame[0][i+1] = i+" ";
}
for(int i = 0;i<11; i++)
{
newgame[i+1][0] = (char)(65+i) + " ";
}
System.out.println("Let's play Battle Ship!\n");
for(int i = 0; i<11; i++)
{
for(int j = 0; j<11; j++)
{
System.out.print(newgame[i][j]);
}
System.out.println("");
}
System.out.println("Pick a coordinate");
Scanner keyboard = new Scanner(System.in);
enter = keyboard.nextLine();
}
}
now im making a new class file that takes the input and interpret it as numbers i can plug in into the gameboard for a proper coordinate.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package battleship;
/**
*
* @author aschg3
*/
public class Coordinates {
private static String row;
private static String column;
/* public static void enteredCoord(String input)
{
row = input.substring(0,1);
column = input.substring(1,2);
//return column;
}*/
public static int columnCoord(String coord)
{
column = coord.substring(1,2);
}
/*public static void main(String[] args)
{
String str = "A1";*/
}
}
what im having trouble with is:
the user input would be a Caps letter and a number i.e. (A1). I thought i could take A1.substring(0,1) to take the A and set it as some variable. Then use that variable and convert it to an ANSI character then subtract 65 from it to get a numerical value that i can use for the coordinate system.
Problem: im having trouble converting strings to chars
please help . . . some of the things i said might not make sense because i just started java. sorry i hope u understand what im asking for

New Topic/Question
Reply




MultiQuote









|