our notes for our youngers

December 9, 2009

Shooting Game ေလးေရးရေအာင္ – 2

pic1

pic1

download source window apppication here

http://www.mediafire.com/download.php?kyndziv3ijv

ကြၽန္ေတာ္ Exercise Two အေနနဲ႔ ေပးခဲ႔တဲ႔ ေသနတ္ပစ္တဲ႔ game ေလးပါ။ ကြၽန္ေတာ္ video tutorial အေနနဲ႔ လုပ္ေပးခ်င္ေပမယ့္ မိုးကုန္သြားျပီဆိုေတာ့ မီးက အခြင့္အေရး မေပးေတာ့ဘူးဗ်ာ။ ဒါေၾကာင့္ ကုဒ္ေလးကိုပဲ ျမန္ျမန္ကူးလာျပီး တင္ေပးလိုက္ပါတယ္။ ညီတို႔ Program ကို Run ျပီး Code ကို Trace လိုက္ၾကည့္လိုက္ရင္ နားလည္မွာပါ။ မရွင္းတဲ႔ အပိုင္းေလးေတြကို ေကာမန္႔မွာ ျပန္ေမးပါ။ ကြၽန္ေတာ္ ျပန္ရွင္းျပပါ့မယ္။ ေနာက္ထပ္ exercise three အေနနဲ႔ေရာ ဘာေရးရင္ ေကာင္းမလဲ… အၾကံရွိရင္လည္း ေကာ္မန္႔ေပးခဲ႔ၾကပါဦး။

