Previous attempt is just to change the size and style of font on console not change its color. The text color can be changed with following script
Console.ForegroundColor = ConsoleColor.Yellow; // assign the color to the `Text`
Console.BackgroundColor = ConsoleColor.White; // assign the background color of the `Text`
Console.WriteLine("Text");
Console.ResetColor(); // if you do not write this, the whole text and its BG changed to the `Text` color(Yellow) and BG(white).
Reminding the concept of the game, the matryoshka, I aims to add some component to the Item
class by applying the bit calculator.
public class Item
{
... // private variables for other feature
// the value should be set to binary for bit calculation
int fHierachy; // the level which represent the size of item
ItemType fType; // to distinguish the weapon, armor, else
int fRank; // the rarity of item (Normal,Rare,Unique,Legend)
... // Functions to `Get`, `Set` the variables
}
public enum ItemType
{
None, Weapon, Armor, Ring
}
Bringing these updates, the Player.cs
have to be modifed to get and set the hierachy and rank
public class Player
{
... // variables for other feature
int fWeaponLvl;
int fArmorLvl;
int fRingLvl;
... // Functions
public Player(/*arguments*/)
{
... // initialization
foreach(var item in list_items)
{
if(item.GetType() == ItemType.Weapon && (fWeaponLvl & item.GetHierachy() != 0)
fWeaponLvl += item.GetHierachy();
if(item.GetType() == ItemType.Armor && (fArmorLvl & item.GetHierachy() != 0)
fArmorLvl += item.GetHierachy();
if(item.GetType() == ItemType.Ring && (fRingLvl & item.GetHierachy() != 0)
fRingLvl += item.GetHierachy();
}
}
public void Equip(int idx) // For the `UnEquip()` the operator `+=` should be changed to `-=`
{
ItemType type = list_items[idx].GetItemType();
switch(type)
{
case ItemType.Weapon:
fWeaponLvl += list_items[idx].GetHierachy();
break;
case ItemType.Armor:
fArmorLvl += list_items[idx].GetHierachy();
break;
case ItemType.Ring:
fRingLvl += list_items[idx].GetHierachy();
break;
}
}
}
To make the character similar to matryoshka, the player cannot access the inner size item when the bigger size item was equipped. These feature can be made by bit calculation.
public class Scene
{
... // scripts before equip/unequip session
if(...)
...
else if ((Player.instance.GetHierachyLvl(ItemType.Weapon) >> (ToMaxBit(item.GetHierachy())) != 0)
// imagine the player have weapon (4 for its hierachy)
// when the player try to equip weapon that have smaller or same size(2,8),
// the left term of bit calculation can be expressed like ( 4>>((1),(3)) =1(cannot equip),0(can equip))
{
Console.WriteLine("Cannot equip due to the size");
}
...
else if()
Player.instance.Equip(idx);
else if()
Player.instance.UnEquip(idx);
int ToMaxBit(int a)
{
... // find the maximum number of bit
}
}
Keep:
Problem:
Try: