kyamaliev

C#Basics HW6 - Problem4

Mar 31st, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. class PrintADeckOf52Cards
  3. {
  4.     static void Main()
  5.     {
  6.         int[] suits = new int[] { 5, 4, 3, 6 };
  7.         for (int i = 2; i < 15; i++)
  8.         {
  9.             for (int suit = 3; suit < 7; suit++)
  10.             {
  11.                 // The following if statements are used to temporarily swap the suit with the one that is in the correct order so the output is as in the example.
  12.                 if (suit == 3) //ето тук почва 'балъшката част' :)
  13.                 {
  14.                     int temp = suit;
  15.                     suit = suits[0];
  16.                     WriteToConsole(i, suit);
  17.                     suit = temp;
  18.                 }
  19.                 else if (suit == 4)
  20.                 {
  21.                     int temp = suit;
  22.                     suit = suits[1];
  23.                     WriteToConsole(i, suit);
  24.                     suit = temp;
  25.                 }
  26.                 else if (suit == 5)
  27.                 {
  28.                     int temp = suit;
  29.                     suit = suits[2];
  30.                     WriteToConsole(i, suit);
  31.                    suit = temp;
  32.                 }
  33.                 else
  34.                 {
  35.                     int temp = suit;
  36.                     suit = suits[3];
  37.                     WriteToConsole(i, suit);
  38.                     }
  39.             }
  40.             Console.WriteLine();
  41.         }
  42.     }
  43.     static void WriteToConsole(int i, int suit)
  44.     {
  45.         switch (i)
  46.         {
  47.             default: Console.Write("".PadLeft(2, ' ') + i + "" + (char)(suit) + " ".PadRight(2, ' ')); break; // поиграл съм си да ми се подредят красиво :)
  48.             case 10: Console.Write("".PadLeft(1, ' ') + "10" + (char)(suit) + "  "); break;
  49.             case 11: Console.Write("".PadLeft(2, ' ') + "J" + (char)(suit) + "  "); break;
  50.             case 12: Console.Write("".PadLeft(2, ' ') + "Q" + (char)(suit) + "  "); break;
  51.             case 13: Console.Write("".PadLeft(2, ' ') + "K" + (char)(suit) + "  "); break;
  52.             case 14: Console.Write("".PadLeft(2, ' ') + "A" + (char)(suit) + "  "); break;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment