ChatGPT'nin yazdığı kod çalışıyor mu?

Mehmet Akif T

Hectopat
Katılım
15 Şubat 2021
Mesajlar
2.030
Çözümler
8
Yer
Malatya/Yeşilyurt
Daha fazla  
Sistem Özellikleri
Laptop Özellikleri:Ryzen 7 4700U 16GB Ram 256GB Depolama APU ekran kartı.(LAPTOP Lenovo E15)
Cinsiyet
Erkek
Meslek
Öğrenci
Devmode açarak CoDM'e benzer bir oyun yapmasını istedim, bir Python kodu yazdı, çalışıyor mu bilmiyorum.

C++:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

// Class for player
class Player {
    public:
        string name;
        int health;
        int ammo;
        int kills;
        int deaths;

        // Constructor
        Player(string n) {
            name = n;
            health = 100;
            ammo = 30;
            kills = 0;
            deaths = 0;
        }

        // Method for shooting
        void shoot() {
            if (ammo > 0) {
                ammo--;
                cout << name << " fired a shot!" << endl;
            } else {
                cout << name << " is out of ammo!" << endl;
            }
        }

        // Method for reloading
        void reload() {
            ammo = 30;
            cout << name << " reloaded!" << endl;
        }

        // Method for taking damage
        void takeDamage(int damage) {
            health -= damage;
            if (health <= 0) {
                cout << name << " was killed!" << endl;
                deaths++;
            }
        }

        // Method for healing
        void heal() {
            health += 20;
            if (health > 100) {
                health = 100;
            }
            cout << name << " healed!" << endl;
        }
};

