@מתכנת-חובב שכחתי לציין שעשיתי את זה ב Open AI Codex ולא בצ'אט ושם המגבלה היא 16000 תווים כמדומני.
@מתכנת-חובב כתב בשיתוף | ChatGPT - הצ'אטבוט החדש של OpenAI ; לכתיבת תסריטים:
בדקת שגם אם תתקן הכל עובד כמו שצריך?
יתכן שאתה צודק, אבל כפי שאמרתי לא היה לי כוח לעבור על הכל, זה גם ככה לא היה משהו חשוב כל כך אלא יותר לשם השעשוע.
אגב, יצרתי עם זה עכשיו קוד #C למשחק סנייק באורך 180 שורות ועבד מצויין, רק הבעיה שכיווני החיצים הפוכים וזה ממש מבלבל...
אם מעניין אותך, הנה הקוד, אני הפעלתי אותו ב Visual studio ע"י יצירת פרוייקט
Console App (.NET Framework) :
using System;
namespace SnakeGame
{
class Program
{
static void Main(string[] args)
{
// Set up the game board
int boardWidth = 20;
int boardHeight = 20;
char[,] board = new char[boardWidth, boardHeight];
for (int i = 0; i < boardWidth; i++)
{
for (int j = 0; j < boardHeight; j++)
{
board[i, j] = ' ';
}
}
// Set up the snake
int snakeLength = 5;
int[] snakeX = new int[snakeLength];
int[] snakeY = new int[snakeLength];
for (int i = 0; i < snakeLength; i++)
{
snakeX[i] = boardWidth / 2;
snakeY[i] = boardHeight / 2;
}
// Set up the food
int foodX = 0;
int foodY = 0;
Random random = new Random();
while (true)
{
foodX = random.Next(0, boardWidth);
foodY = random.Next(0, boardHeight);
if (board[foodX, foodY] == ' ')
{
break;
}
}
// Set up the game variables
int score = 0;
int direction = 0; // 0 = up, 1 = right, 2 = down, 3 = left
bool gameOver = false;
// Main game loop
while (!gameOver)
{
// Draw the board
Console.Clear();
for (int i = 0; i < boardWidth; i++)
{
for (int j = 0; j < boardHeight; j++)
{
if (i == 0 || i == boardWidth - 1 || j == 0 || j == boardHeight - 1)
{
Console.Write('#');
}
else
{
Console.Write(board[i, j]);
}
}
Console.WriteLine();
}
// Draw the score
Console.WriteLine("Score: " + score);
// Get the user input
ConsoleKeyInfo keyInfo = Console.ReadKey();
switch (keyInfo.Key)
{
case ConsoleKey.UpArrow:
if (direction != 2)
{
direction = 0;
}
break;
case ConsoleKey.RightArrow:
if (direction != 3)
{
direction = 1;
}
break;
case ConsoleKey.DownArrow:
if (direction != 0)
{
direction = 2;
}
break;
case ConsoleKey.LeftArrow:
if (direction != 1)
{
direction = 3;
}
break;
}
// Move the snake
for (int i = snakeLength - 1; i > 0; i--)
{
snakeX[i] = snakeX[i - 1];
snakeY[i] = snakeY[i - 1];
}
switch (direction)
{
case 0:
snakeY[0]--;
break;
case 1:
snakeX[0]++;
break;
case 2:
snakeY[0]++;
break;
case 3:
snakeX[0]--;
break;
}
// Check for game over
if (snakeX[0] == 0 || snakeX[0] == boardWidth - 1 || snakeY[0] == 0 || snakeY[0] == boardHeight - 1)
{
gameOver = true;
}
for (int i = 1; i < snakeLength; i++)
{
if (snakeX[0] == snakeX[i] && snakeY[0] == snakeY[i])
{
gameOver = true;
}
}
// Check for food
if (snakeX[0] == foodX && snakeY[0] == foodY)
{
// Increase the score
score++;
// Increase the snake length
snakeLength++;
Array.Resize(ref snakeX, snakeLength);
Array.Resize(ref snakeY, snakeLength);
snakeX[snakeLength - 1] = snakeX[snakeLength - 2];
snakeY[snakeLength - 1] = snakeY[snakeLength - 2];
// Generate new food
while (true)
{
foodX = random.Next(0, boardWidth);
foodY = random.Next(0, boardHeight);
if (board[foodX, foodY] == ' ')
{
break;
}
}
}
// Update the board
board[foodX, foodY] = 'F';
for (int i = 0; i < snakeLength; i++)
{
board[snakeX[i], snakeY[i]] = 'S';
}
}
// Game over
Console.Clear();
Console.WriteLine("Game Over!");
Console.WriteLine("Score: " + score);
Console.ReadKey();
}
}
}
קוד
תיהנה!!!