c# - Add a second command that calls another method? -
i'm remaking text-based adventure game. during character creation, i'd user, @ time, type 'skillset' , list traits specific race has. i've tried couple hours , can't seem figure out.
this character creation class.
public string usercommand_seachskill; skillset searchskill = new skillset(); public void create_character() { // choose gender // { validate = 0; console.clear(); console.write("are male or female? (f/m): "); sex = console.readline().toupper(); if (sex == "m" || sex == "f") { validate = 1; } else if (sex != "m" || sex != "f") { console.writeline("you must enter 'm' or 'f'"); } } while (validate == 0);
and skill set class. in if/else statements methods print traits of race console. let me know if there else can add better ask question. thank in advance! :)
classattributes classes = new classattributes(); character character = new character(); skillset = console.readline().toupper(); { validate = 0; if (skillset == "human") { classes.skillsethuman(); } else if (skillset == "orc") { classes.skillsetorc(); } else if (skillset == "elf") { classes.skillsetelf(); } else if (skillset == "exit") { validate = 1; character.create_character(); } } while (validate == 0);
i think you're looking event. c# console applications seem have 1 kind of event, fires when ctrl+c or ctrl+break happens. handle skillset input/output logic in function handler
you can read more here: https://msdn.microsoft.com/library/system.console.cancelkeypress(v=vs.110).aspx
if need word typed, capture typed in special function, instead of using regular console.readline(). this:
public static string customreadline() { consolekeyinfo cki; string capturedinput = ""; while (true) { cki = console.readkey(true); if (cki.key == consolekey.enter) break; else if (cki.key == consolekey.spacebar) { capturedinput += " "; console.write(" "); } else if (cki.key == consolekey.backspace) { capturedinput = capturedinput.remove(capturedinput.length - 1); console.clear(); console.write(capturedinput); } else { capturedinput += cki.keychar; console.write(cki.keychar); } if (capturedinput.toupper().contains("skillset")) { capturedinput = ""; skillsettyped(); return ""; } } return capturedinput; }
then inside create_character, do
... { console.write("are male or female? (f/m): "); sex = customreadline(); } while (string.isnullorempty(sex));
and finally, handle skillset logic here
protected static void skillsettyped() { console.write("\nwrite skillset capture/display logic here\n"); }
this draft , has minor bugs, believe it's close want.
Comments
Post a Comment