Archive

Posts Tagged ‘C#’

INVADERZ – My First XNA Game

December 1, 2009 azer89 Leave a comment

xna_logo

Game Title : INVADERZ

Genre : Shoot ‘em up

Type : Game 3D

Framework : XNA Game Studio 3.1

Tool :

-    Visual Studio 2008 Professional SP 1
-    SpriteFont 1.2


DOWNLOAD HERE

 

Judul Game     : INVADERZ

Genre              : Shoot ‘em up

Jenis                : Game 3D

Framework      : XNA Game Studio 3.1

Tool                 :

- Visual Studio 2008 Professional SP 1

SpriteFont 1.2

Categories: C#, Game Programming, Programming, XNA Tags: , , ,

Problem Longest Common Subsequence dengan Tiga Sekuen

December 1, 2009 azer89 Leave a comment

Problem yang pertama adalah mengenai longest common subsequence dengan menggunakan tiga sekuen. Algoritma ini memiliki tujuan untuk mendapatkan subsekuen yang sama secara berurutan dan tentunya yang paling panjang dari ketiga subsekuen.

Contoh :

Sekuen Pertama : SURABAYA
Sekuen Kedua : SURAKARTA
Sekuen Ketiga : PASURUAN
Hasil : SURA

Algoritma

Algoritma solusi menggunakan solusi dynamic programming. Sebenarnya LCS dengan tiga sekuen sama saja dengan LCS menggunakan dua sekuen. Namun bedanya disini, dalam mengelesaikan LCS dengan tiga string, dibutuhkan array tiga dimensi yang volumenya adalah X.Y.Z dimana X, Y, dan Z adalah panjang dari ketiga sekuen.
Solusi optimal yang dihasilkan akan didapatkan di elemen array yang terakhir, yaitu array dengan indeks X-1, Y-1, dan Z-1
Petbedaan lainnya dalam LCS menggunakan tiga sekuen, arah/direction yang perlu di-cek adalah sebanyak tujuh arah. Tujuh arah tersebut yang direpresentasikan dengan angka adalah sebagai berikut :

0 menuju ke c[i - 1, j - 1, k - 1]
1 menuju ke c[i - 1, j - 1, k]
2 menuju ke c[i - 1, j, k - 1]
3 menuju ke c[i, j - 1, k - 1]
4 menuju ke c[i, j, k - 1]
5 menuju ke c[i, j - 1, k]
6 menuju ke c[i - 1, j, k]

Read more…

C# Preprocessor

August 1, 2009 azer89 Leave a comment

These commands never translated and included into the executable file but these are very useful for compilation process. Using preprocessors, we can stop the compiler from compiling certain potion of code. This is very helpful in the situation where you are planning to release two versions of software one basic version which has less features and one advance version which has more features. The preprocessor directives are all starts with the # symbol in the beginning of them.

C# actually has almost all the standard preprocessor directives – it just happens to be that the functionality of some of them . The one notable directive that is missing is #include – and it makes sense that C# wouldn’t have it, because C# gets the same sort of functionality from the using statements (although there is the fact that #include refers to files and using refers to assemblies – so they are definitely not equivalent).

Rules

  1. Preprocessor directives must be on separate line
  2. Must not terminate with semicolon compared to normal C# statements
  3. Starts with # character
  4. End of line comments are not allowed
  5. Delimited comments are not allowed

blog

Read more…

Categories: C#, Programming Tags: , ,

Oracle Database and C# : SQL Function

March 26, 2009 azer89 Leave a comment

Function for Query
ex : SELECT

        public DataSet ExecuteQuery(string sql)
        {
            DataSet dsResult = new DataSet();

            try
            {
                OracleDataAdapter daAdapter = new OracleDataAdapter(sql, conn);
                daAdapter.Fill(dsResult);
            }
            catch (OracleException oex)
            {
                if (oex.Number == 2292)
                    MessageBox.Show("crash from a data from other table");
                else
                    MessageBox.Show(oex.Message);

                CloseConnection();
                OpenConnection();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                CloseConnection();
                OpenConnection();
            }

            return dsResult;
        }