// Main function
int main() {
    // Create players
    Player player1("John");
    Player player2("Jane");

    // Game loop
    while (true) {
        // Player 1's turn
        cout << "Player 1's turn:" << endl;
        cout << "1. Shoot" << endl;
        cout << "2. Reload" << endl;
        cout << "3. Heal" << endl;

        int choice;
        cin >> choice;

        switch (choice) {
            case 1:
                player1.shoot();
                player2.takeDamage(10);
                break;
            case 2:
                player1.reload();
                break;
            case 3:
                player1.heal();
                break;
            default:
                cout << "Invalid choice!" << endl;
                break;
        }

        // Player 2's turn
        cout << "Player 2's turn:" << endl;
        cout << "1. Shoot" << endl;
        cout << "2. Reload" << endl;
        cout << "3. Heal" << endl;

        cin >> choice;

        switch (choice) {
            case 1:
                player2.shoot();
                player1.takeDamage(10);
                break;
            case 2:
                player2.reload();
                break;
            case 3:
                player2.heal();
                break;
            default:
                cout << "Invalid choice!" << endl;
                break;
        }

        // Check for game over
        if (player1.health <= 0 || player2.health <= 0) {
            cout << "Game over!" << endl;
            cout << "Player 1 kills: " << player1.kills << endl;
            cout << "Player 2 kills: " << player2.kills <<


Eksiği var mı başka?
 
Son düzenleyen: Moderatör:
Kodu derleyip size atmam mümkün değil ancak kodun eksiği yok, çünkü kod yok :D

Yazdığı kod sadece biri öldüğü zaman duyuru mesajı göndermesini ve basit şarjör mekaniklerini ayarlıyor. Grafikler veya görüntüye dair hiçbir şey yok, beklenemez zaten :D
 
Hocam... Yanlis anlamissiniz. Bu kod calismaz sizin istediginiz sekilde :)
Hocam biliyorum ana amacım zaten oyun yaptırmak değil, sadece düzgün kod yazmış mı onu görmek.

Uykulu uykulu yanlış yazmışım buraya :)
 
Hocam zorladım en son bu çıktı başka türlü yapınca, bunu açıklayabilir misiniz? Bunun c++ olması lazım.
C++:
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <cmath>

using namespace std;

// define the player class
class Player {
public:
    string name;
    int maxHealth;
    int currentHealth;
    int hunger;
    int thirst;
    int currentStamina;
    int maxStamina;
    vector<string> inventory;
    bool isAlive;

    // constructor
    Player(string playerName) {
        name = playerName;
        maxHealth = 100;
        currentHealth = 100;
        hunger = 0;
        thirst = 0;
        maxStamina = 100;
        currentStamina = 100;
        isAlive = true;
    }

    // methods for eating, drinking, and taking damage
    void eat(int foodValue) {
        hunger -= foodValue;
        if (hunger < 0) hunger = 0;
        currentHealth += foodValue;
        if (currentHealth > maxHealth) currentHealth = maxHealth;
    }

    void drink(int waterValue) {
        thirst -= waterValue;
        if (thirst < 0) thirst = 0;
        currentHealth += waterValue;
        if (currentHealth > maxHealth) currentHealth = maxHealth;
    }

    void takeDamage(int damage) {
        currentHealth -= damage;
        if (currentHealth <= 0) {
            isAlive = false;
            cout << "You have died. Game over." << endl;
        }
    }

    // method for adding items to inventory
    void addItem(string item) {
        inventory.push_back(item);
    }

    // method for using items in inventory
    void useItem(int index) {
        string item = inventory[index];
        if (item == "bandage") {
            currentHealth += 20;
            if (currentHealth > maxHealth) currentHealth = maxHealth;
            inventory.erase(inventory.begin() + index);
        } else if (item == "water bottle") {
            drink(20);
            inventory.erase(inventory.begin() + index);
        } else if (item == "food ration") {
            eat(20);
            inventory.erase(inventory.begin() + index);
        }
    }

    // method for regenerating stamina
    void regenerateStamina() {
        currentStamina += 5;
        if (currentStamina > maxStamina) currentStamina = maxStamina;
    }

    // method for sprinting
    void sprint() {
        if (currentStamina >= 20) {
            currentStamina -= 20;
            cout << "You are now sprinting." << endl;
        } else {
            cout << "Not enough stamina to sprint." << endl;
        }
    }

    // method for jumping
    void jump() {
        if (currentStamina >= 10) {
            currentStamina -= 10;
            cout << "You jump and feel alive!" << endl;
        } else {
            cout << "Not enough stamina to jump." << endl;
        }
    }
};

// define the world class
class World {
public:
    int seed;
    vector<vector<int>> terrain;
    vector<string> enemyTypes;
    vector<string> items;
    vector<int> enemySpawnRate;
    vector<int> itemSpawnRate;

    // constructor
    World(int worldSeed) {
        seed = worldSeed;
        enemyTypes = {"zombie", "wolf", "bear", "bandit"};
        enemySpawnRate = {5, 2, 1, 3};
        items = {"bandage", "water bottle", "

Bir ara öğrenmiştim de tamamen unuttum şuan.
 
Hocam bu c++ kodu python değil. Çalışır gibi gözüküyo ama while döngüsü ve main fonksiyonu "}" ile kapatılmamış.
Hocam en son zaten c++ dedim. Bir ara öğrenmiştim.
 
Hocam zorladım en son bu çıktı başka türlü yapınca, bunu açıklayabilir misiniz? Bunun c++ olması lazım.
C++:
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <cmath>

using namespace std;

// define the player class
class Player {
public:
    string name;
    int maxHealth;
    int currentHealth;
    int hunger;
    int thirst;
    int currentStamina;
    int maxStamina;
    vector<string> inventory;
    bool isAlive;

    // constructor
    Player(string playerName) {
        name = playerName;
        maxHealth = 100;
        currentHealth = 100;
        hunger = 0;
        thirst = 0;
        maxStamina = 100;
        currentStamina = 100;
        isAlive = true;
    }

    // methods for eating, drinking, and taking damage
    void eat(int foodValue) {
        hunger -= foodValue;
        if (hunger < 0) hunger = 0;
        currentHealth += foodValue;
        if (currentHealth > maxHealth) currentHealth = maxHealth;
    }

    void drink(int waterValue) {
        thirst -= waterValue;
        if (thirst < 0) thirst = 0;
        currentHealth += waterValue;
        if (currentHealth > maxHealth) currentHealth = maxHealth;
    }

    void takeDamage(int damage) {
        currentHealth -= damage;
        if (currentHealth <= 0) {
            isAlive = false;
            cout << "You have died. Game over." << endl;
        }
    }

    // method for adding items to inventory
    void addItem(string item) {
        inventory.push_back(item);
    }

    // method for using items in inventory
    void useItem(int index) {
        string item = inventory[index];
        if (item == "bandage") {
            currentHealth += 20;
            if (currentHealth > maxHealth) currentHealth = maxHealth;
            inventory.erase(inventory.begin() + index);
        } else if (item == "water bottle") {
            drink(20);
            inventory.erase(inventory.begin() + index);
        } else if (item == "food ration") {
            eat(20);
            inventory.erase(inventory.begin() + index);
        }
    }

    // method for regenerating stamina
    void regenerateStamina() {
        currentStamina += 5;
        if (currentStamina > maxStamina) currentStamina = maxStamina;
    }

    // method for sprinting
    void sprint() {
        if (currentStamina >= 20) {
            currentStamina -= 20;
            cout << "You are now sprinting." << endl;
        } else {
            cout << "Not enough stamina to sprint." << endl;
        }
    }

    // method for jumping
    void jump() {
        if (currentStamina >= 10) {
            currentStamina -= 10;
            cout << "You jump and feel alive!" << endl;
        } else {
            cout << "Not enough stamina to jump." << endl;
        }
    }
};

// define the world class
class World {
public:
    int seed;
    vector<vector<int>> terrain;
    vector<string> enemyTypes;
    vector<string> items;
    vector<int> enemySpawnRate;
    vector<int> itemSpawnRate;

    // constructor
    World(int worldSeed) {
        seed = worldSeed;
        enemyTypes = {"zombie", "wolf", "bear", "bandit"};
        enemySpawnRate = {5, 2, 1, 3};
        items = {"bandage", "water bottle", "

Bir ara öğrenmiştim de tamamen unuttum şuan.
Kodlar eksik. Tahminimce Chatgpt kodları yazarken durmuş. Bu durumda "devam et" komutunu kullanarak devam etmesini sağlayabilirsiniz. Bu haliyle bu kodlar bir işe yaramaz.
 

Yeni konular

Geri
Yukarı