C#'Da Eğlenceli Bir Proje (Konsolda Koşan Adam)
-
Can sıkkınlığından ölürken aklıma eğlenceli bir proje geldi.
Onunla uğraştım. Siznlede paylanmak istiyorum. Belki faydası olur.
Proje C# Consoleda yön tuşları ve (w,a,s,d) tuşları ile hareket eden bir kolboydur.Ateş etmesi içinde uğraştım ama tam o hissi veremediğim için sonra vaz geçtim.
Kodları mantıkla değil fantez yaparak yazdım özellikle adamı çizdiren if bloğu buna çok güzel bir örnek :D--------------------------------------
http://yadi.sk/d/vyzjih7HJ8JvN
--------------------------------------using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { class adam { int x=0,y=0; public int X { get { return x; } set { if (value < 0) x = 0; else if (73<value) x = 73; else x = value; } } public int Y { get { return y; } set { if (value < 0) y = 0; else y = value; } } public void ciz(int a,int b) { for (int c=a; c < b; c++) { if (c == 0 | c == 5 | c == 14 | c == 19 | c == 21 | c == 28 | c == 29 | c == 32 | c == 33 | c == 35 | c == 40 | c == 43 | c == 46 | c == 49 | c == 50 | c == 53 | c == 54 | c == 56 | c == 58 | c == 59 | c == 61 | c == 64 | c == 65 | c == 66 | c == 67){ Console.Write(" "); } if (c == 1 | c == 2 | c == 3 | c == 4 | c == 7 | c == 8 | c == 9 | c == 10 | c == 11 | c == 12){ Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red; Console.Write("a"); Console.ResetColor(); } if (c == 15 | c == 16 | c == 17 | c == 18 | c == 22 | c == 23 | c == 24 | c == 25){ Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("a"); Console.ResetColor(); } if (c == 30 | c == 31 | c == 36 | c == 37 | c == 38 | c == 39 | c == 42 | c == 44 | c == 45 | c == 47 | c == 51 | c == 52 | c == 57 | c == 60 | c == 63 | c == 68){ Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.Blue; Console.Write("a"); Console.ResetColor(); } if (c == 6 | c == 13 | c == 20 | c == 27 | c == 34 | c == 41 | c == 48 | c == 55 | c == 62){ Console.WriteLine(); } } } public void hareket() { for (int a = 0; a < y; a++) Console.WriteLine(); int h=0; while(h<=70 ){ for (int a = 0; a < x; a++) Console.Write(" "); ciz(h, h +=7 ); } } } static void Main(string[] args) { adam kolboy = new adam(); kolboy.ciz(0,70); while (true) { ConsoleKeyInfo tus =Console.ReadKey(true); if (ConsoleKey.DownArrow == tus.Key || ConsoleKey.S == tus.Key){ Console.Clear(); kolboy.Y++; kolboy.hareket(); } else if (ConsoleKey.UpArrow == tus.Key || ConsoleKey.W == tus.Key){ Console.Clear(); kolboy.Y--; kolboy.hareket(); } else if (ConsoleKey.LeftArrow == tus.Key || ConsoleKey.A == tus.Key){ Console.Clear(); kolboy.X--; kolboy.hareket(); } else if (ConsoleKey.RightArrow == tus.Key || ConsoleKey.D == tus.Key){ Console.Clear(); kolboy.X++; kolboy.hareket(); } } } } }
Toplam Hit: 954 Toplam Mesaj: 1
