Tactics Sharp – Character Design

Just spent around 45 minutes playing around with some code.  Here is what I came up with, Bit Diddler would be proud.

This game is going to be a basic tactics game.  So far I only outlined the character class.

using System;
using System.Collections.Generic;

namespace Tactics_Sharp {

    [Flags]
    public enum State {
        Normal = 0x0, //------------------//
        Death = 0x1, // Using bit flags -//
        OnFire = 0x2, //------------------//
        Frozen = 0x4,
        Zapped = 0x8,
        Asleep = 0x10,
        Confused = 0x20,
        Frenzied = 0x40
    }

    [Flags]
    public enum CharClass {
        Squire = 0x0, //------------------//
        Knight = 0x1, // Using bit flags -//
        Monk = 0x2, //------------------//
        Mage = 0x4,
        Archer = 0x8,
        Theif = 0x10
    }

class Character {
    private string _name; // Character's Name; i.e. { "Bit Diddler" }
    private Int32 _id; // Character's ID number; i.e. { 10 }
    //private List _attrs; // Character's Attributes; i.e { str, int, def, spd, mov }
    //private List _stats; // Character's Stats; i.e { HP, MP, LVL }
    private CharClass _class; // Character's Class; i.e "Squire" || "Squire" + "Knight"
    //private State _state; // Character's Current State

    // Will make a Lvl 1 Squire
    public Character(string _name, Int32 _id) {
        this._name = _name; // Lazy coding . . .
        this._id = _id;
        this._class = CharClass.Squire;
    }

    // Using bitwise OR to add multiple classes
    public void promote(string charClass) {
        // Quick & Ugly hack
        if (charClass.Equals("Knight"))
            this._class = this._class | CharClass.Knight;
        else if (charClass.Equals("Monk"))
            this._class = this._class | CharClass.Monk;
        else if (charClass.Equals("Mage"))
            this._class = this._class | CharClass.Mage;
        else if (charClass.Equals("Archer"))
            this._class = this._class | CharClass.Archer;
        else if (charClass.Equals("Theif"))
            this._class = this._class | CharClass.Theif;
     }

    public void demote(string charClass) {
        // Quick & Ugly hack
        if (charClass.Equals("Knight") && CharClass.Knight == ( this._class & CharClass.Knight ) )
            this._class = this._class ^ CharClass.Knight;
        else if (charClass.Equals("Monk") && CharClass.Monk == (this._class & CharClass.Monk))
            this._class = this._class ^ CharClass.Monk;
        else if (charClass.Equals("Mage") && CharClass.Mage == (this._class & CharClass.Mage))
            this._class = this._class ^ CharClass.Mage;
        else if (charClass.Equals("Archer") && CharClass.Archer == (this._class & CharClass.Archer))
            this._class = this._class ^ CharClass.Archer;
        else if (charClass.Equals("Theif") && CharClass.Theif == (this._class & CharClass.Theif))
            this._class = this._class ^ CharClass.Theif;
    }
    public void printClass(){ Console.WriteLine("{0}", this._class ); }
    }
}

Test Code


using System;

namespace Tactics_Sharp {

class Run {
    static void Main(string[] args) {
        Character BitDiddler = new Character("Bit Diddler", 10);
        BitDiddler.printClass();
        BitDiddler.promote("Knight");
        BitDiddler.printClass();

        BitDiddler.promote("Monk");
        BitDiddler.printClass();

        BitDiddler.promote("Mage");
        BitDiddler.printClass();

        BitDiddler.promote("Archer");
        BitDiddler.printClass();

        BitDiddler.promote("Theif");
        BitDiddler.printClass();

        BitDiddler.promote("God"); // God Mode isn't supported,
        BitDiddler.printClass();   // Besides, Bit Diddler is already the man.

        BitDiddler.demote("Knight");
        BitDiddler.printClass();

        BitDiddler.promote("Knight"); // Adding back Knight just because.
        BitDiddler.printClass();

        Console.ReadLine();
        }
    }
}

Sample Output:

Squire
Knight
Knight, Monk
Knight, Monk, Mage
Knight, Monk, Mage, Archer
Knight, Monk, Mage, Archer, Theif
Knight, Monk, Mage, Archer, Theif
Monk, Mage, Archer, Theif
Knight, Monk, Mage, Archer, Theif

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