Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace sorting
- {
- class MainClass
- {
- static int[,] inventory = new int[3, 3];
- static int cursor_x = 0, cursor_y = 0;
- public static void Main ( string [] args )
- {
- Console.CursorVisible = false;
- while ( true )
- {
- DrawInventory ();
- Input ();
- }
- }
- public static void Input ()
- {
- ConsoleKeyInfo keyInfo = Console.ReadKey ( true );
- if ( keyInfo.Key == ConsoleKey.UpArrow )
- {
- cursor_y = Clamp ( cursor_y - 1, 0, inventory.GetLength ( 1 ) - 1 );
- }
- else if ( keyInfo.Key == ConsoleKey.DownArrow )
- {
- cursor_y = Clamp ( cursor_y + 1, 0, inventory.GetLength ( 1 ) - 1 );
- }
- else if ( keyInfo.Key == ConsoleKey.LeftArrow )
- {
- cursor_x = Clamp ( cursor_x - 1, 0, inventory.GetLength ( 0 ) - 1 );
- }
- else if ( keyInfo.Key == ConsoleKey.RightArrow )
- {
- cursor_x = Clamp ( cursor_x + 1, 0, inventory.GetLength ( 0 ) - 1 );
- }
- }
- public static void DrawInventory ( int padding = 2 )
- {
- Console.BackgroundColor = ConsoleColor.Black;
- int lastSize = CanculateSize ( padding-1 );
- for ( int x = 0 ; x < inventory.GetLength ( 0 ) ; x++ )
- {
- for ( int y = 0 ; y < inventory.GetLength ( 1 ) ; y++ )
- {
- if ( x == cursor_x && y == cursor_y )
- {
- Console.BackgroundColor = ConsoleColor.Red;
- }
- DrawBox ( x * lastSize, y * lastSize, padding, inventory [x, y].ToString () );
- Console.BackgroundColor = ConsoleColor.Black;
- }
- }
- }
- public static int Clamp ( int value, int min, int max )
- {
- return value < min ? min : ( value > max ) ? max : value;
- }
- public static int CanculateSize ( int padding )
- {
- return 3 + padding + 2;
- }
- public static void DrawBox ( int _x, int _y, int padding, string number )
- {
- int size = CanculateSize ( padding );
- for ( int x = 0 ; x < size ; x++ )
- {
- for ( int y = 0 ; y < size ; y++ )
- {
- if ( x == 0 || y == 0 || x == size - 1 || y == size - 1 )
- {
- Console.SetCursorPosition ( x + _x, y + _y );
- Console.Write ( '#' );
- }
- }
- }
- Console.SetCursorPosition ( ( _x + size / 2 ) - number.Length / 2, _y + size / 2 );
- Console.Write ( number );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement