SHARE
TWEET

KeywordsTetrisTypeGame v1.0

g-stoyanov Dec 21st, 2012 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Threading;
  3.  
  4. class KeywordsTetrisTypeGame
  5. {
  6.     public struct Object
  7.     {
  8.         public bool isBonusWord;
  9.         public bool isKeyWord;
  10.         public int x;
  11.         public int y;
  12.         public string word;
  13.         public ConsoleColor color;
  14.     }
  15.     static void Draw(int x, int y, ConsoleColor color, string str) // with this method draw in console
  16.     {
  17.         Console.SetCursorPosition(x, y);
  18.         Console.ForegroundColor = color;
  19.         Console.Write(str);
  20.         Console.ForegroundColor = ConsoleColor.White;
  21.     }
  22.     static void Main()
  23.     {
  24.         string[] keyWords =
  25.             { "abstract", "event", "new", "struct", "as", "explicit", "null", "switch", "base", "extern", "object", "this",
  26.               "bool", "false", "operator", "throw", "break", "finally", "out", "true", "byte", "fixed", "override", "try",
  27.               "case", "float", "params", "typeof", "catch", "for", "private", "uint", "char", "foreach", "protected", "ulong",
  28.               "checked", "goto", "public", "unchecked", "class", "if", "readonly", "unsafe", "const", "implicit", "ref",
  29.               "ushort", "continue", "in", "return", "using", "decimal", "int", "sbyte", "virtual", "default", "interface",
  30.               "sealed", "volatile", "delegate", "internal", "short", "void", "do", "is", "sizeof", "while", "double", "lock",
  31.               "stackalloc", "else", "long", "static", "enum", "namespace", "string", };
  32.         string[] normalWords =
  33.             { "analyse", "analysis", "analyst", "analytic", "analytical", "analytically", "analyze", "approach", "approachable",
  34.               "area", "assess", "assessable", "assessment", "assume", "assumed", "assuming", "assumption", "authoritative",
  35.               "authoritatively", "authority", "availability", "available", "beneficial", "beneficiary", "benefit", "blinker",
  36.               "concept", "conception", "conceptual", "conceptualize", "conceptually", "consist", "consistency", "consistent",
  37.               "consistently", "constituency", "constituent", "constitute", "constitution", "constitutional", "constitutionally",
  38.               "constitutive", "context", "contextual", "contextualization", "contextualize", "contextually", "contract",
  39.               "contractor", "create", "creation", "creative", "creatively", "creativity", "creator", "data", "definable",
  40.               "define", "definition", "derivation", "derivative", "derive", "disestablish", "disestablishment", "dissimilar",
  41.               "dissimilarity", "distribute", "distribution", "distributional", "distributive", "distributor", "economic",
  42.               "economical", "economically", "economics", "economist", "economy", "environment", "environmental", "environmentalism",
  43.               "environmentalist", "environmentally", "establish", "established", "establishment", "estimate", "estimation",
  44.               "evidence", "evident", "evidential", "evidently", "export", "exporter", "factor", "finance", "financial",
  45.               "financially", "financier", "finance", "formula", "formulate", "formulation", "period", "function", "functional",
  46.               "functionally", "ID", "identifiable", "identification", "identify", "identity", "illegal", "illegality", "illegally",
  47.               "income", "inconsistency", "inconsistent", "inconsistently", "indicate", "indication", "indicative", "indicator",
  48.               "indiscreet", "indiscreetly", "individual", "individualism", "individualist", "individualistic", "individuality",
  49.               "individually", "insignificance", "insignificant", "insignificantly", "interpret", "interpretable", "interpretation",
  50.               "interpretative", "interpretive", "invariable", "invariably", "involve", "involved", "involvement", "isolating",
  51.               "issue", "issuer", "labor", "labour", "legal", "legality", "legally", "legislate", "legislation", "legislative",
  52.               "legislator", "legislature", "major", "majority", "method", "methodical", "methodically", "methodological",
  53.               "methodologically", "methodology", "misinterpret", "misinterpretation", "occur", "occurrence", "overestimate",
  54.               "overestimation", "percentage", "period", "periodic", "periodical", "periodically", "policy", "principle",
  55.               "principled", "procedural", "procedure", "proceed", "proceeding", "proceeds", "process", "processing", "reassess",
  56.               "reassessment", "recreate", "recreation", "redefine", "redefinition", "redistribute", "redistribution",
  57.               "redistributive", "reformulate", "reformulation", "reinterpret", "reinterpretation", "reoccur", "require",
  58.               "requirement", "research", "researcher", "research", "respond", "respondent", "response", "responsive",
  59.               "responsively", "responsiveness", "restructure", "restructuring", "role", "section", "sector", "significance",
  60.               "significant", "significantly", "signify", "similar", "similarity", "similarly", "source", "specific", "specifically",
  61.               "specification", "specificity", "specifics", "structural", "structurally", "structure", "theoretical",
  62.               "theoretically", "theoretician", "theorist", "theory", "turn", "signal", "unapproachable", "unavailability",
  63.               "unavailable", "unconstitutional", "unconstitutionally", "undefined", "underestimate", "underestimate", "uneconomic",
  64.               "uneconomical", "unidentifiable", "uninvolved", "unprincipled", "unresponsive", "unstructured", "variability",
  65.               "variable", "variably", "variance", "variant", "variation", "varied", "vary",};
  66.         string[] bonusWords = {"Telerik", "svetlin", "nikolay", "pavel", "georgi", "doncho", "nakov", "kostov", "kolev", "georgiev", "minkov"};
  67.         ConsoleColor[] color = { ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.Green, ConsoleColor.Magenta, ConsoleColor.Blue, ConsoleColor.Cyan, ConsoleColor.Gray, ConsoleColor.White };
  68.         Object word = new Object();
  69.         Random randomNumber = new Random();
  70.         bool createNewWord = true;
  71.         byte checkCycle = 0;
  72.         int score = 0;
  73.         int lives = 5;
  74.         while (true)
  75.         {
  76.             if (createNewWord)
  77.             {
  78.                 Console.SetCursorPosition(0, 0);
  79.                 Console.WriteLine("\u2502" + new string(' ', 62) + "\u250c" + new string('\u2500', 12) + "\u2510");
  80.                 for (int i = 0; i < 34; i++)
  81.                 {
  82.                     Console.WriteLine("\u2502" + new string(' ', 62) + "\u2502" + new string(' ', 12) + "\u2502");
  83.                 }
  84.                 Console.WriteLine("\u251c" + new string('\u2500', 20) + "\u253c" + new string('\u2500', 20) + "\u253c" + new string('\u2500', 20) + "\u2524" + new string(' ', 12) + "\u2502");
  85.                 Console.WriteLine("\u2502" + "      Key Word      " + "\u2502" + "     Normal Word    " + "\u2502" + "     Bonus Word     " + "\u2502" + new string(' ', 12) + "\u2502");
  86.                 Console.WriteLine("\u2514" + new string('\u2500', 20) + "\u2534" + new string('\u2500', 20) + "\u2534" + new string('\u2500', 20) + "\u2534" + new string('\u2500', 12) + "\u2518");
  87.                 Console.SetCursorPosition(64, 15);
  88.                 Console.WriteLine("Lives: " + lives);
  89.                 Console.SetCursorPosition(64, 17);
  90.                 Console.WriteLine("Score: " + score);
  91.             }
  92.             if (createNewWord)
  93.             {
  94.                 word = new Object();
  95.                 int chance = randomNumber.Next(0, 101);
  96.                 if (chance < 5 && chance >= 0)
  97.                 {
  98.                     word.word = bonusWords[randomNumber.Next(0, bonusWords.Length)];
  99.                     word.isBonusWord = true;
  100.                 }
  101.                 else if (chance < 51 && chance >= 5)
  102.                 {
  103.                     word.word = keyWords[randomNumber.Next(0, keyWords.Length)];
  104.                     word.isKeyWord = true;
  105.                 }
  106.                 else
  107.                 {
  108.                     word.word = normalWords[randomNumber.Next(0, normalWords.Length)];
  109.                 }
  110.                 word.y = 0;
  111.                 word.x = 30 - (word.word.Length / 2);
  112.                 createNewWord = false;
  113.             }
  114.             Draw(word.x, word.y, ConsoleColor.Black, word.word);
  115.             while (Console.KeyAvailable)
  116.             {
  117.                 ConsoleKeyInfo pressedKey = Console.ReadKey(true);
  118.                 if (pressedKey.Key == ConsoleKey.LeftArrow)        
  119.                 {
  120.                     if (word.x > 1)
  121.                     {
  122.                         word.x--;
  123.                     }
  124.                 }
  125.                 else if (pressedKey.Key == ConsoleKey.RightArrow)
  126.                 {
  127.                     if (word.x < 62 - word.word.Length)
  128.                     {
  129.                         word.x++;
  130.                     }
  131.                 }
  132.                 else if (pressedKey.Key == ConsoleKey.DownArrow)
  133.                 {
  134.                     word.y = 35;
  135.                     checkCycle = 0;
  136.                 }
  137.             }
  138.             if (checkCycle == 4)
  139.             {
  140.                 while (Console.KeyAvailable)
  141.                 {
  142.                     Console.ReadKey(false);
  143.                 }
  144.                 word.y++;
  145.                 checkCycle = 0;
  146.             }
  147.             Draw(word.x, word.y, color[randomNumber.Next(0, color.Length)], word.word);
  148.             checkCycle++;
  149.             Thread.Sleep(150 - score);
  150.             if (word.y == 35)
  151.             {
  152.                 if (word.isKeyWord)
  153.                 {
  154.                     if (word.x > 1 && word.x + word.word.Length < 21)
  155.                     {
  156.                         score++;
  157.                     }
  158.                     else
  159.                     {
  160.                         lives--; ;
  161.                     }
  162.                 }
  163.                 else if (word.isBonusWord)
  164.                 {
  165.                     if (word.x > 43 && word.x + word.word.Length < 63)
  166.                     {
  167.                         score += 10;
  168.                         lives++;
  169.                     }
  170.                     else
  171.                     {
  172.                         lives -= 2;
  173.                     }
  174.                 }
  175.                 else
  176.                 {
  177.                     if (word.x > 22 && word.x + word.word.Length < 42)
  178.                     {
  179.                         score++;
  180.                     }
  181.                     else
  182.                     {
  183.                         lives--;
  184.                     }
  185.                 }
  186.                 createNewWord = true;
  187.                 Draw(word.x, word.y, ConsoleColor.Black, word.word);
  188.             }
  189.             if (lives <= 0)
  190.             {
  191.                 Console.Clear();
  192.                 Console.WriteLine("GAME OVER");
  193.                 Console.WriteLine();
  194.                 Console.WriteLine("Your score is: " + score);
  195.                 Console.WriteLine();
  196.                 Console.Write("Please press N to begin new game or E to exit:");
  197.                 while (true)
  198.                 {
  199.                     ConsoleKeyInfo pressedKey = Console.ReadKey(true);
  200.                     if (pressedKey.Key == ConsoleKey.N)
  201.                     {
  202.                         Main();
  203.                     }
  204.                     else if (pressedKey.Key == ConsoleKey.E)
  205.                     {
  206.                         break;
  207.                     }
  208.                 }
  209.                 break;
  210.             }
  211.         }
  212.     }
  213. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top