Tactics Sharp – Character Design Update

Still haven’t figured out how to get dictionary iteration working smoothly yet but here is the source code. I added back the character classes and state enums. I’m skipping the dictionary issues for now and moving on. Next I’m either going back to the grid to track and move around the characters or start working out attacking events. Also I’ll try to throw in a lambda function where I can.

Here is the a sample of my character class:

using System;
using System.Collections.Generic;

namespace Tactics_Sharp {
    internal class Character : IComparable {

        [Flags] //-State of character.
        public enum CharState {
            Normal = 0x0,
            Death = 0x1,
            Asleep = 0x2,
            Burn = 0x4,
            Frozen = 0x8,
            Paralyze = 0x10,
            Poison = 0x20,
            Confuse = 0x40
        }

        // - Character's Vitals && Skills
        private Dictionary<String, Int32> _skills;
        private Dictionary<String, Int32> _vitals;
        private CharState _state;

        public Character() {
            this._state = CharState.Normal;
            this._skills = new Dictionary<String, Int32>() { 
                { "Punch", 0 }, { "Weapon", 0 }, { "Evade", 0}, { "Steal", 0 }, 
                { "Block", 0 }, { "Fire", 0 }, { "Lighting", 0 }, { "Heal", 0 },  
                { "Bite", 0 }, { "Claw", 0 } };
            this._vitals = new Dictionary<String, Int32>() { { "HP", 0 }, { "MP", 0 }, { "LVL", 0 } };

        }

        // - Virtual Derived Classes
        public virtual Int32 CompareTo(Object _obj) { return this.CompareTo(_obj); }
        public virtual Dictionary<String, Int32> getVitals() { return this._vitals; }
        public virtual Dictionary<String, Int32> getSkills() { return this._skills; }
        public virtual void incrementSkill(String key) { this._skills[key]++; }
        public virtual void incrementVitals(String key) { this._vitals[key]++; }
        public virtual Int32 indexSkill(String key) { return this._skills[key]; }
        public virtual Int32 indexVital(String key) { return this._vitals[key]; }
        public virtual void setSkill(String key, Int32 val) {
            if (val >= 0 && val <= 100)
                this._skills[key] = val;
        }
        public virtual void setVital(String key, Int32 val) {
            if (val >= 0)
                this._vitals[key] = val;
        }
        public virtual CharState getState() { return this._state; }
        public virtual void setState(CharState _state) {
            if (_state != (this._state & _state))  // - Checks if class is deactive  
                this._state = this._state | _state;  // - Adds state
        }
        public virtual void removeState(CharState _state) {
            if (_state == (this._state & _state))   // - Checks if class is active
                this._state = this._state ^ _state; // - Removes state
        }

        // Human Character Class
        internal sealed class Human : Character, IComparable {
            [Flags]
            public enum CharClass {
                Squire = 0x0,
                Knight = 0x1,
                Monk = 0x2,
                Mage = 0x4,
                Archer = 0x8,
                Theif = 0x10
            }

            public String _name;
            public CharClass _class;
            public Human(String _name) {
                this._name = _name;
                this._class = new CharClass();
            }

            // Locals Functions
            public void promote(CharClass _class) {
                if (_class != (this._class & _class))    // - Checks if class is deactive 
                    this._class = this._class | _class;  // - Adds class
            }
            public void demote(CharClass _class) {
                if (_class == (this._class & _class))   // - Checks if class is active
                    this._class = this._class ^ _class; // - Removes class
            }

            // Base Class Functions
            public override Int32 CompareTo(Object _obj) { return base.CompareTo(_obj); }
            public override Dictionary<String, Int32> getSkills() { return base.getSkills(); }
            public override Dictionary<String, Int32> getVitals() { return base.getVitals(); }
            public override void incrementSkill(String key) { base.incrementSkill(key); }
            public override void incrementVitals(String key) { base.incrementVitals(key); }
            public override Int32 indexSkill(String key) { return base.indexSkill(key); }
            public override Int32 indexVital(String key) { return base.indexVital(key); }
            public override void setSkill(String key, Int32 val) { base.setSkill(key, val); }
            public override void setVital(String key, Int32 val) { base.setVital(key, val); }
        }

