C# Game Set Bonuses

Started by
30 comments, last by raidzero 12 years, 9 months ago
The problem now is that converting that plan into code. I'm editing and replacing code all over the place so I decide to start a new project and deal with the most necessary code I need.
Idea seems simple, but man...proved to be harder than I thought. I've been trying for the past hour and I lost in all this code..pretty much at my limit for today.

Is it better to just have an enum Items or separate all items into categories like I had above?

Removed a bunch of code and errors all over the place for now..Should I have enum Items in my hero class or should it be in a separate class and have my hero class use it when it's needed?
using System;
using System.Collections.Generic;

namespace TextBasedGame
{
public enum Item
{
DevBeanie,
DevShirt,
DevPants,
DevShoes,
DevMittens,
DevCloak,
DevPendant,
DevRing,
DevSword,
PandaBeanie,
PandaShield
}

public enum ItemType
{
DevBeanie,
DevShirt,
DevPants,
DevShoes,
DevMittens,
DevCloak,
DevPendant,
DevRing,
DevSword,
PandaBeanie,
PandaShield
}

abstract class Item
{
public int Cost { get; protected set; }
public ItemType Item { get; protected set; }

public Item(int cost, ItemType type)
{
Cost = cost;
Item = type;
}
}
}

using System;
using System.Collections.Generic;

namespace TextBasedGame
{
public class Hero : Character
{
public List<Items> items;

public Hero()
{
items = new List<Items>();
}
public static void Initialize(Hero hero)
{
hero.Level = 1;
hero.CurrentHealth = 100;
hero.MaxHealth = 100;
hero.CurrentMagic = 20;
hero.MaxMagic = 20;
hero.baseStrength = 10;
hero.bonusStrength = 0;
hero.baseDefense = 5;
hero.bonusDefense = 0;
hero.bonusDamage = 0;
hero.Exp = 0;
hero.Gold = 0;
hero.isAlive = true;
}

public bool CheckItems(Items hasThisItem, Hero hero)
{
return hero.items.Contains(hasThisItem);
}

public static void CheckLevel(Hero hero)
{
if (hero.Exp >= 0 && hero.Exp < 50)
{
hero.Level = 1;
}
else if (hero.Exp >= 50 && hero.Exp < 250)
{
hero.Level = 2;
}
else if (hero.Exp >= 250 && hero.Exp < 2500)
{
hero.Level = 3;
}
else if (hero.Exp >= 2500 && hero.Exp < 10000)
{
hero.Level = 4;
}
else if (hero.Exp >= 10000)
{
hero.Level = 5;
}
}

public static void CheckAll(Hero hero)
{
hero.MaxHealth = 100;
hero.MaxMagic = 20;
hero.bonusStrength = 0;
hero.bonusDamage = 0;
hero.bonusDefense = 0;
Hero.CheckLevel(hero);
Hero.CheckEquips(hero);
Hero.CheckSet(hero);
hero.Strength = hero.baseStrength + hero.bonusStrength;
hero.Defense = hero.baseDefense + hero.bonusDefense;
hero.PhysicalDamage = (hero.Strength * 3) + hero.bonusDamage;
if (hero.CurrentHealth > hero.MaxHealth)
{
hero.CurrentHealth = hero.MaxHealth;
}
if (hero.CurrentMagic > hero.MaxMagic)
{
hero.CurrentMagic = hero.MaxMagic;
}
}

public static void CheckEquips(Hero hero)
{

}

public static void CheckSet(Hero hero)
{

}
}
}



Gonna finish up my hero class then get working on Store.
using System;
using System.Collections.Generic;

