private void SetCombatants() { //Session storge typically uses string keys for accessing variables. //Another option in web forms is called ViewState //Look up the difference between ViewState and Session, and let me know //You need to cast them (tell the compiler what type they will be) in order to assign them to your variables. //Session is typically lazy programming, and this is for educational purposes only if (Session["_hero"] == null) { Session["_hero"] = new Hero() { Name = "Jimi Hendrix", AttackPoints = 5, DefensePoints = 5, HitPoints = 50, CombatLevel = 1, DeathCount = 0, KillCount = 0, }; } //Notice that there are no curly braces for this if statement //If there is only a single line for an if statement, they are not necessary //this cleans up the code base a bit by reducing number of lines if (Session["_enemy"] == null) Session["_enemy"] = new Dwarf(); hero = (Hero)Session["_hero"]; dwarf = (Dwarf)Session["_enemy"]; }
protected void NewEnemy(object sender, EventArgs e) { Session["_enemy"] = new Dwarf(); dwarf = (Dwarf)Session["_enemy"]; SetLabels(); }