        // Dragon Character Class
        internal sealed class Dragon : Character, IComparable {
            [Flags]
            public enum CharClass {
                Packrat = 0x0,
                ANTLR = 0x1,
                PLY = 0x2,
                SWIG= 0x4,
            }
            public String _name;
            public CharClass _class;

            public Dragon(String _name) {
                this._name = _name;
                this._class = new CharClass();
            }

            // Locals Functions
            public void promote(CharClass _class) {
                if (_class != (this._class & _class))    // - Checks if class is deactive 
                    this._class = this._class | _class;  // - Adds class
            }
            public void demote(CharClass _class) {
                if (_class == (this._class & _class))   // - Checks if class is active
                    this._class = this._class ^ _class; // - Removes class
            }

            // Base Class Functions
            public override Int32 CompareTo(Object _obj) { return base.CompareTo(_obj); }
            public override Dictionary<String, Int32> getSkills() { return base.getSkills(); }
            public override Dictionary<String, Int32> getVitals() { return base.getVitals(); }
            public override void incrementSkill(String key) { base.incrementSkill(key); }
            public override void incrementVitals(String key) { base.incrementVitals(key); }
            public override Int32 indexSkill(String key) { return base.indexSkill(key); }
            public override Int32 indexVital(String key) { return base.indexVital(key); }
            public override void setSkill(String key, Int32 val) { base.setSkill(key, val); }
            public override void setVital(String key, Int32 val) { base.setVital(key, val); }
        }

        class Program {
            static void Main(string[] args) {
                // Character Objects
                Human BitDiddler = new Human("Bit Diddler");
                Dragon Aho = new Dragon("Aho");

                // Character Objects Locals
                BitDiddler.promote(Human.CharClass.Knight);
                Aho.promote(Dragon.CharClass.LexicalAnalyser);

                // Character Base State
                Aho.setState(CharState.Asleep);

                // - BitDiddler is a master of iteration, But I'm not . . . 
                //foreach (String skill in BitDiddler.getSkills().Keys)
                //    BitDiddler.setSkill(skill, 10);  
                //    BitDiddler.incrementSkill(skill);
                //foreach (String vital in BitDiddler.getVitals().Keys)
                //    BitDiddler.setVital(vital, 100);

                // - This is fine, Dragons are dumb anyway.
                Aho.setSkill("Fire", 5);
                Aho.setSkill("Claw", 5);
                Aho.setSkill("Bite", 5);
                Aho.setVital("HP", 300);
                Aho.setVital("MP", 150);
                Aho.setVital("LVL", 50);

                // - Test Block
                Console.WriteLine(BitDiddler._name + " vs " + Aho._name);
                Console.WriteLine(">>>>>---------------------------<<<<<");
                Console.WriteLine(BitDiddler._name + "'s Pre-Fight Stats:");
                Console.WriteLine("Class: " + BitDiddler._class);
                Console.WriteLine("State: " + BitDiddler.getState());
                Console.Write("Vitals:");
                foreach (var vital in BitDiddler.getVitals())
                    if (vital.Value > 0)
                        Console.Write(" " + vital.Key + ": " + vital.Value);
                Console.WriteLine();
                Console.Write("Skills:");
                foreach (var skill in BitDiddler.getSkills())
                    if (skill.Value > 0)
                        Console.Write(" " + skill.Key + ": " + skill.Value);
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(Aho._name + "'s Pre-Fight Stats:");
                Console.WriteLine("Class: " + Aho._class);
                Console.WriteLine("State: " + Aho.getState());
                Console.Write("Vitals:");
                foreach (var vital in Aho.getVitals())
                    if (vital.Value > 0)
                        Console.Write(" " + vital.Key + ": " + vital.Value);
                Console.WriteLine();
                Console.Write("Skills:");
                foreach (var skill in Aho.getSkills())
                    if (skill.Value > 0)
                        Console.Write(" " + skill.Key + ": " + skill.Value);
                Console.WriteLine();
                Console.ReadLine();
            }
        }
    }
}

Sample Output:

Bit Diddler vs Aho
>>>>>—————————<<<<<
Bit Diddler's Pre-Fight Stats:
Class: Knight
State: Normal
Vitals:
Skills:

Aho's Pre-Fight Stats:
Class: LexicalAnalyser
State: Asleep
Vitals: HP: 300 MP: 150 LVL: 50
Skills: Fire: 5 Bite: 5 Claw: 5

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s