جاري التطوير .......
import java.io.*;
public class SimpleDotCom2{
int [] locationCells;
int numofhits=0;
public void setLocationCells(int[]locs){
locationCells=locs;
}
public String checkyourself(String stringGuess){
int guess=Integer.parseInt(stringGuess);
String result="miss";
for(int i=0;i<locationCells.length;i++)
{
if(guess==locationCells)
{
result="hit";
numofhits++;
break;
}
}
if(numofhits==locationCells.length){
result="kill";
}
System.out.println(result);
return result;
}
public static void main(String [] args){
int numofguesses=0;//conter whit plyer
SimpleDotCom2 dot=new SimpleDotCom2();
Gamehelper helper=new Gamehelper();
int randomnum=(int)(Math.random()*5);
int [] locationCells={randomnum,randomnum+1,randomnum+2};
dot.setLocationCells(locationCells);
boolean isAlive=true;
while(isAlive==true){
String guess=helper.getuserinput("enter a number");
String result=dot.checkyourself(guess);
numofguesses++;
if(result.equals("kill")){
isAlive=false;
System.out.println(numofguesses+"guesses");
}}
}
public static class Gamehelper{
public String getuserinput(String prompt)
{
String inputline=null;
System.out.print(prompt+" ");
try{
BufferedReader is =new BufferedReader(new InputStreamReader(System.in));
inputline=is.readLine();
if(inputline.length()==0)
return null;
}catch(IOException e){
System.out.println("ioexception:"+e);
}return inputline;
}
}
}دائما عودتوني على ملاحظاتكم لاكوادني .....
لا تنسوا هذا الكود فهو من اكوادي