BASİT OYUN MEKANİĞİ
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
Console.WindowWidth = Console.LargestWindowWidth;
Console.WindowHeight = Console.LargestWindowHeight;
Random random = new Random();
int targetCount = 10;
int score = 0;
int width = Console.WindowWidth - 1;
int height = Console.WindowHeight - 1;
int ballX = width / 2;
int ballY = height / 2;
List<Tuple<int, int>> targets = new List<Tuple<int, int>>();
for (int i = 0; i < targetCount; i++)
{
targets.Add(new Tuple<int, int>(random.Next(1, width - 1), random.Next(1, height - 1)));
}
while (true)
{
Console.Clear();
Console.SetCursorPosition(ballX, ballY);
Console.Write("o");
foreach (Tuple<int, int> target in targets)
{
Console.SetCursorPosition(target.Item1, target.Item2);
Console.Write("X");
}
Console.SetCursorPosition(0, height);
Console.Write("Score: " + score + " / " + targetCount);
if (score >= targetCount)
{
Console.SetCursorPosition(0, 0);
Console.WriteLine("You win!");
break;
}
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
switch (keyInfo.Key)
{
case ConsoleKey.UpArrow:
ballY = Math.Max(1, ballY - 1);
break;
case ConsoleKey.DownArrow:
ballY = Math.Min(height - 1, ballY + 1);
break;
case ConsoleKey.LeftArrow:
ballX = Math.Max(1, ballX - 1);
break;
case ConsoleKey.RightArrow:
ballX = Math.Min(width - 1, ballX + 1);
break;
default:
break;
}
for (int i = 0; i < targets.Count; i++)
{
Tuple<int, int> target = targets[i];
if (target.Item1 == ballX && target.Item2 == ballY)
{
targets.RemoveAt(i);
score++;
}
}
}
Console.ReadKey(true);
}
}