一、关于
这个游戏(或者说不算个游戏,简单的娱乐项目)是很久以前做的,==现在拿出来与大家分享。
这个游戏包含了两个小的部分,一个是猜数游戏,一个是算术游戏,玩家可以任意挑选并重复游戏,配上了开头可有可无的独白 (_φ(❐_❐✧ 人丑就要多读书
- 源代码在文章末
二、效果图
无零头的开头 (`・ω・´):
选择 ( ̄▽ ̄)/
猜数游戏 ( ̄. ̄):
算数游戏 ヽ(ー_ー)ノ:
全对,送个大爱心 ( ̄^ ̄):
三、源代码
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <cstring>
#include <ctime>
#include <cstdlib>
using namespace std;
void screen();
void time();
void SetPos(COORD);
void SetPos(int, int);
void game1();
void game2();
char name[10];
int main()
{
screen();//界面
int a = 1;
while (a)
{
int answer;//(游戏选择)
cout << "输入数字选择冒险(1or2):" << endl;
cin >> answer;
system("cls");
switch (answer)
{
case 1:game1(); break;
case 2:game2(); break;
}
time();
cout << "0 ———— 退出游戏 1 ———— 继续游戏" << endl;
cin >> a;
}
}
void screen()
{
srand(unsigned(time(NULL)));
cout << '\t' << '\t' << '\t' << '\t' << "欢迎来到冒险岛!" << endl;
system("pause");
cout << '\t' << '\t' << "你只有完成此地冒险,才能回到现实世界。" << endl;
system("pause");
cout << '\t' << '\t' << "什么?不乐意?那么你将永远无法回到现实世界!!!" << endl;
system("pause");
cout << '\t' << '\t' << '\t' << '\t' << "请输入名字:";
cin >> name;
system("pause");
cout << "" << endl;
system("pause");
system("cls");
}
void time()//获取系统时间
{
time_t tm;
time(&tm);
char tmp[128] = { NULL };
strcpy(tmp, ctime(&tm));
cout << "当前时间:" << endl;;
cout << tmp << endl;
}
void SetPos(COORD a)// set cursor //光标定位1
{
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j)// set cursor//光标定位2
{
COORD pos = { i, j };
SetPos(pos);
}
void game1()
{
cout << "规则如下:" << endl << endl;//游戏规则
cout << "每个骰子有6面,这些面包含1、2、3、4、5、6个点";
cout << ",投两枚骰子之后,计算点数之和。如果第一次投的点数和为7或11,则游戏者获胜;";
cout << "如果第一次投的点数和为2、3或12,则游戏者输;如果第一次投的点数和为4、5、6、8、9或10,则";
cout << "将这个和作为游戏者获胜需要掷出的点数,继续投骰子,";
cout << "直到赚到该点数时算是游戏者获胜。如果投掷7次仍未赚到该点数,则游戏者输。" << endl << endl;
srand(unsigned(time(NULL)));//界面准备
int count = 7; int target; int a;
cout << "target: 7or11" << endl << endl;
cout << "a" << '\t' << "b" << " " << "a + b" << endl;
while (count)//运行部分
{
cin >> a;
int b = rand() % 6 + 1;
int sum = a + b;
cout << a << '\t' << b << '\t' << sum << endl;
if (count == 7)//第一次时的数
{
if (sum == 7 || sum == 11)
{
cout << "You are win!" << endl;
return ;
}
else if (sum == 2 || sum == 3 || sum == 12)
{
cout << "You are defeated!" << endl;
return ;
}
else if (sum == 4 || sum == 5 || sum == 6 || sum == 8 || sum == 9 || sum == 10)//当第一次的点数之和位这些值时,改变目标值
{
target = sum;
cout << endl << "target:" << target << endl << endl;
}
}
else//非第一次后改变目标值
{
if (sum == target)
{
cout << "You are win!" << endl;
return ;
}
}
count--;
}
if (count == 0)//7次后未达到目标,判定为输
{
cout << "You are defeated!" << endl;
}
return;
}
void game2()
{
char start;//start the game
int answer;//choose diffculty level
char operation;//choose the operation
int a, b, result, r;
int mark = 0;
cout << "************arithmetic game***************" << endl;
cout << "Are you ready? input T to start game!" << endl;
while (1)
{
cin >> start;
if (start == 'T')
{
break;
}
else
{
cout << "error!\n";
}
}
cout << "*********************************************" << endl;
cout << "Please choose diffculty level(1 or 2):";
while (1)
{
cin >> answer;
if (answer == 1 || answer == 2)
{
break;
}
else
{
cout << "error!\n";
continue;
}
}
cout << "You have chosen diffculty level" << " " << answer << endl;
cout << "*********************************************" << endl;
cout << "Please input the operation( + or - or * ):";
while (1)
{
cin >> operation;
if (operation == '+' || operation == '-' || operation == '*')
{
break;
}
else
{
cout << "error!\n";
}
}
cout << "You have chosen operation" << " " << operation << endl;
cout << "*********************************************" << endl;
for (int i = 1; i <= 10; i++)
{
while (1)
{
if (answer == 1)
{
a = rand() % 10 + 1;
b = rand() % 10 + 1;
}
if (answer == 2)
{
a = rand() % 100 + 10;
b = rand() % 100 + 10;
}
if (operation == '-')
{
if (a < b)
continue;
}
break;
}
cout << a << operation << b << "=";
cin >> result;
switch (operation)
{
case '+': r = a + b; break;
case '-': r = a - b; break;
case '*': r = a * b; break;
}
if (r == result)
{
cout << "mark+10!!!!!!!!" << endl;
mark += 10;
}
else
cout << "Wrong~~~" << endl;
}
cout << name << ",your mark is " << mark << endl;
if (mark <= 100 && mark >= 90)
{
cout << "Your level is S!!!!!!!!" << endl;
cout << "You are 666 and you get a heart! " << endl;
for (float y = 1.5f; y > -1.5f; y -= 0.1f)
{
for (float x = -1.5f; x < 1.5f; x += 0.05f)
{
float a = x * x + y * y - 1;
putchar(a * a * a - x * x * y * y * y <= 0.0f ? '*' : ' ');
}
putchar('\n');
}
cout << endl;
}
else if (mark < 90 && mark >= 80)
{
cout << "Your level is A!!!!!!" << endl;
cout << "You are excellent!you get a triangle! " << endl;
for (int i = 0; i <= 5; i++)
{
for (int j = 0; j < 5 - i; j++)
{
putchar(' ');
}
for (int k = 0; k < 2 * i - 1; k++)
{
cout << "*";
}
cout << endl;
}
cout << endl;
}
else if (mark < 80 && mark >= 70)
{
cout << "Your level is B!!!!\nAdd oil!" << endl;
}
else if (mark < 70 && mark >= 60)
{
cout << "Your level is C!!" << endl;
}
else
{
cout << "Your fail to this test!" << endl;
}
}