Function for DML
ex : UPDATE, DELETE


        public int ExecuteSQL(string sql)
        {
            int isAffectedRows = 0;

            try
            {
                OracleTransaction oTransaction = conn.BeginTransaction();
                OracleCommand oCmd = conn.CreateCommand();
                oCmd.CommandText = sql;
                isAffectedRows = oCmd.ExecuteNonQuery();
                oTransaction.Commit();
            }
            catch (OracleException oex)
            {
                if (oex.Number == 2292)
                {
                    MessageBox.Show("crash from a data from other table");
                }
                else
                {
                    MessageBox.Show(oex.Message);
                }

                CloseConnection();
                OpenConnection();

                return 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                CloseConnection();
                OpenConnection();

                return 0;
            }

            return isAffectedRows;  // if success return value not 0
        }
Categories: C#, Database, Programming Tags: , ,

Oracle Database Connection using C#

March 17, 2009 azer89 1 comment

what we must do first :

private OracleConnection conn;
private string connString = "Data Source=(DESCRIPTION="
             + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.126.11.15)(PORT=1521)))"
             + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORAPBD9)));"
             + "User Id=joe;Password=joe;";

for opening connection :

public bool OpenConnection()
{
            bool success = true;

            try
            {
                conn = new OracleConnection(connString);
                conn.Open();
            }
            catch (Exception ex)
            {
                success = false;
            }

            return success;
}

closing….

public void CloseConnection()
{
        conn.Close();
        conn.Dispose();
}
Categories: C#, Programming Tags: , ,

C# Dictionary

January 26, 2009 azer89 3 comments

Ini bukan pembahasan kamus lo, Dictionary pada C# merupakan salah satu bentuk dari hash table.

Apa itu hash table ?

hash table adalam struktur data semacam array, tiap elemen memiliki value dan sebuah key. Key disini seperti indeks pada Array. Kompleksitas pencarian sebuah data pada hash table nyaris mencapai O(1).

Lengkapnya untuk penjelasan hash table baca disini.

Berikut ini contoh implementasi dari Dictionary. Disini saya contohkan valuenya adalah string dan key-nya adalah integer. tpe dari value dan key sendiri bebas… gak harus string dan integer.

Read more…

Categories: C#, Programming Tags: , ,

Double Buffering UserControl di C#

January 25, 2009 azer89 Leave a comment

Pastinya komponen UserControl akan berkedap-kedip ketika kita memanggil fungsi Refresh(). Nah,cara mengakalinya ternyata cukup gampang, kita tinggal menambah beberapa baris kode dibawah ini di konstruktor.

this.SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.DoubleBuffer,true);

That’s All, hasilnya, tampilan animasi akan mulus tanpa kedap-kedip.

Categories: C#, Programming Tags: ,

Program OGRE Saya yang Pertama

August 10, 2008 azer89 Leave a comment

Setelah dipelajari sampe otak panas, kemampuan OGRE saya yang nasibnya “gelap gak jelas” akhirnya menunjukkan titik terang….he he he

berikut ini aplikasi OGRE yang suderrrhana banget :)


#include
#include 

class SampleApp : public ExampleApplication
{
public:
    // Basic constructor
    SampleApp()
    {}

protected:

    // Just override the mandatory create scene method
    void createScene(void)
    {
        // Create the SkyBox

        mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");  //latar langit

        // Create a light
        Light* myLight = mSceneMgr->createLight("Light0");
        myLight->setType(Light::LT_POINT);
        myLight->setPosition(0, 40, 0);
        myLight->setDiffuseColour(1, 1, 1);
        myLight->setSpecularColour(1, 1, 1);

        Entity *ent1 = mSceneMgr->createEntity( "Ogre", "ogrehead.mesh" );  //bikin objeknya (kepalanya ogre)
        SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreNode" );
        node1->attachObject( ent1 );

        Entity *ent2 = mSceneMgr->createEntity( "Ninja", "ninja.mesh" );  //bikin objek ninja
        SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "NinjaNode", Vector3( 50, 0, 1000 ) );  // letaknya x=50, y=0, z=1000
        node2->attachObject( ent2 );

        node2->scale( 5, 2, 3 ); // memanipulasi skala dari objek 3D

        //ent1->setVisible(false);  //disable tampilan

    }
};

