Advertisement
csaki

kalózjáték

Nov 21st, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace kalozhajo
  7. {
  8.     class Program
  9.     {
  10.         static int függ1 = 0;
  11.         static int viz1 = 0;
  12.         static char lépés;
  13.         static int függ2;
  14.         static int viz2;
  15.         static string géplép = "wasd";
  16.         static int db = 0;
  17.         static Random rand = new Random();
  18.  
  19.         static void Main(string[] args)
  20.         {
  21.             do
  22.             {
  23.                 for (int i = 0; i < 2; i++)
  24.                 {
  25.                     énlépek();
  26.                    
  27.                 }
  28.  
  29.                 gép();
  30.             }
  31.             while (!(függ1 == függ2 && viz1 == viz2));
  32.  
  33.             Console.SetCursorPosition(28, 12);
  34.             Console.WriteLine("#### Nyertél! ####");
  35.             Console.ReadLine();
  36.         }
  37.  
  38.         static void kiírás()
  39.         {
  40.             Console.Clear();
  41.             Console.SetCursorPosition(viz1, függ1);
  42.             Console.Write("o");
  43.             Console.SetCursorPosition(viz2, függ2);
  44.             Console.Write("x");
  45.         }
  46.  
  47.         static void énlépek()
  48.         {
  49.             kiírás();
  50.             Console.SetCursorPosition(30, 12);
  51.             lépés = Convert.ToChar(Console.ReadKey().KeyChar);
  52.             if (lépés == 's')
  53.             {
  54.                 függ1++;
  55.                 if (függ1 > 25)
  56.                 {
  57.                     függ1 = 25;
  58.                 }
  59.             }
  60.             if (lépés == 'a')
  61.             {
  62.                 viz1--;
  63.                 if (viz1 < 0)
  64.                 {
  65.                     viz1 = 0;
  66.                 }
  67.             }
  68.  
  69.             if (lépés == 'w')
  70.             {
  71.                 függ1--;
  72.                 if (függ1 < 0)
  73.                 {
  74.                     függ1 = 0;
  75.                 }
  76.             }
  77.  
  78.             if (lépés == 'd')
  79.             {
  80.                 viz1++;
  81.                 if (viz1 > 80)
  82.                 {
  83.                     viz1 = 80;
  84.                 }
  85.             }
  86.         }
  87.  
  88.         static void gép()
  89.         {
  90.             Console.Clear();
  91.             lépés = géplép[rand.Next(4)];
  92.             if (db == 0)
  93.             {
  94.                 viz2 = rand.Next(1, 80);
  95.                 függ2 = rand.Next(1, 25);
  96.                 Console.SetCursorPosition(viz2, függ2);
  97.                 db++;
  98.             }
  99.             if (lépés == 's')
  100.             {
  101.                 függ2++;
  102.                 if (függ2 > 25)
  103.                 {
  104.                     függ2 = 25;
  105.                 }
  106.             }
  107.             if (lépés == 'a')
  108.             {
  109.                 viz2--;
  110.                 if (viz2 < 0)
  111.                 {
  112.                     viz2 = 0;
  113.                 }
  114.             }
  115.  
  116.             if (lépés == 'w')
  117.             {
  118.                 függ2--;
  119.                 if (függ2 < 0)
  120.                 {
  121.                     függ2 = 0;
  122.                 }
  123.             }
  124.  
  125.             if (lépés == 'd')
  126.             {
  127.                 viz2++;
  128.                 if (viz2 > 80)
  129.                 {
  130.                     viz2 = 80;
  131.                 }
  132.             }
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement