Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Island game #665

Open
jasons123fortheuse opened this issue Apr 2, 2023 · 0 comments
Open

Island game #665

jasons123fortheuse opened this issue Apr 2, 2023 · 0 comments

Comments

@jasons123fortheuse
Copy link

import java.util.Scanner;

public class Game {
    private Player player;
    private Level currentLevel;
    private boolean running;

    public Game() {
        player = new Player();
        currentLevel = new Level(1);
        running = true;
    }

    public void start() {
        while (running) {
            // Handle player input
            handleInput();

            // Update game state
            update();

            // Draw game elements
            draw();
        }
    }

    private void handleInput() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a command: ");
        String input = scanner.nextLine();

        switch(input) {
            case "up":
                player.move(0, -1);
                break;
            case "down":
                player.move(0, 1);
                break;
            case "left":
                player.move(-1, 0);
                break;
            case "right":
                player.move(1, 0);
                break;
            default:
                System.out.println("Invalid command!");
                break;
        }
    }

    private void update() {
        // Update game state, such as player position and level progress
        player.update();
        currentLevel.update(player);
    }

    private void draw() {
        // Draw game elements, such as player sprite and level environment
        player.draw();
        currentLevel.draw();
    }

    public static void main(String[] args) {
        Game game = new Game();
        game.start();
    }
}

public class Player {
    private int x, y;
    private int health;
    private int score;

    public Player() {
        x = 0;
        y = 0;
        health = 100;
        score = 0;
    }

    public void update() {
        // Update player state, such as position and health
        health -= 1;

        if (health <= 0) {
            System.out.println("You have died!");
            System.exit(0);
        }
    }

    public void draw() {
        // Draw player sprite
        System.out.println("Player position: (" + x + ", " + y + ")");
    }

    public void move(int dx, int dy) {
        // Move player position by dx, dy
        x += dx;
        y += dy;
    }

    public void takeDamage(int damage) {
        // Reduce player health by damage
PS I love you. And i asked the Ask AI app to write this for me. Get it for free --> https://get-askai.app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant