Venciity

[Jumpstart C#] Exam - 5 задача with cursor position

Feb 8th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace exercise5Easy
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Write("x = ");
  14.             int x = Int32.Parse(Console.ReadLine());
  15.  
  16.             Console.Write("y = ");
  17.             int y = Int32.Parse(Console.ReadLine());
  18.  
  19.             int originX = 10;
  20.             int originY = 5;
  21.  
  22.             int transformedX = originX + x;
  23.             int transformedY = originY - y + Console.CursorTop;
  24.  
  25.             for (int row = 0; row < 11; row++)
  26.             {
  27.                 if (row == 5)
  28.                 {
  29.                     Console.WriteLine("{0}+{0}",new string ('-', 10));
  30.                 }
  31.                 else
  32.                 {
  33.                     Console.WriteLine("{0}|", new string(' ', 10));
  34.                 }
  35.             }
  36.  
  37.             int cursorLeft = Console.CursorLeft;
  38.             int cursorTop = Console.CursorTop;
  39.  
  40.             Console.SetCursorPosition(transformedX, transformedY);
  41.             Console.WriteLine("*");
  42.  
  43.             Console.SetCursorPosition(cursorLeft, cursorTop);
  44.  
  45.             if (x > 0)
  46.             {
  47.                 if (y > 0)
  48.                 {
  49.                     Console.WriteLine("1");
  50.                 }
  51.                 else if (y < 0)
  52.                 {
  53.                     Console.WriteLine("4");
  54.                 }
  55.                 else
  56.                 {
  57.                     Console.WriteLine("x");
  58.                 }
  59.             }
  60.             else if (x < 0)
  61.             {
  62.                 if (y > 0)
  63.                 {
  64.                     Console.WriteLine("2");
  65.                 }
  66.                 else if (y < 0)
  67.                 {
  68.                     Console.WriteLine("3");
  69.                 }
  70.                 else
  71.                 {
  72.                     Console.WriteLine("x");
  73.                 }
  74.             }
  75.             else
  76.             {
  77.                 if (y == 0)
  78.                 {
  79.                     Console.WriteLine("+");
  80.                 }
  81.                 else
  82.                 {
  83.                     Console.WriteLine("y");
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment