напиши копию flappy bird на C#
- User
напиши копию flappy bird на C#
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
напиши копию flappy bird на C#
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Вот простая версия Flappy Bird на C# с использованием консоли:
using System;
using System.Collections.Generic;
using System.Threading;
class FlappyBirdConsole
{
const int WIDTH = 60;
const int HEIGHT = 20;
const int PIPE_GAP = 6;
const int PIPE_WIDTH = 3;
static int birdY = HEIGHT / 2;
static double birdVelocity = 0;
static List<int[]> pipes = new List<int[]>();
static int score = 0;
static bool gameOver = false;
static void Main()
{
Console.CursorVisible = false;
Console.SetWindowSize(WIDTH + 1, HEIGHT + 5);
// Создаем первые трубы
pipes.Add(new int[] { WIDTH, GeneratePipeHeight() });
Thread inputThread = new Thread(HandleInput);
inputThread.Start();
while (!gameOver)
{
Update();
Draw();
Thread.Sleep(100);
}
Console.SetCursorPosition(WIDTH / 2 - 5, HEIGHT / 2);
Console.WriteLine("GAME OVER!");
Console.SetCursorPosition(WIDTH / 2 - 5, HEIGHT / 2 + 1);
Console.WriteLine($"Score: {score}");
inputThread.Join();
Console.ReadKey();
}
static void HandleInput()
{
while (!gameOver)
{
if (Console.KeyAvailable)
{
var key = Console.ReadKey(true);
if (key.Key == ConsoleKey.Spacebar)
{
birdVelocity = -1.5;
}
}
}
}
static void Update()
{
// Обновляем позицию птицы
birdVelocity += 0.3;
birdY += (int)birdVelocity;
// Проверяем столкновение с границами
if (birdY <= 0 || birdY >= HEIGHT - 1)
{
gameOver = true;
return;
}
// Обновляем трубы
for (int i = pipes.Count - 1; i >= 0; i--)
{
pipes[i][0]--;
// Удаляем трубы за экраном
if (pipes[i][0] < -PIPE_WIDTH)
{
pipes.RemoveAt(i);
score++;
}
}
// Добавляем новые трубы
if (pipes.Count == 0 || pipes[pipes.Count - 1][0] < WIDTH - 25)
{
pipes.Add(new int[] { WIDTH, GeneratePipeHeight() });
}
// Проверяем столкновения с трубами
foreach (var pipe in pipes)
{
if (pipe[0] <= 10 && pipe[0] + PIPE_WIDTH >= 10)
{
if (birdY <= pipe[1] || birdY >= pipe[1] + PIPE_GAP)
{
gameOver = true;
return;
}
}
}
}
static void Draw()
{
Console.Clear();
// Рисуем границы
for (int i = 0; i < WIDTH; i++)
{
Console.SetCursorPosition(i, 0);
Console.Write("═");
Console.SetCursorPosition(i, HEIGHT);
Console.Write("═");
}
for (int i = 0; i <= HEIGHT; i++)
{
Console.SetCursorPosition(0, i);
Console.Write("║");
Console.SetCursorPosition(WIDTH, i);
Console.Write("║");
}
// Рисуем трубы
Console.ForegroundColor = ConsoleColor.Green;
foreach (var pipe in pipes)
{
for (int x = 0; x < PIPE_WIDTH; x++)
{
if (pipe[0] + x >= 0 && pipe[0] + x < WIDTH)
{
// Верхняя труба
for (int y = 1; y < pipe[1]; y++)
{
Console.SetCursorPosition(pipe[0] + x, y);
Console.Write("█");
}
// Нижняя труба
for (int y = pipe[1] + PIPE_GAP; y < HEIGHT; y++)
{
Console.SetCursorPosition(pipe[0] + x, y);
Console.Write("█");
}
}
}
}
Console.ResetColor();
// Рисуем птицу
Console.ForegroundColor = ConsoleColor.Yellow;
Console.SetCursorPosition(10, birdY);
Console.Write("►");
Console.ResetColor();
// Показываем счет
Console.SetCursorPosition(2, HEIGHT + 2);
Console.Write($"Score: {score}");
Console.SetCursorPosition(2, HEIGHT + 3);
Console.Write("Press SPACE to jump");
}
static int GeneratePipeHeight()
{
Random rand = new Random();
return rand.Next(3, HEIGHT - PIPE_GAP - 2);
}
}
Эта версия работает в консоли и включает:
Для запуска просто скомпилируйте и запустите программу. Управление - пробел для прыжка.