一:DeepSeek-V3

DeepSeek是杭州深度求索公司发布的一系列在知识类任务上表现出色的人工智能模型!

这个模型以其高质量的编码服务而著称简直就是我们开发者的福利,并且DeepSeek还能够处理和分析复杂的数据,执行图像识别、自然语言处理、语音识别和预测分析等任务, 通过模拟人类大脑的神经网络结构来学习数据和规律,并利用这些知识来执行各种任务!

官网地址 https://www.deepseek.com
git: https://github.com/deepseek-ai/DeepSeek-V3

二:注册

https://platform.deepseek.com/sign_in

我们打开官网以后…先用手机注册一个账号!

在这里插入图片描述

成功注册之后,会跳转到DeepSeek-V3用户后台管理界面

我们注册完毕之后,可以先来看看DeepSeek的网页版对话, 这是完全免费的!

三:创建API key

我们登录一下DeepSeek来到开放平台的管理页面, 选择API keys选项
然后点击创建API key

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

这里提示也给我们明确说明了, API key 仅在创建时可见可复制
就是说当我们创建完成之后,这个API Key就设置为不可见了, 所以提前复制好保存到合适的地方去!
在这里插入图片描述

四:网页版

https://chat.deepseek.com/a/chat/

在这里插入图片描述

五:VSCode版

安装Cline插件

Cline是VSCode中的一个扩展插件, 通过它我们可以无缝接入各种AI语言大模型API然后利用AI技术为我们开发者提供智能的代码补全、错误检测与修复、代码生成等功能,提高编程效率和代码质量!

打开VSCode, 点击左侧活动栏中的扩展图标或按下快捷键Ctrl + Shift + X
在搜索框中输入Cline关键字, 并找到相应的插件, 点击Install进行安装!

配置DeepSeek-V3

安装完成后,点击VSCode左侧活动栏中的Cline图标打开配置文件进行编辑
在配置文件中,选择API Provider为DeepSeek,并填入之前创建的API Key

这里有两个错误提示可以不用管它!最后点击上面的Done完成!

在这里插入图片描述

案例:用html+css+javascript给我写个网页版本的坦克大战小游戏

在这里插入图片描述

在这里插入图片描述

index.html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tank Battle Game</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="game-container">
        <canvas id="gameCanvas" width="800" height="600"></canvas>
    </div>
    <script src="game.js"></script>
</body>

</html>
style.css
body {
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #333;
}