public partial class Form1 : Form
{
    int startCounter = 6;
    int bulletCount = 7;
    int totalPoint = 0;
    int currentPoint = 0;
    int tmr = 0;
    bool PlayingTime = false;
    bool bulletMovingTime = false;
    Random rnd = new Random();

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyValue == 113 && !PlayingTime)
        {
            StartGame();
        }
        else if (PlayingTime)
        {
            if (e.KeyValue == 38)
            {
                if (picGun.Top > groupBox1.Height + groupBox1.Top)
                {
                    picGun.Top -= 5;
                    if (!bulletMovingTime)
                    {
                        picMovingBullet.Top -= 5;
                    }
                }
            }
            else if (e.KeyValue == 40)
            {
                if (picGun.Top + picGun.Height < panel1.Top)                 {                     picGun.Top += 5;                     if (!bulletMovingTime)                     {                         picMovingBullet.Top += 5;                     }                 }             }             else if (e.KeyValue == 13 || e.KeyValue == 32)             {                 if (!bulletMovingTime)                 {                     if (bulletCount >= 1)
                    {
                        bulletCount--;
                        lblTotalBullet.Text = bulletCount.ToString();
                        totalPoint += Convert.ToInt32(lblTarget.Text);
                        bulletMovingTime = true;
                        tmrMovingBullet.Enabled = true;
                        picMovingBullet.Left = picGun.Left + picGun.Width;
                        picMovingBullet.Top = picGun.Top + 3;
                        switch (bulletCount)
                        {
                            case 1: picBullet1.Visible = true;
                                picBullet2.Visible = false;
                                picBullet3.Visible = false;
                                picBullet4.Visible = false;
                                picBullet5.Visible = false;
                                picBullet6.Visible = false;
                                picBullet7.Visible = false;
                                break;
                            case 2: picBullet1.Visible = true;
                                picBullet2.Visible = true;
                                picBullet3.Visible = false;
                                picBullet4.Visible = false;
                                picBullet5.Visible = false;
                                picBullet6.Visible = false;
                                picBullet7.Visible = false;
                                break;
                            case 3: picBullet1.Visible = true;
                                picBullet2.Visible = true;
                                picBullet3.Visible = true;
                                picBullet4.Visible = false;
                                picBullet5.Visible = false;
                                picBullet6.Visible = false;
                                picBullet7.Visible = false;
                                break;
                            case 4: picBullet1.Visible = true;
                                picBullet2.Visible = true;
                                picBullet3.Visible = true;
                                picBullet4.Visible = true;
                                picBullet5.Visible = false;
                                picBullet6.Visible = false;
                                picBullet7.Visible = false;
                                break;
                            case 5: picBullet1.Visible = true;
                                picBullet2.Visible = true;
                                picBullet3.Visible = true;
                                picBullet4.Visible = true;
                                picBullet5.Visible = true;
                                picBullet6.Visible = false;
                                picBullet7.Visible = false;
                                break;
                            case 6: picBullet1.Visible = true;
                                picBullet2.Visible = true;
                                picBullet3.Visible = true;
                                picBullet4.Visible = true;
                                picBullet5.Visible = true;
                                picBullet6.Visible = true;
                                picBullet7.Visible = false;
                                break;
                            case 7: picBullet1.Visible = true;
                                picBullet2.Visible = true;
                                picBullet3.Visible = true;
                                picBullet4.Visible = true;
                                picBullet5.Visible = true;
                                picBullet6.Visible = true;
                                picBullet7.Visible = true;
                                break;
                            default: picBullet1.Visible = false;
                                picBullet2.Visible = false;
                                picBullet3.Visible = false;
                                picBullet4.Visible = false;
                                picBullet5.Visible = false;
                                picBullet6.Visible = false;
                                picBullet7.Visible = false;
                                break;
                        }
                    }
                    else
                    {
                        tmrMovingTarget.Enabled = false;
                    }
                }
            }
        }
    }

    private void tmrTimer_Tick(object sender, EventArgs e)
    {
        tmr++;
        lblTimer.Text = tmr.ToString("D4");
        if (currentPoint != 0 && totalPoint != 0)
        {
            decimal accuracy = ((Convert.ToDecimal(currentPoint) / Convert.ToDecimal(totalPoint)) * 100);
            lblAccuracy.Text = Math.Round(accuracy).ToString("N0") + "%";
            lblPoint.Text = currentPoint + "/" + totalPoint;
        }
    }

    private void tmrMovingTarget_Tick(object sender, EventArgs e)
    {
        lblTarget.Top = rnd.Next(groupBox1.Height + groupBox1.Top, panel1.Top - lblTarget.Height);
        lblTarget.Text = Convert.ToString(rnd.Next(1, 6) * 2 - 1);
    }

    private void tmrStartCounter_Tick(object sender, EventArgs e)
    {
        if (startCounter == 6)
        {
            lblReady.Text = "Ready to start";
            startCounter--;
        }
        else if (startCounter >= 1)
        {
            lblReady.Text = (startCounter--).ToString();
        }
        else if (startCounter == 0)
        {
            lblReady.Text = "GO!";
            startCounter--;
        }
        else
        {
            PlayingTime = true;
            tmrMovingTarget.Enabled = true;
            tmrStartCounter.Enabled = false;
            lblReady.Visible = false;
            tmrTimer.Enabled = true;
        }
    }

    private void tmrMovingBullet_Tick(object sender, EventArgs e)
    {
        if (picMovingBullet.Left + picMovingBullet.Width >= this.ClientSize.Width)
        {
            tmrMovingBullet.Enabled = false;
            bulletMovingTime = false;
            picMovingBullet.Left = picGun.Left + picGun.Width;
            picMovingBullet.Top = picGun.Top + 3;
            ShowMessage();
        }
        else if ((picMovingBullet.Left + picMovingBullet.Height >= lblTarget.Left) &&
            (picMovingBullet.Top + picMovingBullet.Height > lblTarget.Top && picMovingBullet.Top < lblTarget.Top + lblTarget.Height))
        {
            currentPoint += Convert.ToInt32(lblTarget.Text);
            lblPoint.Text = currentPoint + "/" + totalPoint;
            tmrMovingBullet.Enabled = false;
            bulletMovingTime = false;
            picMovingBullet.Left = picGun.Left + picGun.Width;
            picMovingBullet.Top = picGun.Top + 3;
            ShowMessage();
        }
        else
            picMovingBullet.Left += 3;
    }

    private void ShowMessage()
    {
        if (bulletCount == 0)
        {
            tmrMovingTarget.Enabled = false;
            tmrTimer.Enabled = false;
            lblPoint.Text = currentPoint + "/" + totalPoint;
            PlayingTime = false;
            decimal accuracy = ((Convert.ToDecimal(currentPoint) / Convert.ToDecimal(totalPoint)) * 100);
            lblAccuracy.Text = Math.Round(accuracy).ToString("N0") + "%";
            MessageBox.Show("Your Score : " + currentPoint + "\nAccuracy : " + Math.Round(accuracy).ToString("N0") + "%\nTotal Time : " + tmr/100 + "." + tmr%100 + " - seconds");
        }
    }

    private void StartGame()
    {
        lblAccuracy.Text = "0%";
        lblPoint.Text = "0/0";
        tmrStartCounter.Enabled = true;
        lblReady.Visible = true;
        startCounter = 6;
        bulletCount = 7;
        totalPoint = 0;
        currentPoint = 0;
        tmr = 0;
        lblTimer.Text = "0000";
        lblTotalBullet.Text = bulletCount.ToString();
        PlayingTime = true;
        picBullet1.Visible = true;
        picBullet2.Visible = true;
        picBullet3.Visible = true;
        picBullet4.Visible = true;
        picBullet5.Visible = true;
        picBullet6.Visible = true;
        picBullet7.Visible = true;
    }
}

November 26, 2009

Shooting Game ေလးေရးရေအာင္

Shooting the best…. ( Exercise Two )

shooting the best...

pic_1

ကြၽန္ေတာ္တို႔ ေလ့က်င့္ခန္းေလး ေနာက္တစ္ခု အေနနဲ႔ ေသနတ္ပစ္တဲ႔ ဂိမ္းေလး ေရးၾကရေအာင္။ ဒီဂိမ္းေလးမွာ Timer Control ကို အဓိကသံုးထားပါတယ္။ ေနာက္တစ္ခုက Form ေပၚမွာ key ႏွိပ္တဲ႔ event မွာ user ႏွိပ္တဲ႔ key ကို ျပန္စစ္တဲ႔ အလုပ္ေလးလည္း ပါတာေပါ့။ ဒီ ၂ ခ်က္ထဲပဲ ေသခ်ာသိဖို႔လိုပါတယ္။ အိုေက… အားလံုးပဲ စမ္းေရးၾကည့္ၾကပါဦး။ ထံုးစံ အတိုင္း ေနာက္တစ္ပါတ္မွာ source code ကိုတင္ေပးပါ့မယ္။ ေလာေလာဆယ္ေတာ့ exe file ေလးကို ေဒါင္းျပီး runၾကည့္ play ၾကည့္ၾကပါဦး။

 

exe file

http://www.mediafire.com/download.php?gnzww3iyjnc

November 5, 2009

Exercise One Video

ကြၽန္ေတာ္ exercise အေနနဲ႔ ေပးခဲ႔တဲ႔ Screen Saver Program ေလးကို မေန႔ညက ကြၽန္ေတာ္ Video Training ေလး လုပ္လာခဲ႔တယ္။ ေသေသခ်ာခ်ာေလးေတာ့ လုပ္ေပးထားပါတယ္။ ညီတို႔ ေဒါင္းျပီး ၾကည့္ၾကည့္ပါဦး။ မရွင္းတာရွိရင္ ျပန္ေမးေစခ်င္ပါတယ္။ ကြၽန္ေတာ္ Video Training လုပ္ဖို႔ သံုးတဲ႔ software က SnapIt9 ပါ။ အဲ့ဒီ software ရဲ႕႔ အားနည္းခ်က္ေၾကာင့္ထင္တယ္ ေျပာေနရင္း အခ်ိန္ၾကာလာရင္ အသံက ျမန္ျပီး ရုပ္ပံုက ေႏွးေနတာေလး တစ္ခုေတာ့ ရွိတယ္။ အဲ့ဒါေလး သည္းခံျပီး နားေထာင္ေပးၾကပါခင္ဗ်ာ။ အဲ… ေနာက္တစ္ခုက ကြၽန္ေတာ္ရဲ႕ အသံဆိုးဆိုးေလးကိုလည္း သည္းခံေပးပါေနာ္ :)

