从零到屎山系列-游戏开发(Day1)

简介

想了想还是猜数游戏最简单,我们只需要简单输入,判断,输出就可以。

猜数游戏

猜数游戏就是电脑心里想一个数字,你来不断的猜它想的数字是多少,猜大了还是小了会告诉你,直到你猜中,游戏结束。

整点活

我觉得仅仅一个猜数太无聊了,来点规则吧,比如说你猜了超过10次,电脑觉得你太笨了,就会强制结束游戏。如果你猜中了,电脑觉得你窥探到了它的内心,它心态炸了会崩溃。

我们的代码如下。

class Game
{
	int answer = 0;
	int count = 0;
public:
	Game(){}

	void Initialize()
	{
		srand((int)time(0));
		answer = rand() % 1000;
	}

	void UpdateFrame()
	{
		int num = 0;
		while(true)
		{ 
			std::cout << "Please input num:";
			std::cin >> num;
			
			if (num < answer)
			{
				std::cout << "Smaller than answer" << std::endl;
			}
			else if (num > answer)
			{
				std::cout << "Bigger than answer" << std::endl;
			}
			else
			{
				std::cout << "You win! I will crash!" << std::endl;
				_sleep(1000);
				assert(0);
			}

			count++;
			if (count > 10)
			{
				std::cout << "You are as stupid as a goose! Bye." << std::endl;
				_sleep(1000);
				return;
			}
		}
	}
};

一个五脏不全但极其调皮的游戏就诞生了。

完整源码

ARTELE/GameDev (github.com)

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-01 06:52:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-01 06:52:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-01 06:52:04       82 阅读
  4. Python语言-面向对象

    2024-05-01 06:52:04       91 阅读

热门阅读

  1. zookeeper相关命令

    2024-05-01 06:52:04       29 阅读
  2. Python.第六章(函数)

    2024-05-01 06:52:04       23 阅读
  3. Electron打包流程

    2024-05-01 06:52:04       24 阅读
  4. selenium启动参数设置

    2024-05-01 06:52:04       28 阅读
  5. nvm pnpm powershell

    2024-05-01 06:52:04       33 阅读
  6. Ubuntu Linux完全入门视频教程

    2024-05-01 06:52:04       30 阅读
  7. 详解FastChat部署大模型API的实战教程

    2024-05-01 06:52:04       31 阅读
  8. macOS asdf 工具版本管理器

    2024-05-01 06:52:04       29 阅读
  9. 云计算知识点-03

    2024-05-01 06:52:04       32 阅读