Tactics Sharp – Game Board Design

I quickly design the game board, here is what I got so far.

Additional, this article might be helpful.
http://msdn.microsoft.com/en-us/magazine/cc163995.aspx

using System;
using System.Collections.Generic;

namespace Tactics_Sharp
{
    public enum Terrain 
    {
        grass,
        stone,
        dirt,
        wood
    }
    class Square
    {
        private Character _ch;
        private Terrain _tr;

        public Square(Character _ch, string _tr)
        {
            // Quick && Ugly Hack
            this._ch = _ch;
            if (_tr.Equals("grass"))
                this._tr = Terrain.grass;
            else if (_tr.Equals("stone"))
                this._tr = Terrain.stone;
            else if (_tr.Equals("dirt"))
                this._tr = Terrain.dirt;
            else if (_tr.Equals("wood"))
                this._tr = Terrain.wood;
        }

        public Square(string _tr) 
        {
            // Quick && Ugly Hack
            this._ch = null;
            if (_tr.Equals("grass"))
                this._tr = Terrain.grass;
            else if (_tr.Equals("stone"))
                this._tr = Terrain.stone;
            else if (_tr.Equals("dirt"))
                this._tr = Terrain.dirt;
            else if (_tr.Equals("wood"))
                this._tr = Terrain.wood;
        }

        public Square()
        {
            this._ch = null;
        }

        public Character getChar() { return (this._ch); }
    }
    class Grid
    {
        private Int32 MAX_ROW;
        private Int32 MAX_COL;

        private Square[] _board;

        public Grid(Int32 MAX_ROW, Int32 MAX_COL) 
        {
            this.MAX_ROW = MAX_ROW;
            this.MAX_COL = MAX_COL;
            this._board = new Square[MAX_ROW * MAX_COL];
        }

        public Square get(Int32 row, Int32 col)
        {
            return ( this._board[row * MAX_COL + col] );
        }

        public void set(Int32 row, Int32 col, Character _ch, string _tr)
        {
            this._board[row * MAX_COL + col] = new Square(_ch, _tr);
        }

        //Debug class
        public void print(Int32 row, Int32 col)
        {
            this._board[row * MAX_COL + col].getChar().printClass();
        }
    }
}

Test Class

using System;

namespace Tactics_Sharp
{
    class Run
    {
        static void Main(string[] args)
        {
            Character BitDiddler = new Character("Bit Diddler", 10);            
            BitDiddler.promote("Knight");
            BitDiddler.promote("Monk");
            BitDiddler.promote("Mage");
            BitDiddler.promote("Archer");
            BitDiddler.promote("Theif");
    
            //
            Grid gameBoard = new Grid(10, 10);
            gameBoard.set(1, 1, BitDiddler, "grass");
            gameBoard.print(1,1);
            Console.ReadLine();
        }
    }
}

Sample Output:

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