gpt4 book ai didi

c++ - 在简单的 C++ 游戏中遇到问题

转载 作者:行者123 更新时间:2023-11-28 01:55:58 25 4
gpt4 key购买 nike

我是一名初级程序员,我目前正在学习 C++ 作为我的第一门语言。我一直在尝试制作一个简单的游戏,但它就是不工作。这并不是给我一个错误,而是当我开始时它没有做它应该做的事情。(使用 Code::Blocks)我也知道有很多未使用的类、函数、变量等。

代码:

#include <iostream>
#include <conio.h>
using namespace std;

int main();

//variables
const int X = 0;
const int Y = 10;
const int Z = 0;
int X1 = X;
int Y1 = Y;
int Z1 = Z;
int Input;
int Input2;

int Menu()
{
cout<<"Please type what you want to do."<<endl;
cin>>Input;

return Input;
//deciding what they want to do.
}

int Calculating()
{
//Calculating Function(Unused)
}

class Player
{
public:
void Movement()
{
//the loop that activates when the Input == 1
while(1)
{
cout<<"2 - Move"<<endl;
do
{
cin>>Input2;
}while(Input2 < 3 && Input2 > 1);

switch(Input2)
{
case 1:
cout<<"You moved"<<endl;
}
}
}
void Attack()
{
//the loop that activates when the Input == 2
while(1)
{
cout<<"1 - Sword Dance"<<endl;
do
{
cin>>Input2;
}while(Input2 < 3 && Input2 > 1);

switch(Input2)
{
case 1:
cout<<"DMG"<<endl;
break;
}
}
}
};

class Enemy
{
//Enemy class(Unused)
};

int main()
{
Player Pl;
//if the chosen number was 1 it will make the Player move.
//if the chosen number was 2 it will make the Player attack.
if(Input == 1)
{
Pl.Movement();
}
else if(Input == 2)
{
Pl.Attack();
}

Menu();
//calling the Menu function
return 0;
}

最佳答案

在您的 Main 中,您必须将 Menu() 调用为:

int main()
{

Player Pl;
Input=Menu();
//if the chosen number was 1 it will make the Player move.
//if the chosen number was 2 it will make the Player attack.
if(Input == 1)
{
Pl.Movement();
}
else if(Input == 2)
{
Pl.Attack();
}

Menu();
//calling the Menu function
return 0;
}

关于c++ - 在简单的 C++ 游戏中遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41184399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com