c# uygulama örnekleric# uygulama örnekleri

C# programlama dili kullanarak farklı türlerde oyunlar yazabilirsiniz. İşte size farklı türlerde örnek oyun kodları:

C# ile Örnek Oyun Kodları Nelerdir?

Basit bir yılan oyunu:

csharp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnakeGame
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 16;
Console.WindowWidth = 32;
int x = Console.WindowWidth / 2;
int y = Console.WindowHeight / 2;
Console.SetCursorPosition(x, y);
Console.Write(“*”);
int fx = new Random().Next(0, Console.WindowWidth);
int fy = new Random().Next(0, Console.WindowHeight);
Console.SetCursorPosition(fx, fy);
Console.Write(“X”);
int score = 0;
while (true)
{
if (x == fx && y == fy)
{
score++;
fx = new Random().Next(0, Console.WindowWidth);
fy = new Random().Next(0, Console.WindowHeight);
Console.SetCursorPosition(fx, fy);
Console.Write(“X”);
}
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
if (key.Key == ConsoleKey.UpArrow)
y–;
if (key.Key == ConsoleKey.DownArrow)
y++;
if (key.Key == ConsoleKey.LeftArrow)
x–;
if (key.Key == ConsoleKey.RightArrow)
x++;
}
Console.Clear();
Console.SetCursorPosition(x, y);
Console.Write(“*”);
Console.SetCursorPosition(fx, fy);
Console.Write(“X”);
Console.SetCursorPosition(0, Console.WindowHeight – 1);
Console.Write(“Score: ” + score);
if (x < 0 || x >= Console.WindowWidth || y < 0 || y >= Console.WindowHeight)
break;
}
Console.Clear();
Console.SetCursorPosition(Console.WindowWidth / 2 – 5, Console.WindowHeight / 2);
Console.Write(“Game Over”);
Console.ReadKey();
}
}
}

 

Basit bir Tetris oyunu:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TetrisGame
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 20;
Console.WindowWidth = 20;
int[,] grid = new int[Console.WindowWidth, Console.WindowHeight];
int x = Console.WindowWidth / 2;
int y = 0;
while (true)
{
Console.Clear();
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
if (key.Key == ConsoleKey.LeftArrow && x > 0)
x–;
if (key.Key == ConsoleKey.RightArrow && x < Console.WindowWidth – 1)
x++;
if (key.Key == ConsoleKey.DownArrow && y < Console.WindowHeight – 1)
y++;
}
if (grid[x, y] == 1 || y == Console.WindowHeight – 1)
break;
grid[x, y] = 1;
for (int i = 0; i < Console.WindowHeight; i++)
{
for (int j = 0; j < Console.WindowWidth; j++)
{
if (grid[j, i] == 1)
Console.Write(“X”);
else
Console.Write(” “);
}
Console.WriteLine();
}
System.Threading.Thread.Sleep(100);
if (y < Console.WindowHeight – 1 && grid[x, y + 1] == 0)
y++;
}
Console.Clear();
Console.SetCursorPosition(Console.WindowWidth / 2 – 5, Console.WindowHeight / 2);
Console.Write(“Game Over”);
Console.ReadKey();
}
}
}

 

  Bu örnekler sadece basit oyunlar olup, daha karmaşık oyunlar yazmak için daha fazla çalışma gerekebilir. Ancak bu kod örnekleri, C# kullanarak oyun yazmanın temel kavramlarını anlamaya yardımcı olabilir.

Bu uygulamada herhangi bir sorun yaşarsanız aşağıya yorum olarak bırakabilirsiniz. Bunun yanı sıra web sitemizdeki diğer hazır C# programlama örneklerine ulaşmak için bu linke tıklayabilirsiniz. 

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir