C
C#•11mo ago
Eren

Need help with pokemon game for school

i only have 2 days left been working on this stuff but its so much and very hard can someone help me
147 Replies
Pobiega
Pobiega•11mo ago
You've made several thread and in all of them you fail to provide any details unless asked. I'd have hoped you would have learned to include details in the opening post instead of us having to drag it out of you So if you truly want help, you'll have to give more details about where you are stuck and what you need help with. Posting a thread and then going to play fortnite isn't really going to finish your assignment on its own 🙂
Angius
Angius•11mo ago
It's a continuation from #calling functions I guess?
Eren
ErenOP•11mo ago
ill give more details my bad
Eren
ErenOP•11mo ago
this is what i need to make i have gotten to phase 3.1 i dont have to skill to get to 4.20 in 1 day and a half why are u being rude im not on the game its open in the background if u got nothing good to say dont reply no i solved that because of u so thank you for that
Pobiega
Pobiega•11mo ago
You made a thread then disappeared for exactly one hour.
Eren
ErenOP•11mo ago
was just wondering if anyone could help me with that i was coding my 3.1 function i solved that issue i had with it as u can see it took me a whole hour because im still a newbie so i made this thread to see if anyone could help speed this up cuz i only have 2 days left
Pobiega
Pobiega•11mo ago
Do you not see how its very rude to make a help post, provide zero details and not even reply to follow up questions?
Eren
ErenOP•11mo ago
i replied gave the file
Pobiega
Pobiega•11mo ago
After an hour. a full hour after getting questions. questions that were asked 4 minutes after you posted the thread.
Eren
ErenOP•11mo ago
i was solving something with the help of someone so i ask for help forget to check which is my bad and ur just gonna sit here n argue with me thats not gonna help any of us i dont have time to argue over bullshiot shit either help or go argue somewhere else
Pobiega
Pobiega•11mo ago
Well you have yet to actually say what you need help with
Eren
ErenOP•11mo ago
i need help with
Pobiega
Pobiega•11mo ago
Other than posting the entire PDF
Eren
ErenOP•11mo ago
making the functions so basically
Pobiega
Pobiega•11mo ago
What have you tried? Where are you stuck?
Eren
ErenOP•11mo ago
theres like 25 + functions i still have to make and im stuck at the 3.2 function which involves making the item selection i sent the file because it shows all of it Short description During the battle, the trainers must be able to use items. Implementation • Create a function that, based on a trainer, returns the index of the selected item • First the user is asked which item he or she wants to use "Trainer {trainer.Name}, what item would you like to use?" • Then print the item battle information from the trainer to the console • If the user does not enter a valid item index, throw an exception and catch it • Continue asking the user for a valid item index as long as they have not provided one this is what i need to do for the function
Pobiega
Pobiega•11mo ago
And what have you tried? You need to post your code
Eren
ErenOP•11mo ago
wait so if i need help with something i havent made yet u cant help?
Pobiega
Pobiega•11mo ago
How can you know you need help if you havn't even started? how can you be stuck before even trying?
Eren
ErenOP•11mo ago
i need help cuz i dont have enough time and dont understand everything well enough thats my issue i been working on this for so long aswell
Pobiega
Pobiega•11mo ago
Define exactly what kind of help you are looking for
Eren
ErenOP•11mo ago
putting so many hours into just this project someone who could help me get past the last 2 phases and help if i ask them a question when im trying so i dont get stuck on one part for 2-3 hrs like i did earlier
Pobiega
Pobiega•11mo ago
ask them a question when im trying
thats what you can use this thread for, no? I'm here. If you ask a question, I can answer it.
Eren
ErenOP•11mo ago
yeahi got a question cuz im stuck on one part atm idk if u mind reading this real quick Short description During the battle, the trainers must be able to choose between their Pokémon moves perform or use items yourself. Implementation • Create a function that, based on a trainer and a Pokémon, is the index of the chosen action gives back • First the user is asked what action he or she wants to perform "Trainer {trainer.Name}, what would you like to do?" "1) Do Move" "2) Use Item" • If the user does not enter a valid action index, throw an exception and catch it on • When the user enters action index 1 and all the moves of the Pokémon are the number times it can be executed equals 0, throw an exception, and catch it too • When the user enters action index 2 and the number of trainer items is 0, discard an exception and catch it • Keep asking the user for a valid action index as long as he or she has not provided one this is what i need to make next and i am stuck on the part of what i need to return
Pobiega
Pobiega•11mo ago
Well you have something like a game loop, that runs until one player wins right?
while(battle still going)
{
player 1 takes action
player 2 takes action
}
while(battle still going)
{
player 1 takes action
player 2 takes action
}
something like this
Eren
ErenOP•11mo ago
yeah but thats later i dont have that yet
Pobiega
Pobiega•11mo ago
okay. because
• Create a function that, based on a trainer and a Pokémon, is the index of the chosen action gives back
seems to be specifically about the player ordering their pokemon to do a move thats not relevant if the player instead picked to use an item
Eren
ErenOP•11mo ago
right so ill have to give in the trainer and pokemon then? and return the index ?
Pobiega
Pobiega•11mo ago
the function responsible for getting a pokemon move, sure but...
During the battle, the trainers must be able to choose between their Pokémon moves perform or use items yourself.
this text conflicts with that you need to know if the player wants to do a move or if they want to use an item first
Eren
ErenOP•11mo ago
yes but i think they will show me what the order is thats also in the later functions rn its mostly creating the fucntions to select them to be able to
Pobiega
Pobiega•11mo ago
but 3.1 and 3.2 are those parts
Eren
ErenOP•11mo ago
cuz rn i cant pick any actions
Pobiega
Pobiega•11mo ago
3.3 is the "do a move OR use an item" function
Eren
ErenOP•11mo ago
yes which r done but for the action yes true so i would need to use a if else assuming it asks for item or move
Pobiega
Pobiega•11mo ago
well you need to ask the user what they want to do and get the answer, then use either 3.1 or 3.2 to handle the choice
Eren
ErenOP•11mo ago
yeah okay makes sense
Eren
ErenOP•11mo ago
this is what ive got so far
No description
Pobiega
Pobiega•11mo ago
Okay
Eren
ErenOP•11mo ago
am i supposed to use one of the old functions in this one?
Pobiega
Pobiega•11mo ago
maybe later, but not yet
Eren
ErenOP•11mo ago
alright
Pobiega
Pobiega•11mo ago
you first need to know what the user wants to do
Eren
ErenOP•11mo ago
i gave it input aswell
Pobiega
Pobiega•11mo ago
you've printed instructions so far
Eren
ErenOP•11mo ago
so i added a string input = Console.Readline()
Pobiega
Pobiega•11mo ago
okay
Eren
ErenOP•11mo ago
now it says i need a exception would a try catch me block be usefull here or should i leave that out?
Pobiega
Pobiega•11mo ago
well, you need to check what the user wrote
Eren
ErenOP•11mo ago
if its out of the index bounds it will be invalid so the amount of moves/items u can select
Pobiega
Pobiega•11mo ago
sure, or if I wrote "cheesecake" thats not a valid choice in this setting
Eren
ErenOP•11mo ago
yeah for stuff like that alright what would be valid
Pobiega
Pobiega•11mo ago
cmon
Eren
ErenOP•11mo ago
maybe a if statment? statement
Pobiega
Pobiega•11mo ago
you could indeed solve this with if
Eren
ErenOP•11mo ago
something like this ?
No description
Pobiega
Pobiega•11mo ago
no you just want to know if they picked 1, or 2, or something else
Eren
ErenOP•11mo ago
so if index = 1 return index else throw new exception ?
Pobiega
Pobiega•11mo ago
well, thats not how I imagine it like, I don't think you should follow the first instruction here, since it seems at odds with the intent of the function it says to return the selected pokemon move index, but that makes no sense if the user selects to use an item oooh "action", not "move" yeah, it just wants 1 or 2
Eren
ErenOP•11mo ago
yeah
Pobiega
Pobiega•11mo ago
thats silly, but okay
Eren
ErenOP•11mo ago
so does this make sense
No description
Eren
ErenOP•11mo ago
i know but i gotta bear with it
Pobiega
Pobiega•11mo ago
almost the core idea is there, but you need a few adjustments
Eren
ErenOP•11mo ago
still need to return something right as in the numbers maybe are wrong ? or the code
Pobiega
Pobiega•11mo ago
• Keep asking the user for a valid action index as long as he or she has not provided one
so if the index wasnt 1 or 2, just keep going well what needs adjustment is the check for valid pokemon moves
Eren
ErenOP•11mo ago
so that console.writeline at the bottom needs to have something with it
Pobiega
Pobiega•11mo ago
that needs to go inside the while loop
Eren
ErenOP•11mo ago
done
Pobiega
Pobiega•11mo ago
actually, can you copypaste this entire function here?
Eren
ErenOP•11mo ago
is that all or is there more logic missing behind the cw ?
Pobiega
Pobiega•11mo ago
preferably in a $code block
MODiX
MODiX•11mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Eren
ErenOP•11mo ago
$codegif
Eren
ErenOP•11mo ago
yes
public int SelectAction(Trainer trainer , Pokémon pokémon)
{
int index = 0;

while (index == 0)
{
Console.WriteLine($"Trainer {trainer.Name} , what would you like to do?");
Console.WriteLine("1) Do Move");
Console.WriteLine("2) Use Item");

string input = Console.ReadLine();

if (int.TryParse(input, out index))
{
if(index == 1)
{
return index;
}
else
{
throw new Exception("No moves available for the pokemon");
}
}
else if (index == 2)
{
if (trainer.Item.Count > 0)
{
return index;
}
else
{
throw new Exception("No items available for the trainer");
}
}
Console.WriteLine("Invalid action index . Please try again");
}
}
public int SelectAction(Trainer trainer , Pokémon pokémon)
{
int index = 0;

while (index == 0)
{
Console.WriteLine($"Trainer {trainer.Name} , what would you like to do?");
Console.WriteLine("1) Do Move");
Console.WriteLine("2) Use Item");

string input = Console.ReadLine();

if (int.TryParse(input, out index))
{
if(index == 1)
{
return index;
}
else
{
throw new Exception("No moves available for the pokemon");
}
}
else if (index == 2)
{
if (trainer.Item.Count > 0)
{
return index;
}
else
{
throw new Exception("No items available for the trainer");
}
}
Console.WriteLine("Invalid action index . Please try again");
}
}
sorry was figuring out how to make it enter
Pobiega
Pobiega•11mo ago
so, to increase readability here I'd probably suggest you "invert" your ifs instead of checking if the value was valid, check for invalid
Eren
ErenOP•11mo ago
so i would have to change the values correct?
Pobiega
Pobiega•11mo ago
while (index == 0)
{
Console.WriteLine($"Trainer {trainer.Name} , what would you like to do?");
Console.WriteLine("1) Do Move");
Console.WriteLine("2) Use Item");

if (!int.TryParse(Console.ReadLine(), out index))
{
Console.WriteLine("Invalid action index . Please try again");
continue; // restart the while loop.
}

// we now know index was a number
while (index == 0)
{
Console.WriteLine($"Trainer {trainer.Name} , what would you like to do?");
Console.WriteLine("1) Do Move");
Console.WriteLine("2) Use Item");

if (!int.TryParse(Console.ReadLine(), out index))
{
Console.WriteLine("Invalid action index . Please try again");
continue; // restart the while loop.
}

// we now know index was a number
consider this snippet
Eren
ErenOP•11mo ago
hmm so thats basically more readable and shorter
Pobiega
Pobiega•11mo ago
I sure think so
Eren
ErenOP•11mo ago
and does the same thing
Pobiega
Pobiega•11mo ago
yup.
Eren
ErenOP•11mo ago
are u okay with me using that yes?
Pobiega
Pobiega•11mo ago
yes.
Eren
ErenOP•11mo ago
would i still have to use the code where it says item is unavailable and move is unavailble or do i scrap that too?
Pobiega
Pobiega•11mo ago
no you need those, according to the instructions
Eren
ErenOP•11mo ago
can i send u the code and show u if theres more adjustments needed
public int SelectAction(Trainer trainer , Pokémon pokémon)
{
int index = 0;

while (index == 0)
{
while (index == 0)
{
Console.WriteLine($"Trainer {trainer.Name} , what would you like to do?");
Console.WriteLine("1) Do Move");
Console.WriteLine("2) Use Item");

if (!int.TryParse(Console.ReadLine(), out index))
{
Console.WriteLine("Invalid action index . Please try again");
continue;
}
else if (index == 2)
{
if (trainer.Item.Count > 0)
{
return index;
}
else
{
throw new Exception("No items available for the trainer");
}
}
}
Console.WriteLine("Invalid action index . Please try again");
}
return index;
}
public int SelectAction(Trainer trainer , Pokémon pokémon)
{
int index = 0;

while (index == 0)
{
while (index == 0)
{
Console.WriteLine($"Trainer {trainer.Name} , what would you like to do?");
Console.WriteLine("1) Do Move");
Console.WriteLine("2) Use Item");

if (!int.TryParse(Console.ReadLine(), out index))
{
Console.WriteLine("Invalid action index . Please try again");
continue;
}
else if (index == 2)
{
if (trainer.Item.Count > 0)
{
return index;
}
else
{
throw new Exception("No items available for the trainer");
}
}
}
Console.WriteLine("Invalid action index . Please try again");
}
return index;
}
Pobiega
Pobiega•11mo ago
something aint right here two index loops?
Eren
ErenOP•11mo ago
i forgot to delete that removed it now sorry
Pobiega
Pobiega•11mo ago
also you don't handle index == 1 here
Eren
ErenOP•11mo ago
so while index = 1 then it does the part u send then else if index = 2
Pobiega
Pobiega•11mo ago
nah the part I sent is there to stop "cheesecake" it just handles the cases where the user entered a non-number you still need to check that the number was valid and do the right checks before returning the index
Eren
ErenOP•11mo ago
right so ill still need to add the part of the unavailble items / moves
Pobiega
Pobiega•11mo ago
well you had it for items btw, your trainers list of items is it really called Item? shouldn't it be Items?
Eren
ErenOP•11mo ago
they told me to call it item so idk i just do whats given
Pobiega
Pobiega•11mo ago
Een Trainer heeft: • Een naam • Een lijst van pokémon • Een lijst van items
Eren
ErenOP•11mo ago
its just so hard to do when they send u a random file and tell u to do what they want yes it has a list of items in the class
Pobiega
Pobiega•11mo ago
No description
Pobiega
Pobiega•11mo ago
that states the prop should be called Items
Eren
ErenOP•11mo ago
oh i wrote it wrong then
Pobiega
Pobiega•11mo ago
visual studio can rename it for you just click it and do refactor->rename and it will rename it everywhere
Eren
ErenOP•11mo ago
i just dit it manually everywhere hhaha didnt know that but thank u for finding that now back to the fucntion all i have is the part u send me i removed my bit cuz it confused me so now i need to make the part where it gives me the statement when a move or item is not available right?
Pobiega
Pobiega•11mo ago
well, after my snippet you know the user input was a number and that index now holds that number but thats all we know but I think you can fix the rest of the method from here, based on what you've previously shown
Eren
ErenOP•11mo ago
so all i need now is to throw the exception
Pobiega
Pobiega•11mo ago
I don't know, I can't see your code
Eren
ErenOP•11mo ago
when its got no more uses left?
Pobiega
Pobiega•11mo ago
but if all you have is my snippet, then... no?
Eren
ErenOP•11mo ago
yeah thats all i have at th moment it got confusing when i mixed it
Pobiega
Pobiega•11mo ago
think about it logically
Eren
ErenOP•11mo ago
i need the exception
Pobiega
Pobiega•11mo ago
// we now know input was a number, and index has the value
Eren
ErenOP•11mo ago
and to make it ask for the correct input until it gets given the right inpput
Pobiega
Pobiega•11mo ago
well you kinda already have that
Eren
ErenOP•11mo ago
a else statment throwing a exception and saying that it is unavailable/ ?
Pobiega
Pobiega•11mo ago
you shouldn't need else at all in this code tbh
Eren
ErenOP•11mo ago
so just use ifs then?
Pobiega
Pobiega•11mo ago
imho, yes but honestly, dont worry about it use else if you want
Eren
ErenOP•11mo ago
idk man im not that good at this stuff so i dont wanna not listen to you yk but
Pobiega
Pobiega•11mo ago
in fact, if you follow my every suggestion Im pretty sure your teacher will be able to tell you've had a lot of outside help 😛 see, when I write a method like this
Eren
ErenOP•11mo ago
no teacher is helping
Pobiega
Pobiega•11mo ago
I do it the way I write production code.
Eren
ErenOP•11mo ago
we have been given this in a file they didnt explain nothing its just a file sent to use to make and we just started seeing about the classes and stuff they kinda just gave us the whole pack after 2 weeks of lessons about classes
Pobiega
Pobiega•11mo ago
read what I wrote again. Im saying that my code style is different from yours visibly so meaning when your teacher reads the code to grade it or whatever, they will see how different this method is from the rest
Eren
ErenOP•11mo ago
yeah thats why ill just use the else statement now back to the function cuw i stilll havent found it i need to use a else if here or a if right and then check if there is more then 0 uses
Pobiega
Pobiega•11mo ago
something like that ye
Eren
ErenOP•11mo ago
so if move count = 0 cw No moves available ? idk im so confused idek what it is
Pobiega
Pobiega•11mo ago
what is confusing here? you've more or less written the correct code like 3 times over now
Eren
ErenOP•11mo ago
HAHHA have i ?? whats the part i need to still insert then of what ive wrote
Pobiega
Pobiega•11mo ago
well, with one or two minor things missing in each iteration 😄 show me what you have right now
Eren
ErenOP•11mo ago
alright with a creenshot or the code this ?
Pobiega
Pobiega•11mo ago
code here is almost always better unless you are trying to show an error
Eren
ErenOP•11mo ago
alright understood ill just do that from now on
public static int SelectAction(Trainer trainer , Pokémon pokémon)
{
int index = 0;

while (index == 0)
{
Console.WriteLine($"Trainer {trainer.Name} , what would you like to do?");
Console.WriteLine("1) Do Move");
Console.WriteLine("2) Use Item");

if (!int.TryParse(Console.ReadLine(), out index))
{
Console.WriteLine("Invalid action index . Please try again");
continue;
}
else if (index == 1)
{
if (pokémon.Moves.Count > 0)
{
Console.WriteLine("No moves available for the pokemon");
}
}


}
return index;
}
public static int SelectAction(Trainer trainer , Pokémon pokémon)
{
int index = 0;

while (index == 0)
{
Console.WriteLine($"Trainer {trainer.Name} , what would you like to do?");
Console.WriteLine("1) Do Move");
Console.WriteLine("2) Use Item");

if (!int.TryParse(Console.ReadLine(), out index))
{
Console.WriteLine("Invalid action index . Please try again");
continue;
}
else if (index == 1)
{
if (pokémon.Moves.Count > 0)
{
Console.WriteLine("No moves available for the pokemon");
}
}


}
return index;
}
cs
Pobiega
Pobiega•11mo ago
that.. uh.. you'll return 1 here regardless if the user has available moves or not and you are not handling the case of index == 2 at all also, your return index thing will make it so any number can be returned since your while loop only checks for == 0 I'd recommend you remove the number validation from the while loop tbh if the value is 1, check if there are any moves available, return 1 if the value is 2, check if items are available, return 2 if anything else, print "invalid choice" and restart the loop remember: an exception or a return statement immediately stops the execution of a method
Eren
ErenOP•11mo ago
alright let me try it so delete the return index then it gives me a error
Pobiega
Pobiega•11mo ago
yeah, because of your while loop if you fix that too, it won't your method MUST have a return value. One way of doing that is to never let the execution leave the while loop until it returns a valid value or throws an exception
Eren
ErenOP•11mo ago
sorry had dinner im back i still havent found it man
Pobiega
Pobiega•11mo ago
¯\_(ツ)_/¯ I get the feeling you are not familiar enough with the individual parts to be able to assemble them into the correct structure you correctly identified that you needed a while loop, console input, parsing, checking numbers, returning values, throwing exceptions etc so unless you've been chatgpting the code the entire time, you should be a few minutes away from this being done
Eren
ErenOP•11mo ago
im not using chat
Pobiega
Pobiega•11mo ago
good
Eren
ErenOP•11mo ago
because i have to explain this so if i use it i will be standing there with no idea whats going on
Pobiega
Pobiega•11mo ago
sure well, without giving you the answer directly Im not sure how much more I can do You have all the parts you just need to assemble them I'll give you one more hint: while(true) is better than while(index == 0) here.
Eren
ErenOP•11mo ago
alright let me have a look properly and see what i can do been making this for so long taking me so much time probably why im so confused rn cuz ive been sat here for more then a week doing this
Pobiega
Pobiega•11mo ago
bashing your head against a wall for a week is not a good idea, as you've noticed 😛 once you stop making progress, its best to ask for help asap
Eren
ErenOP•11mo ago
yeah i genuinely been losing it i know its part of it but this is alot for me personally i didnt solve it yet btw but im jsut gonna make the ones i understand already cuz me sitting there waiting isnt bringing me forward
Pobiega
Pobiega•11mo ago
What must you do if the user chose to do a pokemon move? What must you do if the user chose to use an item?
Eren
ErenOP•11mo ago
-1 i solved it btw ty for the help
Want results from more Discord servers?
Add your server