-1
In a program I created a class called Player
and in it assigns various values, among them there is the value of Itens
.
In addition to this class, there is another class called Itens
with different attributes. I would like to know how to assign the class Itens
at value Itens
class Player
.
That is all values of the class Itens
would go for the attribute Itens
class Player
.
Here is my code:
using System;
using System.Collections.Generic;
public class Player
{
public string nome;
public int xp;
public int gold;
public Item();
}
public class Item
{
public string nome;
public int iD;
public int preco;
}
public class LP2_Trabalho
{
static List<Player> Players = new List<Player>();
static void Main(string[] args)
{
bool MostrarMenu = true;
while (MostrarMenu)
{
MostrarMenu = MenuPrincipal();
}
}
private static bool MenuPrincipal()
{
Console.Clear();
Console.WriteLine("Entre com '1' para criar um jogador (necessário para entrar na loja).");
Console.WriteLine("Entre com '2' para checar as informações de todos os jogadores criados.");
Console.WriteLine("Entre com '3' para olhar o seu inventário.");
Console.WriteLine("Entre com '4' para entrar na loja.");
Console.WriteLine("Entre com '4' para encerrar o programa.");
switch (Console.ReadLine())
{
case "1":
Console.Clear();
Console.Write("Digite o nome do seu jogador: ");
var np = Console.ReadLine();
Console.Write("Digite a quantidade de XP (experiência): ");
var xpP = Console.ReadLine();
Random randNum = new Random();
var dinDin = randNum.Next(50, 200);
Players.Add(new Player { nome = np, xp = Convert.ToInt32(xpP), gold = dinDin});
Console.Clear();
Console.WriteLine("Jogador criado com sucesso");
Console.WriteLine("");
Console.WriteLine("Verifique o seu gold (gerado de forma aleatoria): " + dinDin);
Console.WriteLine("Tecle 'ENTER' para continuar...");
Console.ReadLine();
return true;
case "2":
Console.Clear();
for (int i = 0; i < Players.Count; i++)
{
Console.WriteLine("");
Console.WriteLine("Jogadores:");
Console.WriteLine("Nome : " + Players[i].nome);
Console.WriteLine("XP : " + Players[i].xp);
Console.WriteLine("Gold : " + Players[i].gold);
Console.WriteLine("");
}
Console.WriteLine("");
Console.Write("Pressione qualquer tecla para sair...");
Console.ReadKey();
return true;
case "3":
return true;
case "4":
return false;
default:
return true;
}
}
}
PLEASE! If my question is not good for the site tell me what to do! I’ve read the survival guide and the other article showing why my question is not in good quality. Also I already tried to google my problem before coming here. Please don’t close my question :(
– Carlos
Hello Carlos. Try to show us your class
Itens
that you said in the question. You quoted that there is this class, but you don’t show us how it is created. :)– Pedro Paulo
@Pedropaulo sorry about that. I’ve fixed the problems of the question.
– Carlos