C#学习:综合练习聊天机器人第一版

传智播客.Net培训—C#编程基础(综合练习聊天机器人第一版)

编写聊天机器人,如果问“今天天气怎么样?”则回答天气。。。如果说“88”,则回答再见并退出程序。机器人有一个饥饿值,每聊天一句饥饿值-1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 聊天机器人1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("您好,我是机器人");
            int fullLevel = 5;   //初始化饥饿值
            while (true)   
            {
                string str = Console.ReadLine();   //读取用户输入字符串
                if (fullLevel <= 0)   //当饥饿值小于0时
                {
                    Console.WriteLine("不聊了,饿死了,喂我点东西吃吧");
                    string strFood = Console.ReadLine();
                    int food = Convert.ToInt32(strFood);
                    if (food <= 0)    //所喂事物不能小于0
                    {
                        Console.WriteLine("你在玩我么亲?");
                        return;
                    }
                    if (food > 10)   //所喂食物不能大于10 
                    {
                        Console.WriteLine("撑死了!!!");
                        return;
                    }
                    fullLevel = fullLevel + food;
                    continue;
                }
                if (str == "今天天气怎么样?")
                {
                    Console.WriteLine("天气挺好的!");
                }
                else if (str == "你是男的还是女的?")
                {
                    Console.WriteLine("不要崇拜哥,哥只是传说");
                }
                else if (str == "你有女朋友吗?")
                {
                    Console.WriteLine("年龄太小,不想考虑");
                }
                else if (str == "88")
                {
                    Console.WriteLine("886");
                    return;
                }
                else
                {
                    Console.WriteLine("你说神马?");
                }
                fullLevel--;     //每聊一句饥饿值-1
            }

            Console.ReadKey();
        }
    }
}

执行结果:


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值