目錄
飛算 JavaAl 產品介紹?
安裝飛算 JavaAl?
第一步:點擊 File->Setting
第二步:點擊 Plugins
第三步:搜索?CalEx-JavaAI
第四步:點擊 Install 進行安裝
第五步:點擊 Install ,查看安裝好的飛算JavaAI
?注冊飛算 JavaAI
第一步:點擊Java chat,再點擊立即登錄
第二步:注冊賬號
體驗飛算JavaAI
1、體驗它的代碼編寫能力
2、體驗飛算JavaAI對代碼的優化和改進
3、分享部分貪吃蛇代碼(看看飛算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;@Overridepublic 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() {@Overridepublic 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秒@Overridepublic 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() {@Overridepublic 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后續的表現。