I am creating a Battleship style game for a class project and I found this piece of code found below and my game only works with it in the code. I would like to have a better understanding of what the variables mean, they are not used in the code prior to this(other than "board"). Thank you for any help given.
i = 1+size*rand;j = 1+size*rand;loop = 1;while (loop) temp = rand * 3; dx = 0; if (temp > 2) dx = 1; elseif (temp < 1) dx = -1; end temp = rand * 3; dy = 0; if (temp > 2) dy = 1; elseif (temp < 1) dy = -1; end i0 = dx * 4 + i; j0 = dy * 4 + j; if (i0 > 0 && i0 <= size && j0 > 0 && j0 <= size) loop = 0; end if (dx == 0 && dy == 0) loop = 1; end end for I = 0:3 Board(int32(i + I * dx),int32(j + I * dy))=1;end
Best Answer