使用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;
}

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



