目录
第五步:点击 Install ,查看安装好的飞算JavaAI
飞算 JavaAl 产品介绍
飞算JavaAI 是飞算科技于2025年1月发布的全球首款聚焦Java语言的智能开发助手。该工具通过自然语言或语音输入开发需求,可自动完成需求分析、软件设计及完整工程代码生成全流程,输出包含配置类文件、Java源代码目录、资源文件及测试资源在内的整套工程源码。相较于片段式代码生成工具,其完整工程代码生成能力使开发效率提升10倍,有效降低重复编码工作量,助力开发者聚焦业务逻辑创新与系统架构优化。
安装飞算 JavaAl
第一步:点击 File->Setting
第二步:点击 Plugins
第三步:搜索 CalEx-JavaAI
第四步:点击 Install 进行安装
静静等待安装 ing~
第五步:点击 Install ,查看安装好的飞算JavaAI
点击Apply然后在点击OK
安装成功!!!
注册飞算 JavaAI
第一步:点击Java chat,再点击立即登录
第二步:注册账号
微信扫码就可以直接注册登录了,然后绑定一下手机号即可
注册登录成功,可以开始使用飞算JavaAI了
体验飞算JavaAI
1、体验它的代码编写能力
生成一个贪吃蛇小游戏,用JavaFX编写,注意页面的美观。
直接就将代码写好了,我们直接点击接受就行
这里可以看到飞算JavaAI帮我们生成的项目目录,十分规范。代码也帮我们直接写好了,我们不需要写任何代码,现在直接让我们来测试一下它写的代码有没有什么问题。
点击运行代码
可以看到非常顺利的运行了出来,十分简单
我们刚刚体验了飞算JavaAI在Java项目结构上的创建以及代码的编写能力,体验感非常的不错,可以很快的帮我们处理我们遇到的问题。那么接下来我们在那飞算JavaAI来测试一下它在代码的优化以及交换上面的体验。
2、体验飞算JavaAI对代码的优化和改进
AI提示词:我觉的这个界面不说很好看,请你帮我设计的更加好看一点,并且我觉得将每场得分的结果记录在我的数据库表中,我的数据库地址是localhost:3306,用户名root,密码1234。游戏失败了可以重新开始。
可以建到它将游戏界面优化的更加炫酷了。
并且创建了属于该项目的数据库。
create database mygame;
USE mygame;
CREATE TABLE snake_scores (
id INT AUTO_INCREMENT PRIMARY KEY,
score INT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
基本上要求全部都达到了,后期只需要按照自己的需求慢慢改进即可。使用起来还是十分顺手的。
3、分享部分贪吃蛇代码(看看飞算JavaAI写的怎么样)
SnakeGame.Java文件
package com.hmall.fxcsdn;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class SnakeGame extends Application {
private static final int TILE_SIZE = 20;
private static final int WIDTH = 30;
private static final int HEIGHT = 30;
private Canvas canvas;
private GraphicsContext gc;
private int[] snakeX = new int[WIDTH * HEIGHT];
private int[] snakeY = new int[WIDTH * HEIGHT];
private int snakeLength = 3;
private int foodX;
private int foodY;
private int directionX = 1;
private int directionY = 0;
private int score = 0;
private Label scoreLabel;
private Label statusLabel;
private AnimationTimer timer;
private Button restartButton;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("贪吃蛇游戏");
canvas = new Canvas(WIDTH * TILE_SIZE, HEIGHT * TILE_SIZE);
gc = canvas.getGraphicsContext2D();
scoreLabel = new Label("Score: " + score);
scoreLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: white;");
statusLabel = new Label("Status: Playing");
statusLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: white;");
restartButton = new Button("重新开始");
restartButton.setOnAction(event -> restartGame());
restartButton.setStyle("-fx-font-size: 24px; -fx-background-color: darkgreen; -fx-text-fill: white;");
HBox controls = new HBox(10, scoreLabel, statusLabel, restartButton);
controls.setAlignment(Pos.CENTER);
controls.setStyle("-fx-background-color: #333333; -fx-padding: 10px;");
BorderPane root = new BorderPane();
root.setTop(controls);
root.setCenter(canvas);
root.setStyle("-fx-background-color: black;");
Scene scene = new Scene(root, WIDTH * TILE_SIZE, HEIGHT * TILE_SIZE + 50);
scene.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
switch (event.getCode()) {
case UP:
if (directionY == 0) {
directionX = 0;
directionY = -1;
}
break;
case DOWN:
if (directionY == 0) {
directionX = 0;
directionY = 1;
}
break;
case LEFT:
if (directionX == 0) {
directionX = -1;
directionY = 0;
}
break;
case RIGHT:
if (directionX == 0) {
directionX = 1;
directionY = 0;
}
break;
}
});
primaryStage.setScene(scene);
primaryStage.show();
generateFood();
timer = new AnimationTimer() {
@Override
public void handle(long now) {
update();
draw();
}
};
timer.start();
}
private void generateFood() {
foodX = (int) (Math.random() * WIDTH);
foodY = (int) (Math.random() * HEIGHT);
}
private void update() {
for (int i = snakeLength; i > 0; i--) {
snakeX[i] = snakeX[i - 1];
snakeY[i] = snakeY[i - 1];
}
snakeX[0] += directionX;
snakeY[0] += directionY;
if (snakeX[0] >= WIDTH || snakeX[0] < 0 || snakeY[0] >= HEIGHT || snakeY[0] < 0) {
// 游戏结束条件
System.out.println("游戏结束!");
statusLabel.setText("Status: Game Over");
timer.stop();
saveScore(score);
}
if (snakeX[0] == foodX && snakeY[0] == foodY) {
snakeLength++;
score++;
scoreLabel.setText("Score: " + score);
generateFood();
}
for (int i = 1; i < snakeLength; i++) {
if (snakeX[0] == snakeX[i] && snakeY[0] == snakeY[i]) {
// 游戏结束条件
System.out.println("游戏结束!");
statusLabel.setText("Status: Game Over");
timer.stop();
saveScore(score);
}
}
}
private void draw() {
gc.clearRect(0, 0, WIDTH * TILE_SIZE, HEIGHT * TILE_SIZE);
// 绘制食物
gc.setFill(Color.RED);
gc.fillRect(foodX * TILE_SIZE, foodY * TILE_SIZE, TILE_SIZE, TILE_SIZE);
// 绘制蛇
gc.setFill(Color.GREEN);
for (int i = 0; i < snakeLength; i++) {
gc.fillRect(snakeX[i] * TILE_SIZE, snakeY[i] * TILE_SIZE, TILE_SIZE - 2, TILE_SIZE - 2);
}
}
private void restartGame() {
snakeLength = 3;
score = 0;
scoreLabel.setText("Score: " + score);
statusLabel.setText("Status: Playing");
directionX = 1;
directionY = 0;
generateFood();
timer.start();
}
private void saveScore(int score) {
String url = "jdbc:mysql://localhost:3306/mygame"; // 替换为您的数据库名称
String user = "root";
String password = "1234";
try (Connection conn = DriverManager.getConnection(url, user, password)) {
String sql = "INSERT INTO snake_scores (score) VALUES (?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, score);
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println("Error saving score: " + e.getMessage());
}
}
public static void main(String[] args) {
launch(args);
}
}
SnakeGame.Java文件
package com.snakegame;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class SnakeGame extends Application {
private static final int TILE_SIZE = 20;
private static final int WIDTH = 30;
private static final int HEIGHT = 30;
private Canvas canvas;
private GraphicsContext gc;
private int[] snakeX = new int[WIDTH * HEIGHT];
private int[] snakeY = new int[WIDTH * HEIGHT];
private int snakeLength = 3;
private int foodX;
private int foodY;
private int directionX = 1;
private int directionY = 0;
private int score = 0;
private Label scoreLabel;
private Label statusLabel;
private AnimationTimer timer;
private Button restartButton;
private long lastUpdateTime = 0;
private static final long UPDATE_INTERVAL = 200_000_000; // 0.2秒
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("贪吃蛇游戏");
canvas = new Canvas(WIDTH * TILE_SIZE, HEIGHT * TILE_SIZE);
gc = canvas.getGraphicsContext2D();
scoreLabel = new Label("Score: " + score);
scoreLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: white;");
statusLabel = new Label("Status: Playing");
statusLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: white;");
restartButton = new Button("重新开始");
restartButton.setOnAction(event -> restartGame());
restartButton.setStyle("-fx-font-size: 24px; -fx-background-color: darkgreen; -fx-text-fill: white;");
HBox controls = new HBox(10, scoreLabel, statusLabel, restartButton);
controls.setAlignment(Pos.CENTER);
controls.setStyle("-fx-background-color: #333333; -fx-padding: 10px;");
BorderPane root = new BorderPane();
root.setTop(controls);
root.setCenter(canvas);
root.setStyle("-fx-background-color: black;");
Scene scene = new Scene(root, WIDTH * TILE_SIZE, HEIGHT * TILE_SIZE + 50);
scene.setOnKeyPressed(event -> {
switch (event.getCode()) {
case UP:
if (directionY == 0) {
directionX = 0;
directionY = -1;
}
break;
case DOWN:
if (directionY == 0) {
directionX = 0;
directionY = 1;
}
break;
case LEFT:
if (directionX == 0) {
directionX = -1;
directionY = 0;
}
break;
case RIGHT:
if (directionX == 0) {
directionX = 1;
directionY = 0;
}
break;
}
});
primaryStage.setScene(scene);
primaryStage.show();
generateFood();
timer = new AnimationTimer() {
@Override
public void handle(long now) {
if (now - lastUpdateTime >= UPDATE_INTERVAL) {
update();
draw();
lastUpdateTime = now;
}
}
};
timer.start();
}
private void generateFood() {
foodX = (int) (Math.random() * WIDTH);
foodY = (int) (Math.random() * HEIGHT);
}
private void update() {
for (int i = snakeLength; i > 0; i--) {
snakeX[i] = snakeX[i - 1];
snakeY[i] = snakeY[i - 1];
}
snakeX[0] += directionX;
snakeY[0] += directionY;
if (snakeX[0] >= WIDTH || snakeX[0] < 0 || snakeY[0] >= HEIGHT || snakeY[0] < 0) {
// 游戏结束条件
System.out.println("游戏结束!");
statusLabel.setText("Status: Game Over");
timer.stop();
saveScore(score);
}
if (snakeX[0] == foodX && snakeY[0] == foodY) {
snakeLength++;
score++;
scoreLabel.setText("Score: " + score);
generateFood();
}
for (int i = 1; i < snakeLength; i++) {
if (snakeX[0] == snakeX[i] && snakeY[0] == snakeY[i]) {
// 游戏结束条件
System.out.println("游戏结束!");
statusLabel.setText("Status: Game Over");
timer.stop();
saveScore(score);
}
}
}
private void draw() {
gc.clearRect(0, 0, WIDTH * TILE_SIZE, HEIGHT * TILE_SIZE);
// 绘制食物
gc.setFill(Color.RED);
gc.fillRect(foodX * TILE_SIZE, foodY * TILE_SIZE, TILE_SIZE, TILE_SIZE);
// 绘制蛇
gc.setFill(Color.GREEN);
for (int i = 0; i < snakeLength; i++) {
gc.fillRect(snakeX[i] * TILE_SIZE, snakeY[i] * TILE_SIZE, TILE_SIZE - 2, TILE_SIZE - 2);
}
}
private void restartGame() {
snakeLength = 3;
score = 0;
scoreLabel.setText("Score: " + score);
statusLabel.setText("Status: Playing");
directionX = 1;
directionY = 0;
generateFood();
timer.start();
}
private void saveScore(int score) {
String url = "jdbc:mysql://localhost:3306/mygame"; // 替换为您的数据库名称
String user = "root";
String password = "1234";
try (Connection conn = DriverManager.getConnection(url, user, password)) {
String sql = "INSERT INTO snake_scores (score) VALUES (?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, score);
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println("Error saving score: " + e.getMessage());
}
}
public static void main(String[] args) {
launch(args);
}
}
全是由飞算ai自己写的哦~
总结一下
本次实践验证了飞算 JavaAI 在提升开发效率、降低技术门槛方面的实际价值,其工程化能力已具备生产环境应用基础。期待后续通过算法模型升级与场景拓展,进一步释放智能化开发工具在软件工程全周期中的潜力,为技术团队提供更深度的生产力赋能。
- 完成内容:介绍功能、完成安装注册及实操验证,工具在代码生成、调试等场景表现稳定。
- 后续计划:将在工作中深化应用,观察其在复杂业务场景的表现,期待版本迭代优化。
整体上感觉还不错,后续工作和日常生活中在看看,期待飞算JavaAI后续的表现。