SHARE
TWEET

KeywordsTetrisTypeGame v.1.1

g-stoyanov Dec 21st, 2012 98 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.         Console.WindowWidth = 80;
  75.         Console.BufferWidth = 200;
  76.         Console.WindowHeight = 40;
  77.         Console.BufferHeight = 50;
  78.         while (true)
  79.         {
  80.             if (createNewWord)
  81.             {
  82.                 Console.SetCursorPosition(0, 0);
  83.                 Console.WriteLine("\u2502" + new string(' ', 62) + "\u250c" + new string('\u2500', 12) + "\u2510");
  84.                 for (int i = 0; i < 34; i++)
  85.                 {
  86.                     Console.WriteLine("\u2502" + new string(' ', 62) + "\u2502" + new string(' ', 12) + "\u2502");
  87.                 }
  88.                 Console.WriteLine("\u251c" + new string('\u2500', 20) + "\u253c" + new string('\u2500', 20) + "\u253c" + new string('\u2500', 20) + "\u2524" + new string(' ', 12) + "\u2502");
  89.                 Console.WriteLine("\u2502" + "      Key Word      " + "\u2502" + "     Normal Word    " + "\u2502" + "     Bonus Word     " + "\u2502" + new string(' ', 12) + "\u2502");
  90.                 Console.WriteLine("\u2514" + new string('\u2500', 20) + "\u2534" + new string('\u2500', 20) + "\u2534" + new string('\u2500', 20) + "\u2534" + new string('\u2500', 12) + "\u2518");
  91.                 Console.SetCursorPosition(64, 15);
  92.                 Console.WriteLine("Lives: " + lives);
  93.                 Console.SetCursorPosition(64, 17);
  94.                 Console.WriteLine("Score: " + score);
  95.             }
  96.             if (createNewWord)
  97.             {
  98.                 word = new Object();
  99.                 int chance = randomNumber.Next(0, 101);
  100.                 if (chance < 5 && chance >= 0)
  101.                 {
  102.                     word.word = bonusWords[randomNumber.Next(0, bonusWords.Length)];
  103.                     word.isBonusWord = true;
  104.                 }
  105.                 else if (chance < 51 && chance >= 5)
  106.                 {
  107.                     word.word = keyWords[randomNumber.Next(0, keyWords.Length)];
  108.                     word.isKeyWord = true;
  109.                 }
  110.                 else
  111.                 {
  112.                     word.word = normalWords[randomNumber.Next(0, normalWords.Length)];
  113.                 }
  114.                 word.y = 0;
  115.                 word.x = 30 - (word.word.Length / 2);
  116.                 createNewWord = false;
  117.             }
  118.             Draw(word.x, word.y, ConsoleColor.Black, word.word);
  119.             while (Console.KeyAvailable)
  120.             {
  121.                 ConsoleKeyInfo pressedKey = Console.ReadKey(true);
  122.                 if (pressedKey.Key == ConsoleKey.LeftArrow)        
  123.                 {
  124.                     if (word.x > 1)
  125.                     {
  126.                         word.x--;
  127.                     }
  128.                 }
  129.                 else if (pressedKey.Key == ConsoleKey.RightArrow)
  130.                 {
  131.                     if (word.x < 62 - word.word.Length)
  132.                     {
  133.                         word.x++;
  134.                     }
  135.                 }
  136.                 else if (pressedKey.Key == ConsoleKey.DownArrow)
  137.                 {
  138.                     word.y = 35;
  139.                     checkCycle = 0;
  140.                 }
  141.             }
  142.             if (checkCycle == 4)
  143.             {
  144.                 while (Console.KeyAvailable)
  145.                 {
  146.                     Console.ReadKey(false);
  147.                 }
  148.                 word.y++;
  149.                 checkCycle = 0;
  150.             }
  151.             Draw(word.x, word.y, color[randomNumber.Next(0, color.Length)], word.word);
  152.             checkCycle++;
  153.             Thread.Sleep(150 - score);
  154.             if (word.y == 35)
  155.             {
  156.                 if (word.isKeyWord)
  157.                 {
  158.                     if (word.x > 1 && word.x + word.word.Length < 21)
  159.                     {
  160.                         score++;
  161.                     }
  162.                     else
  163.                     {
  164.                         lives--; ;
  165.                     }
  166.                 }
  167.                 else if (word.isBonusWord)
  168.                 {
  169.                     if (word.x > 43 && word.x + word.word.Length < 63)
  170.                     {
  171.                         score += 10;
  172.                         lives++;
  173.                     }
  174.                     else
  175.                     {
  176.                         lives -= 2;
  177.                     }
  178.                 }
  179.                 else
  180.                 {
  181.                     if (word.x > 22 && word.x + word.word.Length < 42)
  182.                     {
  183.                         score++;
  184.                     }
  185.                     else
  186.                     {
  187.                         lives--;
  188.                     }
  189.                 }
  190.                 createNewWord = true;
  191.                 Draw(word.x, word.y, ConsoleColor.Black, word.word);
  192.             }
  193.             if (lives <= 0)
  194.             {
  195.                 Console.Clear();
  196.                 Console.WriteLine("GAME OVER");
  197.                 Console.WriteLine();
  198.                 Console.WriteLine("Your score is: " + score);
  199.                 Console.WriteLine();
  200.                 Console.Write("Please press N to begin new game or E to exit:");
  201.                 while (true)
  202.                 {
  203.                     ConsoleKeyInfo pressedKey = Console.ReadKey(true);
  204.                     if (pressedKey.Key == ConsoleKey.N)
  205.                     {
  206.                         Main();
  207.                     }
  208.                     else if (pressedKey.Key == ConsoleKey.E)
  209.                     {
  210.                         break;
  211.                     }
  212.                 }
  213.                 break;
  214.             }
  215.         }
  216.     }
  217. }
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