// ----------------------------------------------------------------------------
// Main function, just boots the application object
// ----------------------------------------------------------------------------
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
    // Create application object
    SampleApp app;

    try
    {
        app.go();
    }
    catch( Exception& e )
    {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else

        std::cerr << &quot;An exception has occured: &quot; <scale( 5, 2, 3 );

gunanya adalah memanipulasi ukuran objek, kalau kita memperbesar skala y nanti karakter kita akan menjadi jangkung, bisa juga diubah jadi gendut atau pendek :)

Dalam OGRE, terdapat berbagai macam jenis vektor, yang saya bahas ini vektor 3D, nah, kalau sumbu x itu adalah garis dari sebelah kiri monitor sampai sebelah kanan monitor, subu y adalah bagian bawah monitor ke bagian atas monitor, sedangkan sumbu z berasal dari dalam monitor lalu ke luar monitor.

kalau kita mau merotasi objek pada sumbu x

node2->pitch( Degree( -90 ) );

kalau kita mau merotasi objek pada sumbu y

node1->yaw( Degree( -90 ) );

kalau kita mau merotasi objek pada sumbu z

node3->roll( Degree( -90 ) );

nih…screenshotnya:

Categories: OGRE 3D, Programming Tags: , ,

Game Programming With OGRE 3D

August 8, 2008 azer89 9 comments

Ahh…apaan lagi ini? kali ini saya lagi membicarakan game programming, yep, saya pernah posting tentang Allegro, nah, setelah diberi tahu oleh teman, saya baru tahu kalau ada library grafis khusus untuk 3D, ya, library ini bernama OGRE 3D, atau singkatnya disebut OGRE saja (kepanjangannya sih Object-Oriented Graphics Rendering Engine). Library ini termasuk open source. O ya, library ini dikhususkan untuk bahasa C++, kalau C ? kayaknya tidak bisa karena diwajibkan untuk pemrograman berorientasi objek, untuk IDE-nya sendiri saya pake CodeBlocks+MinGw.

Awal pertama kali tahu tentang OGRE saya kayaknya mulai tertarik, wow, keren nih, soalnya kalau pake Allegro agak susah kalau pemrograman 3D-nya. Sebenarnya waktu itu saya ditawari teman untuk bikin proyek animasi dan game. Dia fokus ke desain 3D dan saya bagian programmingnya, menarik banget!

Pada saat tulisan ini ditulis–>kemampuan saya tentang OGRE masih nol besar, hahaha, cuman baru bisa compile doang, langkah awal saya belajar OGRE ya..baru menginstall aplikasi MinGw+CodeBlocks+OGRE,nah, pas dicoba compile aplikasi OGRE-nya, wah error! Katanya tidak diketemukan d3dx9d_30.dll. Wah bingung saya, kalo gak salah, d3dx9d_30.dll itu DirectX 10, nah saya tambah bingung, kan saya pakai Vista,sudah pasti ada DirectX 10-nya, tapi kok masi error aja ya? Wah terpaksa saya donwload d3dx9d_30.dll dari internet, awalnya saya pikir,bisa gak ya? Jangan-jangan d3dx9d_30.dll yang saya download palsu… Ah, mau gimana lagi, langsung saja d3dx9d_30.dll yang baru saya download kukopi ke folder OGRE-nya, dan..berhasil dicompile…..oke jeehhh…bisa! Moga-moga nanti gak ada error lagi gara-gara d3dx9d_30.dll yang didownload dari sumber yang tidak jelas.

Wew..kapan saya bisa jadi master OGRE? tunggu tanggal mainnya! hehehe….

Categories: OGRE 3D, Programming Tags: , ,

(C#) Tower Of Hanoi

July 30, 2008 azer89 2 comments

Hello again, now, for killing time in holiday,i wrote a program again :) , the program is Tower Of Hanoi. Here sort explanation of Tower Of Hanoi, i took it from Wikipedia:
The Tower of Hanoi or Towers of Hanoi (also known as The Towers of Benares) is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks neatly stacked in order of size on one rod, the smallest at the top, thus making a conical shape.
The objective of the puzzle is to move the entire stack to another rod, obeying the following rules:

  • Only one disk may be moved at a time.
  • Each move consists of taking the upper disk from one of the pegs and sliding it onto another rod, on top of the other disks that may already be present on that rod.
  • No disk may be placed on top of a smaller disk.
  • Using recurrence relation, the exact number of moves that this solution requires can be calculated by: 2h − 1

Read more…

Categories: C#, Programming Tags: ,