ကြၽန္ေတာ္ အပိုင္း ၅ ပိုင္း ခြဲျပီး တင္ပါမယ္။ ၁ပိုင္းစီကို rar file ေျဖျပီး နားေထာင္လို႔ရတယ္ေနာ္။ အားလံုး ေဒါင္းျပီးမွ ၾကည့္စရာမလိုဘူး။ Source Code ကိုလည္း ထည့္ေပးလိုက္ပါတယ္။ အဲ့ဒါေလးကို ၾကည့္ျပီး ကိုယ္တိုင္ ျပန္လုပ္ၾကည့္ပါ။ ရသြားရင္… ဒါမ်ိဳး ဆင္တူေလးေတြကို ကိုယ္တိုင္စမ္းလုပ္ၾကည့္ပါ။ (ဥပမာ.. အခုကြၽန္ေတာ္က line ဆြဲျပထားတယ္ အဲ့ဒီအစား စက္၀ိုင္းတို႔ ဘာတို႔ လုပ္ၾကည့္ေပါ့ေနာ္ )

ညီ၊ညီမ တို႔ အားလံုး programming ကို အခက္အခဲမရွိ ေလ့လာနိုင္ၾကပါေစ….

Part One :

http://www.sendspace.com/file/5yrx3u

 

Part Two :

http://www.sendspace.com/file/t3wji1

 

Part Three :

http://www.sendspace.com/file/6gbway

 

Part Four :

http://www.sendspace.com/file/r58ep8

 

Part Five :

http://www.sendspace.com/file/cxwb2y

 

Source Code :

http://www.sendspace.com/file/we1wb9

October 29, 2009

screensaver အတုေလး ေရးရေအာင္

ကြၽန္ေတာ္တစ္ခု စဥ္းစားမိတာ ရွိတယ္။ ကြၽန္ေတာ္တို႔ အတူတူ C# program ေလးေတြ ေရးၾကရေအာင္။ အရင္ဆံုး ကြၽန္ေတာ္က ေရးျပီးသား exe file ေလး တင္ေပးမယ္။ ညီတို႔က အဲ့ဒီ exe file ေလးကို run ၾကည့္ျပီး။ အဲ့ဒီ result အတိုင္းထြက္ေအာင္ ၾကိဳးစားျပီး program ေရးၾကည့္ၾကပါ။ တစ္ပါတ္ၾကာရင္ ကြၽန္ေတာ္က အဲ့ဒီ program ကို ျပန္ရွင္းျပျပီး source code တင္ေပးပါ့မယ္။ ၾကားထဲမွာ ညီတို႔ ေရးတဲ႔ program ကို ကြၽန္ေတာ္ email ကို ပို႔ေပးရင္လည္း ကြၽန္ေတာ္ စစ္ေပးပါမယ့္။ ဒီလို လုပ္ျခင္း အားျဖင့္ ကိုယ္တိုင္ ေလ့လာတဲ႔ အေလ့အက်င့္ေလးလည္း ရသြားမယ္။ program လည္း ေရး က်င့္ရသြားမယ္ေပါ့။
ကဲ အရင္ဆံုး C# window application နဲ႔ ေရးထားတဲ႔ Screen server ပံုစံ program ေလး နဲ႔ စေရးလိုက္ရေအာင္။
exe file ေလးကို ဒီကေန ယူျပီး run ၾကည့္ပါ။
http://www.sendspace.com/file/xy2ql1

note:

ဒီ program ေလးေရးဖို႔အတြက္

1 – Graphics class အေၾကာင္း

2 – Random class အေၾကာင္း

3 – Array အေၾကာင္း

4 – Timer Control အေၾကာင္းကို သိဖို႔လိုပါတယ္။

တကယ္ လိုက္ျပီး ေရးၾကလိမ့္မယ္လို႔ ေမွ်ာ္လင့္ပါတယ္….

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.