25.07.2017 Views

Intro-CSharp-Book-v2015

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1078 Въведение в програмирането със C#<br />

for (int i = 0; i < count; i++)<br />

{<br />

matrix[positionY, positionX] = i;<br />

if (stepPosition < stepsCount)<br />

{<br />

stepPosition++;<br />

}<br />

else<br />

{<br />

stepPosition = 1;<br />

}<br />

if (stepChange == 1)<br />

{<br />

stepsCount++;<br />

}<br />

stepChange = (stepChange + 1) % 2;<br />

direction = (direction + 1) % 4;<br />

}<br />

}<br />

switch (direction)<br />

{<br />

case 0:<br />

positionY++;<br />

break;<br />

case 1:<br />

positionX--;<br />

break;<br />

case 2:<br />

positionY--;<br />

break;<br />

case 3:<br />

positionX++;<br />

break;<br />

}<br />

private static void PrintMatrix(int[,] matrix, int n)<br />

{<br />

for (int i = 0; i < n; i++)<br />

{<br />

for (int j = 0; j < n; j++)<br />

{<br />

Console.Write("{0,3}", matrix[i, j]);<br />

}<br />

Console.WriteLine();<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!