.game-container {
    border: 2px solid #fff;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

canvas {
    background-color: #000;
}
game.js
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');

// Game settings
const GAME_WIDTH = 800;
const GAME_HEIGHT = 600;
const TANK_SIZE = 40;
const BULLET_SPEED = 5;
const ENEMY_SPEED = 1.5;

// Player tank
const player = {
    x: GAME_WIDTH / 2,
    y: GAME_HEIGHT - 60,
    width: TANK_SIZE,
    height: TANK_SIZE,
    color: 'green',
    speed: 3,
    direction: 'up',
    bullets: []
};

// Enemy tanks
let enemies = [];
let score = 0;
const ENEMY_SPAWN_RATE = 100; // Frames between enemy spawns
let enemySpawnCounter = 0;

function createEnemy() {
    const enemy = {
        x: Math.random() * (GAME_WIDTH - TANK_SIZE),
        y: 0,
        width: TANK_SIZE,
        height: TANK_SIZE,
        color: 'red',
        speed: ENEMY_SPEED,
        direction: 'down',
        bullets: []
    };
    enemies.push(enemy);
}

function updateEnemies() {
    // Spawn new enemies
    if (enemySpawnCounter >= ENEMY_SPAWN_RATE) {
        createEnemy();
        enemySpawnCounter = 0;
    }
    enemySpawnCounter++;

    // Move and update enemies
    enemies.forEach((enemy, index) => {
        enemy.y += enemy.speed;

        // Remove enemy if out of bounds
        if (enemy.y > GAME_HEIGHT) {
            enemies.splice(index, 1);
        }
    });
}

function checkCollisions() {
    // Check player bullets against enemies
    player.bullets.forEach((bullet, bulletIndex) => {
        enemies.forEach((enemy, enemyIndex) => {
            if (bullet.x < enemy.x + enemy.width &&
                bullet.x + bullet.width > enemy.x &&
                bullet.y < enemy.y + enemy.height &&
                bullet.y + bullet.height > enemy.y) {

                // Collision detected
                player.bullets.splice(bulletIndex, 1);
                enemies.splice(enemyIndex, 1);
                score += 10;
            }
        });
    });
}

// Key states
const keys = {
    ArrowUp: false,
    ArrowDown: false,
    ArrowLeft: false,
    ArrowRight: false,
    Space: false
};

// Event listeners for controls
window.addEventListener('keydown', (e) => {
    if (keys.hasOwnProperty(e.key)) {
        keys[e.key] = true;
    }
});

window.addEventListener('keyup', (e) => {
    if (keys.hasOwnProperty(e.key)) {
        keys[e.key] = false;
    }
});

function drawTank(tank) {
    ctx.save();
    ctx.translate(tank.x + tank.width / 2, tank.y + tank.height / 2);

    // Rotate based on direction
    switch (tank.direction) {
        case 'up': break;
        case 'down': ctx.rotate(Math.PI); break;
        case 'left': ctx.rotate(-Math.PI / 2); break;
        case 'right': ctx.rotate(Math.PI / 2); break;
    }

    // Draw tank body
    ctx.fillStyle = tank.color;
    ctx.fillRect(-tank.width / 2, -tank.height / 2, tank.width, tank.height);

    // Draw tank barrel
    ctx.fillStyle = 'gray';
    ctx.fillRect(-5, -20, 10, 20);

    ctx.restore();
}

function updatePlayer() {
    // Movement
    if (keys.ArrowUp && player.y > 0) {
        player.y -= player.speed;
        player.direction = 'up';
    }
    if (keys.ArrowDown && player.y < GAME_HEIGHT - player.height) {
        player.y += player.speed;
        player.direction = 'down';
    }
    if (keys.ArrowLeft && player.x > 0) {
        player.x -= player.speed;
        player.direction = 'left';
    }
    if (keys.ArrowRight && player.x < GAME_WIDTH - player.width) {
        player.x += player.speed;
        player.direction = 'right';
    }

    // Shooting
    if (keys.Space) {
        shootBullet(player);
        keys.Space = false;
    }
}

function shootBullet(tank) {
    const bullet = {
        x: tank.x + tank.width / 2 - 2.5,
        y: tank.y + tank.height / 2 - 2.5,
        width: 5,
        height: 5,
        color: 'yellow',
        speed: BULLET_SPEED,
        direction: tank.direction
    };
    tank.bullets.push(bullet);
}

function updateBullets() {
    player.bullets.forEach((bullet, index) => {
        // Move bullet based on direction
        switch (bullet.direction) {
            case 'up': bullet.y -= bullet.speed; break;
            case 'down': bullet.y += bullet.speed; break;
            case 'left': bullet.x -= bullet.speed; break;
            case 'right': bullet.x += bullet.speed; break;
        }

        // Remove bullet if out of bounds
        if (bullet.x < 0 || bullet.x > GAME_WIDTH ||
            bullet.y < 0 || bullet.y > GAME_HEIGHT) {
            player.bullets.splice(index, 1);
        }
    });
}

function drawBullets() {
    player.bullets.forEach(bullet => {
        ctx.fillStyle = bullet.color;
        ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
    });
}

// Game loop
function gameLoop() {
    // Clear canvas
    ctx.clearRect(0, 0, GAME_WIDTH, GAME_HEIGHT);

    // Update game state
    updatePlayer();
    updateBullets();
    updateEnemies();
    checkCollisions();

    // Draw game elements
    drawTank(player);
    enemies.forEach(enemy => drawTank(enemy));
    drawBullets();

    // Draw score
    ctx.fillStyle = 'white';
    ctx.font = '20px Arial';
    ctx.fillText(`Score: ${score}`, 10, 30);

    requestAnimationFrame(gameLoop);
}

// Start game
gameLoop();

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