使用VSCode开发少儿编程项目:聊天机器人(基于规则)

使用VSCode开发少儿编程项目:聊天机器人(基于规则)

我将为你创建一个简单而有趣的基于规则的聊天机器人,适合在VSCode中开发和学习。这个项目使用预设的规则和关键词来回应。

代码实现

以下是完整的HTML文件,包含所有必要的HTML、CSS和JavaScript代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能聊天机器人 - 少儿编程项目</title>
    <style>
        * {
     
     
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
     
     
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: #333;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        
        .container {
     
     
            width: 100%;
            max-width: 800px;
            background: white;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            overflow: hidden;
        }
        
        header {
     
     
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            color: white;
            padding: 25px;
            text-align: center;
        }
        
        h1 {
     
     
            font-size: 2.2rem;
            margin-bottom: 10px;
        }
        
        .subtitle {
     
     
            font-size: 1.1rem;
            opacity: 0.9;
        }
        
        .chat-container {
     
     
            display: flex;
            flex-direction: column;
            height: 500px;
        }
        
        .chat-header {
     
     
            background: #f8f9fa;
            padding: 15px 20px;
            border-bottom: 1px solid #e9ecef;
            display: flex;
            align-items: center;
        }
        
        .bot-avatar {
     
     
            width: 40px;
            height: 40px;
            background: #4facfe;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            font-size: 1.2rem;
        }
        
        .bot-info h3 {
     
     
            font-size: 1.2rem;
            margin-bottom: 3px;
        }
        
        .bot-info p {
     
     
            font-size: 0.85rem;
            color: #6c757d;
        }
        
        .chat-messages {
     
     
            flex: 1;
            padding: 20px;
            overflow-y: auto;
            background: #f8f9fa;
        }
        
        .message {
     
     
            max-width: 80%;
            margin-bottom: 15px;
            padding: 12px 16px;
            border-radius: 18px;
            line-height: 1.4;
            position: relative;
            animation: fadeIn 0.3s ease;
        }
        
        @keyframes fadeIn {
     
     
            from {
     
      opacity: 0; transform: translateY(10px); }
            to {
     
      opacity: 1; transform: translateY(0); }
        }
        
        .user-message {
     
     
            background: #4facfe;
            color: white;
            margin-left: auto;
            border-bottom-right-radius: 5px;
        }
        
        
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值