2024.9.24

上次软件构造课程的作业:

一. 多选题(共8题,66.4分)

1. (多选题)从软件工程方面,软件可以划分为:

  • A. 支撑软件
  • B. 单机软件
  • C. 应用软件
  • D. 系统软件
我的答案: CD:应用软件; 系统软件;正确答案: ACD:支撑软件; 应用软件; 系统软件;
 
4.2分

2. (多选题)常见的软件开发过程包括:

  • A. 个体软件过程
  • B. 增量式开发过程
  • C. 团队软件过程
  • D. 瀑布式开发过程
我的答案: BD:增量式开发过程; 瀑布式开发过程;正确答案: ABCD:个体软件过程; 增量式开发过程; 团队软件过程; 瀑布式开发过程;
 
4.2分

3. (多选题)敏捷开发的核心价值观包括:

  • A. 响应变化胜过遵循计划
  • B. 个体和互动胜过流程和工具
  • C. 客户合作胜过合同谈判
  • D. 不需要文档
我的答案: ABC:响应变化胜过遵循计划; 个体和互动胜过流程和工具; 客户合作胜过合同谈判;正确答案: ABC:响应变化胜过遵循计划; 个体和互动胜过流程和工具; 客户合作胜过合同谈判;
 
8.3分

4. (多选题)从服务对象方面,软件可以划分为:

  • A. 项目软件
  • B. 产品软件
  • C. 网络软件
  • D. 单机软件
我的答案: AB:项目软件; 产品软件;正确答案: AB:项目软件; 产品软件;
 
8.3分

5. (多选题)软件包括:

  • A. 程序
  • B. 开发者
  • C. 文档
  • D. 数据
我的答案: AC:程序; 文档;正确答案: ACD:程序; 文档; 数据;
 
4.2分

6. (多选题)敏捷技术常见的最佳实践方法包括:

  • A. 结对编程
  • B. 代码重构
  • C. 测试驱动开发
  • D. 持续集成
我的答案: ABCD:结对编程; 代码重构; 测试驱动开发; 持续集成;正确答案: ABCD:结对编程; 代码重构; 测试驱动开发; 持续集成;
 
8.3分

7. (多选题)常见计算机编程语言

  • A. Java
  • B. C
  • C. Python
  • D. 自然语言
我的答案: ABC:Java; C; Python;正确答案: ABC:Java; C; Python;
 
8.3分

8. (多选题)Scrum框架的角色包括:

  • A. 产品负责人
  • B. 项目经理
  • C. 产品经理
  • D. 团队
我的答案: ABD:产品负责人; 项目经理; 团队;正确答案: ACD:产品负责人; 产品经理; 团队;
 
0分

二. 单选题(共2题,16.8分)

9. (单选题)关于软件生命周期说法正确的是:

  • A. 软件开发+软件测试
  • B. 从软件需求,到软件开发,到最终软件不再使用的整个过程。
  • C. 软件开发的整个过程
  • D. 软件开发+软件测试+软件出售
我的答案: B:从软件需求,到软件开发,到最终软件不再使用的整个过程。;正确答案: B:从软件需求,到软件开发,到最终软件不再使用的整个过程。;
 
8.4分

10. (单选题)构造占软件开发()的工作时间

  • A. 10%~30%
  • B. 0%~10%
  • C. 80%~90%
  • D. 30%~80%
我的答案: D:30%~80%;正确答案: D:30%~80%;
 
8.4分

三. 判断题(共1题,8.4分)

11. (判断题)敏捷开发可以替代传统开发模式。

  • A. 对
  • B. 错
我的答案: 错正确答案: 错

四. 简答题(共1题,8.4分)

12. (简答题)

请利用文心一言等大模型开发一个具有界面的贪吃蛇小游戏,采用Java或Python语言。要求提交源代码及运行视频。

1、要有简单的界面

2、要可操控

3、代码要自行运行,视频录制代码在编译器里运行然后出界面的过程。

我的代码:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Random;

public class SnakeGame extends JPanel implements ActionListener {

