如何解决有谁知道我如何在菜单上显示随机选择 6 个项目中的 1 个如剑/盾/等,然后将其添加/显示到背包中?
这是我迄今为止尝试过的,包括我的小班项目游戏的整个项目代码。老实说,与数组斗争,甚至不知道从哪里开始。项目要求显示一个菜单(使用 switch 语句来实现菜单)的操作。然后显示用户选择攻击或不攻击。然后随机拿起一个项目并将随机项目添加到名为 knapSack 的数组中的 6 个项目之一。然后显示用户捡起的物品及其随机名称以及显示 Knap Sacks 内容(已排序)的选项。我实际上是从计算机科学中退学,但如果我不通过这项任务,我就会失败,所以我在乞求 LMAO。
#include <iostream>
#include <string>
#include <stdio.h>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
using namespace std;
int
main ()
{
//Variables
const double stepForest = 50;
const double stepDungeon = 100;
const double stepHouse = 4000;
const double stepMaze = 6000;
//Direction of walking
string north;
string South;
string East;
string West;
//Direction
string direction;
double step;
double steps;
//Asking how many steps
string ssteps;
int nSteps = 0;
//Not allowing negative steps
while (cout << "How many steps are you taking? " << endl
&& !(cin >> nSteps) || nSteps < 0)
{
cin.clear ();
cout << "ERROR: Illegal input!" << endl;
}
//Asking direction user is moving in
cout << "Which direction? (north,West,South,or East) " << endl;
cin >> direction;
//Steps for forest
if (steps >= stepForest && direction == "north");
{
cout << "You have reached the forest. " << endl;
}
//Steps for dungeon
if (steps >= stepDungeon && direction == "South")
{
cout << "You have reached the dungeon. " << endl;
}
//Steps for house
else if (steps >= stepHouse && direction == "East")
{
cout << "You have reached the house. " << endl;
}
//Steps for maze
else if (steps >= stepMaze && direction == "West")
{
cout << "You have reached the maze. " << endl;
}
{
//For menu
int input ();
void output (float);
//Drop down meny bar selections
float result;
int choice,num;
cout << ("Press 1 to attack\n");
cout << ("Press 2 to not attack\n");
cout << ("Press 3 to pick up an item\n");
cout << ("Press 4 to display Knapsack contents\n");
cout << ("Enter your choice:\n");
choice = input ();
//Attack option
switch (choice)
{
case 1:
{
cout << ("You have chosen to attack\n");
cout << ("Your character has attacked\n");
output (result);
break;
}
//No attack option
case 2:
{
cout << ("You have chosen not to attack\n");
cout << ("You do nothing\n");
output (result);
break;
}
//Picking up item option
case 3:
{
cout << ("You have picked up an item\n");
cout << ("The item has been added to Knapsack\n");
//Random array output for knapSack items
char sorteio1[50][11] =
{ "Sword","Scarf","Spear","Knife","Katana","Bow" };
int i;
i = rand () % 50;
cout << ("%s\n",sorteio1[i]);
cout << ("The item you picked up was\n"); //This is where I wanted to insert the random
array
cout << (int ());
// Maybe: "knapsack[count] = loot" *****
// loot= randomItems[randomNumber] *****
//Knapsack contents
output (result);
break;
}
case 4:
{
printf ("1.Sword \n");
printf ("2.Scarf \n");
printf ("3.Spear \n");
printf ("4.Knife \n");
printf ("5.Katana \n");
printf ("6.Bow \n");
output (result);
break;
}
printf ("wrong Input\n");
}
}
int number;
scanf ("%d",&number);
return (number);
{
//To quit game
int choice,num;
bool quit = false;
cout << "Would you like to quit (y/n)? ";
cin >> choice;
//If player chooses to quit
if (choice == 'y')
{
cout << "Goodbye you have chosen to quit the game. See you next time! ";
}
else
{
quit = true;
//If player chooses not to quit,but its the end fo the program anyways so
if (choice == 'n')
{
cout <<
"You have chosen not to quit the game. But this is the end anyways! ";
}
quit = false;
return 0;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。