java - Vector, Point, Battleship, 2D -


Will I schedule some battles in Java for the battleship?

  Make a static point [] Make skip with the length (int.)      p>  bring , a random position on the field and a random direction, and gives a reference to the ship.  

The ship will be of type point and we will use the object vector as a container for all ships.

I still have the full program code:

  import java.awt. *; Import java.awt.Point; Import java.lang *; Import java.util. *; Public class Programm34 {public int anzahlschiffe = 5; Public Point [] Skiff = New Point [Enhalskyf]; Public static zero main (string [] args) {vector v = new vector (); int i = 10; Double random = 0; System.out.println ("Zufolzzhelen:"); For (i = anzahlschiffe; i> i;) - {random = random (0,10); System.out.print ((int) random + ""); Println (""); } // test FRI method !! Int [] [] Spiegel = new int [10] [10]; Init (Spielfeld); For (int x = 9; x> = 0; x -) {for (int y = 9; y> gt; y -) {System.out.print (Spieelfeld [x] [y]); If (y! = 0) {System.out.print (""); } If (y == 0 & amp; x! = 0) {System.out.print ("\ n"); }}}} Private static long random (int u, int o) {double random; Random = math.random () * (U-O) + O; Random (int); } Private static point [] Make skif (will bring) {point (1,2); Private static boolean concept (vector & lieutenant; point []> shifa, point [1], private statistical boolean granage (point [] skiff) Private static boolean nubbar (vector & lefthinum; point [] & gt; shifey, point [] Schiff) {} Private steady Boolean increment (vector & lieutenant; point []> shifes, int langes} {} private static zero Init Int [] [] Spielfeld) {for (int i = 9; i & Gt; = 0; i -) {for (int j = 9; j & gt; = 0; j -) {spielfe Ld [i] [j] = 0;}}}} add private static zero (int [] [] spellfold, vector & lt; point []> gt; schiffe} {}}   < P> All those methods and main programs will be, but what matters createstchiff ("createship") is one.  

Can you help me explain the vector? Point? And how does the whole thing work? I am not sitting here for 2 hours ... there is no progress ... thx lot

< P> First a minor (but helpful) thing: You should add a generic parameter to the vector. (I doubt it is necessary to use vector . list should be sufficient. But when it is in the assignment, you have to do it ...)
  vector & lt; Point [] & gt; V = new vector & lt; Point [] & gt; (); Regarding the method:   

createSchiff : You will have to create many points objects, i.e., an area for which the ship is covered by . This can look broadly like this:

  Make a personal fixed point [] Create a square (int) {int pause x = ... // some random position int status Y = .. // Make some random condition // array that contains the fields covered / covered: the result of the point [] = new point [ll]; // fill the array for (int i = 0; i & lt; laenge; i ++) {result [i] = new point (positionX, positionY); // Change the position for the next field, // Based on the direction of the ship: positionX + = ... positionY + = ...} return result; }   

Then you can call this method like this:

  Point ship [] = constructor (3); v.add (ship);   

(I can insert more actual code than placeholder ... , but you should try it yourself)

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -