C
C#9mo ago
HD-Fr0sT

I need help with cursor logic

the cursor moves one one space but i need it to always move where there is text and not empty spaces
5 Replies
HD-Fr0sT
HD-Fr0sTOP9mo ago
using System.Diagnostics;

int[,] grid = {
{1, 2, 3,},
{4, 5, 6,},
{7, 8, 9,},
};

int kolumnMAX = grid.GetLength(0) -1 ;
int radMAX = grid.GetLength(1) -1;

int kolumn = 0;
int rad = 0;

ConsoleKeyInfo key;

Console.Clear();

for (int i = 0; i < grid.GetLength(0); i++)
{
for (int j = 0; j < grid.GetLength(1); j++)
{
Console.Write(grid[i,j]);
Console.Write(" ");
}

Console.WriteLine(" ");
}

while (true)
{




key = Console.ReadKey();

switch (key.Key)
{

case ConsoleKey.UpArrow:
kolumn--;
break;

case ConsoleKey.DownArrow:
kolumn++;
break;

case ConsoleKey.LeftArrow:
rad--;
break;

case ConsoleKey.RightArrow:
rad++;
break;
}

if (kolumn>kolumnMAX)
{
kolumn=0;
}

else if(kolumn<0)
{
kolumn = kolumnMAX;
}

if (rad>radMAX)
{
rad=0;
}

else if(rad<0)
{
rad = radMAX;
}

//Switch gillar ej dynamiska tal
/* switch (kolumn)
{

case >2:
kolumn = 0;
break;

case <0:
kolumn = 2;
break;

} */

/* switch (rad)
{
case >2:
rad = 0;
break;

case <0:
rad = 2;
break;
} */


Console.SetCursorPosition(rad , kolumn);


}
using System.Diagnostics;

int[,] grid = {
{1, 2, 3,},
{4, 5, 6,},
{7, 8, 9,},
};

int kolumnMAX = grid.GetLength(0) -1 ;
int radMAX = grid.GetLength(1) -1;

int kolumn = 0;
int rad = 0;

ConsoleKeyInfo key;

Console.Clear();

for (int i = 0; i < grid.GetLength(0); i++)
{
for (int j = 0; j < grid.GetLength(1); j++)
{
Console.Write(grid[i,j]);
Console.Write(" ");
}

Console.WriteLine(" ");
}

while (true)
{




key = Console.ReadKey();

switch (key.Key)
{

case ConsoleKey.UpArrow:
kolumn--;
break;

case ConsoleKey.DownArrow:
kolumn++;
break;

case ConsoleKey.LeftArrow:
rad--;
break;

case ConsoleKey.RightArrow:
rad++;
break;
}

if (kolumn>kolumnMAX)
{
kolumn=0;
}

else if(kolumn<0)
{
kolumn = kolumnMAX;
}

if (rad>radMAX)
{
rad=0;
}

else if(rad<0)
{
rad = radMAX;
}

//Switch gillar ej dynamiska tal
/* switch (kolumn)
{

case >2:
kolumn = 0;
break;

case <0:
kolumn = 2;
break;

} */

/* switch (rad)
{
case >2:
rad = 0;
break;

case <0:
rad = 2;
break;
} */


Console.SetCursorPosition(rad , kolumn);


}
HD-Fr0sT
HD-Fr0sTOP9mo ago
HD-Fr0sT
HD-Fr0sTOP9mo ago
i want to make the cursor skip empty spaces and make it so it can recognize diffrent digit numbers 1 10 100
Kouhai
Kouhai9mo ago
Console.SetCursorPosition(rad*2, kolumn); Btw the variable names are a bit confusing, you're moving the column cursor with Up and Down arrows, and the row cursor with left and right, it should be the other way around
HD-Fr0sT
HD-Fr0sTOP9mo ago
ik i screwed around till it worked shouldnt have done the way i did prob
Want results from more Discord servers?
Add your server