C# 检查口袋妖怪是否能进化
我这里有Pokemon.cs:C# 检查口袋妖怪是否能进化,c#,C#,我这里有Pokemon.cs: using System; using System.Collections.Generic; namespace PokemonPocket{ public class PokemonMaster{ public string Name {get;set;} public int NoToEvolve {get; set;} public string EvolveTo {get; set;}
using System;
using System.Collections.Generic;
namespace PokemonPocket{
public class PokemonMaster{
public string Name {get;set;}
public int NoToEvolve {get; set;}
public string EvolveTo {get; set;}
public PokemonMaster(string name, int noToEvolve, string evolveTo){
this.Name = name;
this.NoToEvolve = noToEvolve;
this.EvolveTo = evolveTo;
}
}
这就是我一直在研究的代码:
using System;
using System.Collections.Generic;
using System.Linq;
namespace PokemonPocket
{
class Program
{
static void Main(string[] args)
{
//PokemonMaster list for checking pokemon evolution availability.
List<PokemonMaster> pokemonMasters = new List<PokemonMaster>(){
new PokemonMaster("Pikachu", 2, "Raichu"),
new PokemonMaster("Eevee", 3, "Flareon"),
new PokemonMaster("Charmander", 1, "Charmeleon")
};
// Use "Environment.Exit(0);" if you want to implement an exit of the console program
PokemonMenu();
}
static void PokemonMenu() {
// From now on myDictionary is available for any menu option
var myDictionary = new Dictionary<string, string>();
while (true) { // <- loop until exit option (key 'Q') is pressed
Console.WriteLine("Welcome to Pokemon Pocket App!");
Console.WriteLine("(1). Add Pokemon to my pocket");
Console.WriteLine("(2). List Pokemon(s) in my pocket");
Console.WriteLine("(3). Check if I can evolve Pokemon");
Console.WriteLine("(4). Evolve Pokemon\n");
Console.Write("Please only enter [1,2,3,4] or Q to exit:");
char menu = Convert.ToChar(Console.ReadLine());
if (menu == '1') { //Part 1
Console.Write("Enter Pokemon Name :");
string name = Console.ReadLine();
Console.Write("Enter Pokemon HP : ");
int hp = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Pokemon EXP : ");
int exp = Convert.ToInt32(Console.ReadLine());
if (myDictionary.Count <= 0) {
myDictionary.Add("Pokemon's Name", name);
myDictionary.Add("Pokemon's HP", hp.ToString());
myDictionary.Add("Pokemon's EXP", exp.ToString());
Console.WriteLine("Pokemon has been added!");
}
}
else if (menu == '2') { //Part 2
foreach (var v in myDictionary)
Console.WriteLine(string.Format("{1}: {0}", v.Value, v.Key));
}
else if(menu == '3') { //Part 3
}
else if (menu == 'Q') {
Console.WriteLine("App exited!");
Environment.Exit(0);
}
}
}
}
}
我该怎么做?这应该可以:
使用系统;
使用System.Collections.Generic;
使用System.Linq;
命名空间口袋妖怪
{
班级计划
{
静态void Main(字符串[]参数)
{
//用于检查pokemon evolution可用性的PokemonMaster列表。
List pokemonMasters=newlist(){
新口袋妖怪大师(“皮卡丘”,2,“雷丘”),
新口袋妖怪大师(“Eevee”,3,“Flareon”),
新口袋妖怪大师(“魔术师”,1,“魔术师”)
};
//如果要实现控制台程序的退出,请使用“Environment.Exit(0);”
口袋妖怪;
}
静态void PokemonMenu(列出pokemans)
{
//从现在起,myDictionary可用于任何菜单选项
var myDictionary=newdictionary();
while(true)
{//您的“NoToEvolve”成员是一个整数:public int NoToEvolve{get;set;}
这个数字是什么意思?这个数字如何告诉你口袋妖怪是否可以进化?这个字段的有效值是什么?我肯定答案是一个简单的if
语句,但你没有给我们足够的信息来回答这个问题。也许“if”可以,我需要尝试,但“notevolution”进化是按照特定的顺序进行的,比如如果字典里有所有3个口袋妖怪,没有1个的口袋妖怪会先进化,所以onOkay…同样,这里没有足够的信息。如果“NoToEvolve”只是一个排序字段,那么用什么来确定口袋妖怪是否可以进化?是“exp”吗字段?如果是的话,你在对比什么?每个口袋妖怪都有它需要的不同XP量吗?用简单的英语解释一下,并在你的帖子中显示相关的字段…这一个很好用,谢谢,但是你能解释一下你为Console.WriteLine($“{matchedPokemon.Name}-->{matchedPokemon.evolve}”)做了什么吗;
@user15982865该语句相当于Console.WriteLine(string.Format(“{0}-->{1}”),matchedpookemon.Name,matchedpookemon.EvolveTo)
,但它使用了更新的语法,使它更容易一些:
Charmander --> Charmeleon