    private static final int TILE_SIZE = 20;         // 每个网格的尺寸
    private static final int WIDTH = 600;            // 游戏窗口的宽度
    private static final int HEIGHT = 400;           // 游戏窗口的高度
    private static final int NUM_TILES_X = WIDTH / TILE_SIZE; // 网格的宽度
    private static final int NUM_TILES_Y = HEIGHT / TILE_SIZE; // 网格的高度
    private static final int INIT_LENGTH = 3;        // 初始蛇的长度
    private static final int INITIAL_DELAY = 200;    // 初始定时器延迟(毫秒)
    private static final int MIN_DELAY = 50;         // 最小定时器延迟(毫秒)

    private ArrayList<Point> snake;   // 蛇的身体
    private Point food;               // 食物的位置
    private int direction;            // 蛇的移动方向(0:上,1:右,2:下,3:左)
    private boolean growing;         // 是否需要增长
    private boolean gameOver;        // 游戏是否结束
    private Timer timer;             // 定时器,用于更新游戏状态
    private int delay;               // 当前定时器延迟

    public SnakeGame() {
        this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
        this.setBackground(Color.BLACK);
        this.setFocusable(true);

        this.snake = new ArrayList<>();
        for (int i = INIT_LENGTH - 1; i >= 0; i--) {
            snake.add(new Point(NUM_TILES_X / 2, NUM_TILES_Y / 2 + i));
        }

        this.direction = 1; // 初始化时蛇向右移动
        this.growing = false;
        this.gameOver = false;

        this.delay = INITIAL_DELAY;
        this.timer = new Timer(delay, this);
        this.timer.start();

        this.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                switch (e.getKeyCode()) {
                    case KeyEvent.VK_UP:
                        if (direction != 2) direction = 0;
                        break;
                    case KeyEvent.VK_RIGHT:
                        if (direction != 3) direction = 1;
                        break;
                    case KeyEvent.VK_DOWN:
                        if (direction != 0) direction = 2;
                        break;
                    case KeyEvent.VK_LEFT:
                        if (direction != 1) direction = 3;
                        break;
                }
            }
        });

        spawnFood();
    }

    private void spawnFood() {
        Random rand = new Random();
        int x = rand.nextInt(NUM_TILES_X);
        int y = rand.nextInt(NUM_TILES_Y);
        food = new Point(x, y);
    }

    private void moveSnake() {
        Point head = snake.get(0);
        Point newHead = (Point) head.clone();

        switch (direction) {
            case 0: newHead.y--; break;  // 向上移动
            case 1: newHead.x++; break;  // 向右移动
            case 2: newHead.y++; break;  // 向下移动
            case 3: newHead.x--; break;  // 向左移动
        }

        if (newHead.equals(food)) {
            growing = true;
            spawnFood();
            // 每吃到食物,减少延迟,使游戏加速
            delay = Math.max(MIN_DELAY, delay - 10);
            timer.setDelay(delay);
        }

        if (newHead.x < 0 || newHead.x >= NUM_TILES_X || newHead.y < 0 || newHead.y >= NUM_TILES_Y || snake.contains(newHead)) {
            gameOver = true;
        }

        if (!gameOver) {
            snake.add(0, newHead);
            if (!growing) {
                snake.remove(snake.size() - 1);
            } else {
                growing = false;
            }
        }
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        if (gameOver) {
            g.setColor(Color.RED);
            g.setFont(new Font("Arial", Font.BOLD, 30));
            g.drawString("Game Over!", WIDTH / 2 - 80, HEIGHT / 2);
            return;
        }

        g.setColor(Color.GREEN);
        for (Point p : snake) {
            g.fillRect(p.x * TILE_SIZE, p.y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
        }

        g.setColor(Color.RED);
        g.fillRect(food.x * TILE_SIZE, food.y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (!gameOver) {
            moveSnake();
            repaint();
        }
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("贪吃蛇游戏");
        SnakeGame game = new SnakeGame();
        frame.add(game);
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

 

posted @ 2024-12-25 01:53  cvjj  阅读(8)  评论(0)    收藏  举报