namespace TextBasedGame
{
public class Store
{
string choice = "";
public Store(Hero hero)
{
while (hero.Id == null || hero.Id == "" || hero.Id == " ")
{
Console.Clear();
Console.WriteLine("Choose a name for your hero.");
hero.Id = Console.ReadLine();
}
StoreLoop(hero);
}

public void StoreLoop(Hero hero)
{
do
{
Console.Clear();
Console.WriteLine("Welcome to the store");
Console.WriteLine("How can I help you?");
Console.Write(@"
_______________________________
Buy:
Sell:

Leave:
_______________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "Buy":
case "buy":
BuyLoop(hero);
break;
case "Sell":
case "sell":
SellLoop(hero);
break;
case "Leave":
case "leave":
Hero.CheckAll(hero);
Console.Clear();
Console.WriteLine("Best of luck out there");
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
while (choice != "Leave" && choice != "leave");
Console.ReadLine();
}

void BuyLoop(Hero hero)
{
while (choice != "Back" && choice != "back")
{
Console.Clear();
Console.WriteLine("Choose a category");
Console.Write(@"
________________________________
Headgear:
Top:
Bottom:
Shoes:
Gloves:
Mantle:
Pendant:
Ring:

Primary:
Secondary:

Back:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "Headgear":
case "headgear":
BuyHeadgear(hero);
break;
case "Top":
case "top":
BuyTop(hero);
break;
case "Bottom":
case "bottom":
BuyBottom(hero);
break;
case "Shoes":
case "shoes":
BuyShoes(hero);
break;
case "Gloves":
case "gloves":
BuyGloves(hero);
break;
case "Primary":
case "primary":
BuyPrimary(hero);
break;
case "Secondary":
case "secondary":
BuySecondary(hero);
break;
case "Mantle":
case "mantle":
BuyMantle(hero);
break;
case "Pendant":
case "pendant":
BuyPendant(hero);
break;
case "Ring":
case "ring":
BuyRing(hero);
break;
case "Back":
case "back":
break;
default:
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyHeadgear(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevBeanie: 1 gold +99 Defense
PandaBeanie: 1 gold +10 Defense

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevBeanie":
case "devbeanie":
if (hero.CheckItems(DevBeanie) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devbeanie);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a headgear");
Console.ReadLine();
}
break;
case "PandaBeanie":
case "pandabeanie":
if (hero.CheckItems(PandaBeanie) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(pandabeanie);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a headgear");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyTop(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevShirt: 1 gold +99 Defense

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevShirt":
case "devshirt":
if (hero.CheckItems(DevShirt) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devshirt);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a top");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyBottom(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevPants: 1 gold +99 Defense

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevPants":
case "devpants":
if (hero.CheckItems(DevPants) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devpants);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a bottom");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyShoes(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevShoes: 1 gold +99 Defense

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevShoes":
case "devshoes":
if (hero.CheckItems(DevShoes) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devshoes);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have shoes");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyGloves(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevMittens: 1 gold +99 Defense

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevMittens":
case "devmittens":
if (hero.CheckItems(DevMittens) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devmittens);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have gloves");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyMantle(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevCloak: 1 gold +99 Defense

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevCloak":
case "devcloak":
if (hero.CheckItems(DevCloak) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devcloak);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a mantle");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyPendant(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevPendant: 1 gold +99 Max Health +99 Max Magic

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevPendant":
case "devpendant":
if (hero.CheckItems(DevPendant) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devpendant);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a pendant");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyRing(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevRing: 1 gold +99 Max Health +99 Max Magic

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevRing":
case "devring":
if (hero.CheckItems(DevRing) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devring);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a ring");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuyPrimary(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
DevSword: 1 gold +99 Attack

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevSword":
case "devsword":
if (hero.CheckItems(DevSword) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(devsword);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a sword");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void BuySecondary(Hero hero)
{
while (choice != "Return" && choice != "return")
{
Console.Clear();
Console.WriteLine("What would you like to buy?");
Console.Write(@"
________________________________
PandaShield: 1 gold +10 Defense

Return:
________________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "PandaShield":
case "pandashield":
if (hero.CheckItems(PandaShield) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(pandashield);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a shield");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}

void SellLoop(Hero hero)
{
while (choice != "Return" && choice != "return")
{
bool checkitem = false;
Console.Clear();
Console.WriteLine("What would you like to sell?");
Console.WriteLine("____________________________");
foreach (string item in hero.items)
{
Console.WriteLine(item);
}
Console.WriteLine("Return:");
Console.WriteLine("____________________________");
Console.WriteLine();
choice = Console.ReadLine();
switch (choice)
{
case "DevBeanie":
case "devbeanie":
if (hero.CheckItems(DevBeanie) == true)
{
hero.Gold += 1;
hero.items.Remove(devbeanie);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "DevShirt":
case "devshirt":
if (hero.CheckItems(DevShirt) == true)
{
hero.Gold += 1;
hero.items.Remove(devshirt);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "DevPants":
case "devpants":
if (hero.CheckItems(DevPants) == true)
{
hero.Gold += 1;
hero.items.Remove(devpants);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "DevShoes":
case "devshoes":
if (hero.CheckItems(DevShoes) == true)
{
hero.Gold += 1;
hero.items.Remove(devshoes);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "DevMittens":
case "devmittens":
if (hero.CheckItems(DevMittens) == true)
{
hero.Gold += 1;
hero.items.Remove(devmittens);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "Devcloak":
case "devcloak":
if (hero.CheckItems(DevCloak) == true)
{
hero.Gold += 1;
hero.items.Remove(devcloak);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "DevPendant":
case "devpendant":
if (hero.CheckItems(DevPendant) == true)
{
hero.Gold += 1;
hero.items.Remove(devpendant);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "DevRing":
case "devring":
if (hero.CheckItems(DevRing) == true)
{
hero.Gold += 1;
hero.items.Remove(devring);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "DevSword":
case "devsword":
if (hero.CheckItems(DevSword) == true)
{
hero.Gold += 1;
hero.items.Remove(devsword);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "PandaBeanie":
case "pandabeanie":
if (hero.CheckItems(PandaBeanie) == true)
{
hero.Gold += 1;
hero.items.Remove(pandabeanie);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "PandaShield":
case "pandashield":
if (hero.CheckItems(PandaShield) == true)
{
hero.Gold += 1;
hero.items.Remove(pandashield);
Console.WriteLine("Thank you, anything else you want to sell?");
Console.ReadLine();
}
else
{
Console.WriteLine("You do not own one");
Console.ReadLine();
}
break;
case "Return":
case "return":
break;
default:
Console.Clear();
Console.WriteLine("How can I help you?");
Console.ReadLine();
break;
}
}
}
}
}
Advertisement
Alright, so I fixed up my Hero.cs and there seems to be no error. Now I just need to work on Store.cs, but how do I call on my Item class so all the items exist in current context?
Finally figured it out. That seemed like one big obstacle.
What I want to do now is figure out if I can define values like Cost, Type, bonuses, etc inside a x.cs and have it used in my store..not sure if that all made sense.

But like here's my ItemInfo.cs that my items inherit from.
using System;
using System.Collections.Generic;

namespace TextBasedGame
{
public enum Items
{
DevBeanie
}

public enum ItemType
{
Headgear
}

abstract class ItemInfo
{
protected ItemInfo(int cost, ItemType type)
{
Cost = cost;
Item = type;
}
public int Cost { get; protected set; }
public ItemType Item { get; protected set; }
}
}


Then have my actual item class
using System;
using System.Collections.Generic;

namespace TextBasedGame
{
class DevBeanie : ItemInfo
{
public DevBeanie()
: base(1, ItemType.Headgear)
{

}
}
}


Would it be possible to add things in like hero.bonusDefense +=10; and have it take away money?
Right now my shop is set up to check for the item then take away the gold.
case "DevBeanie":
case "devbeanie":
if (hero.items.Contains(Items.DevBeanie) == false)
{
if (hero.Gold >= 1)
{
hero.Gold -= 1;
hero.items.Add(Items.DevBeanie);
Console.WriteLine("Thank you, anything else you want?");
Console.ReadLine();
}
else
{
Console.WriteLine("You currently have {0} gold, how do you expect to pay me?", hero.Gold);
Console.ReadLine();
}
}
else
{
Console.WriteLine("You already have a headgear");
Console.ReadLine();
}
break;

This topic is closed to new replies.

Advertisement