<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Teerapong Sontayaman 's Kode Talker .NET</title>
	<atom:link href="https://gpluspluss.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://gpluspluss.wordpress.com</link>
	<description>C# .NET  , ASP.NET 2.0 discuss and tutorial</description>
	<lastBuildDate>Thu, 17 Nov 2011 07:16:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gpluspluss.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s-ssl.wordpress.com/i/buttonw-com.png</url>
		<title>Teerapong Sontayaman 's Kode Talker .NET</title>
		<link>https://gpluspluss.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://gpluspluss.wordpress.com/osd.xml" title="Teerapong Sontayaman &#039;s Kode Talker .NET" />
	<atom:link rel='hub' href='https://gpluspluss.wordpress.com/?pushpress=hub'/>
		<item>
		<title>ฝึกการเขียนโปรแกรม ด้วย Robo MIND  ภาค #2</title>
		<link>https://gpluspluss.wordpress.com/2011/07/03/educational_programming2/</link>
		<comments>https://gpluspluss.wordpress.com/2011/07/03/educational_programming2/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 11:14:55 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C# .NET]]></category>
		<category><![CDATA[educational programming]]></category>
		<category><![CDATA[RoboMind]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=520</guid>
		<description><![CDATA[ครับต่อไปก็ไม่ต้องพล่ามกันแล้วครับ เราจะลองมา เขียนโปแกรมกับเจ้า RoboMind กันดูนะครับ หากใครยังไม่ทราบว่า บทความนี้เป็นอย่างไรมาอย่างไร ก็ขอให้ กลับไปดู ฝึกการเขียนโปรแกรม ด้วย Robo MIND ซึ่งเป็นตอนแรกของบทความนี้นะครับ สำหรับในส่วนนี้เราจะทำอะไรบ้าง ตามนี้นะครับ Load and install RoboMind Example progam Load and install RoboMind ครับเราก็จะload เจ้า RoboMind มาติดตั้งบนเครื่องของเราเสียก่อนนะครับก่อนที่เราจะสามารถเขียน code กัน ให้ไปตาม link นี้นะครับ http://www.robomind.net/en/download.html ให้เลือก นะครับเพราะเราใช้ windows กันเป็นส่วนใหญ่ หากท่าน ใด ใช้ operating system ตัวอื่นก็เลือกเอาเลยครับ ตามที่เราใช้ หลักจาก load ลงเครื่องเราแล้ว ก็ double click บน file ที่เรา [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=520&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://gpluspluss.files.wordpress.com/2011/07/robomind2.jpg"><img class="aligncenter size-medium wp-image-510" title="robomind2" src="http://gpluspluss.files.wordpress.com/2011/07/robomind2.jpg?w=300&#038;h=103" alt="" width="300" height="103" /></a></p>
<p>ครับต่อไปก็ไม่ต้องพล่ามกันแล้วครับ เราจะลองมา เขียนโปแกรมกับเจ้า RoboMind กันดูนะครับ หากใครยังไม่ทราบว่า บทความนี้เป็นอย่างไรมาอย่างไร ก็ขอให้ กลับไปดู<a href="../2011/07/03/educational_programming/"> ฝึกการเขียนโปรแกรม ด้วย Robo MIND</a> ซึ่งเป็นตอนแรกของบทความนี้นะครับ สำหรับในส่วนนี้เราจะทำอะไรบ้าง ตามนี้นะครับ</p>
<ul type="disc">
<li>Load and install RoboMind</li>
<li>Example progam</li>
</ul>
<p><strong>Load and install RoboMind</strong></p>
<p>ครับเราก็จะload เจ้า RoboMind มาติดตั้งบนเครื่องของเราเสียก่อนนะครับก่อนที่เราจะสามารถเขียน code กัน ให้ไปตาม link นี้นะครับ <a href="http://www.robomind.net/en/download.html">http://www.robomind.net/en/download.html</a> ให้เลือก</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/07/installation.jpg"><img class="aligncenter size-full wp-image-522" title="installation" src="http://gpluspluss.files.wordpress.com/2011/07/installation.jpg?w=600" alt=""   /></a></p>
<p>นะครับเพราะเราใช้ windows กันเป็นส่วนใหญ่ หากท่าน ใด ใช้ operating system ตัวอื่นก็เลือกเอาเลยครับ ตามที่เราใช้</p>
<p>หลักจาก load ลงเครื่องเราแล้ว ก็ double click บน file ที่เรา load มาได้แล้วนะครับ [ น่าจะชื่อ ว่า RobomindSetup2.x.exe อะไรประมาณนี้ ครับ แล้ว ] แล้วก็รอจนกว่ามันจะดำเนินการเสร็จ ก็จะได้โปรแกรม ลงบนเครื่องเราแล้ว ครั้งแรกมันอาจจะ run ขึ้นมาเลย หลังจาก ลงเสร็จแล้ว พร้อมกับโปรแกรม ตัวอย่างสั้น ๆ</p>
<p>เราลองมาพจารณาการใช้งานพร้อมกับ ดูตัวอย่างไปด้วยกันเลยนะครับ</p>
<p><strong>Example progam</strong></p>
<p>Example โปรแกรม ที่แสดงขึ้นมาพร้อมกับการ แสดงหน้าจอ RoboMind นั้นจะอยู่ช่องด้านซ้ายมือ ส่วนขวามือจะเป็นที่แสดง การทำงานของ เจ้า ROBO และโลกของ มันนะครับน่าจะได้ตามรูป นี้</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/07/robomidn6.jpg"><img class="aligncenter size-full wp-image-528" title="robomidn6" src="http://gpluspluss.files.wordpress.com/2011/07/robomidn6.jpg?w=600&#038;h=238" alt="" width="600" height="238" /></a><a href="http://gpluspluss.files.wordpress.com/2011/07/robomind7.jpg"><img class="aligncenter size-full wp-image-529" title="robomind7" src="http://gpluspluss.files.wordpress.com/2011/07/robomind7.jpg?w=600" alt=""   /></a></p>
<p>และมี code ดังนี้ครับ</p>
<p><pre class="brush: delphi;">
&lt;pre&gt;# Draw a square
 paintWhite()
 repeat(4)
 {
     forward(2)
     right()
 }
 stopPainting()
</pre></p>
<p>ส่วนข้อความที่อยู่หลัง เครื่องหมาย &#8216;#&#8217; เราไม่ต้องสนใจก็ได้นะครับ เพราะมันไม่ถูก นำไปหประมวลผลแต่อย่างได้ นอกจากเป็นการเขียน comment ไว้เป้นคำอธิบาย ครับ</p>
<p>ช่องด้านซ้ายจะเป็นที่สำหรับเราเอาไว้เขียน code ตามความต้องการของเรา ต่อไปนะครับ ตอนนี้เราลองมาดูกันว่า code ชุดนี้เราจะสั่งให้มันทำงานอย่างไร จากเครื่องมือที่โปรแกรมมีให้เราสังเกตุหน้าจอในส่วน ที่สองหรือด้านล่างนะครับเราจะเห็น ดังรูป</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/07/robomind8.jpg"><img class="aligncenter size-full wp-image-530" title="robomind8" src="http://gpluspluss.files.wordpress.com/2011/07/robomind8.jpg?w=600&#038;h=95" alt="" width="600" height="95" /></a></p>
<p>เป็นเครื่องมือที่ช่วยให้เรา สั่งให้ code ที่เราเขียนทำงาน ครับ เพียงแค่คลิกที่ปุ่มที่ มี icon สีเขียว หากโปรแกรมไม่มีข้อผิดพลาดอะไร เจ้า ROBO มันจะทำงานตามคำสั่ง ทีละคำสั่งจากบนลงล่างครับ ถ้าเรา พิจารณาจาก code ด้านซ้ายมือนะครับ จะเป็นการสั่งให้เจ้า ROBO มันระบายสีเป็น สี่เหลี่ยม แล้วหยุด โดยที่ เคลื่อนที่ เป็น loop  4 รอบ แต่ละรอบ จะเเคลื่อนไปข้างหน้า 2 step แล้วหัน ขวา ทำให้เกิดเป็น สี่เหลี่ยมเกิดขึ้น ลอง run ดูแล้ว พิจาณาว่าได้ตมที่ผมพูดไหว้หรือป่าว ฮิ ฮิ เดี๊ยวจะหาว่าโม้ เพราะผม run ดูแล้ว</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/07/robomind9.jpg"><img class="aligncenter size-full wp-image-531" title="robomind9" src="http://gpluspluss.files.wordpress.com/2011/07/robomind9.jpg?w=600" alt=""   /></a>สุดท้านมันก็จะมาหยุดตามรูป ครับ</p>
<p>สังเกตุจากเครื่องมือ นอกจากมันจะสั่ง run ได้แล้ว มันก็ยังสามารถที่ สั่งหยุดระหว่างการทำงานได้ หรือหยุดชั่วคราวแล้ว runต่อก็ได้ สุดหท้ายก็สามารถที่จะ เร่งหรือลด speed ของการทำงานได้ด้วย แหม เจ๋งเป๋งเลยว่ามะ</p>
<p>เราสามารถดูตัวอย่างอื่น ๆที่เขามีมาให้ด้วย ก็ไป  คลิกที่ icon ตามรูปอยู่ด้านบนซ้ายนะครับ</p>
<p style="text-align:left;"><a href="http://gpluspluss.files.wordpress.com/2011/07/robomind10.jpg"><img class="size-full wp-image-532 aligncenter" title="robomind10" src="http://gpluspluss.files.wordpress.com/2011/07/robomind10.jpg?w=600" alt=""   /></a></p>
<p style="text-align:left;"><a href="http://gpluspluss.files.wordpress.com/2011/07/robomind11.jpg"><img class="aligncenter size-full wp-image-533" title="robomind11" src="http://gpluspluss.files.wordpress.com/2011/07/robomind11.jpg?w=600" alt=""   /></a>แล้วจะได้หน้าต่างสำหรับการเลือก เปิดไฟล์ขึ้นมาครับ ลองเปิดและ run ดูนะครับ แล้วก็ลองดู code มันว่าพอเข้าใจใหม่นะครับ ในตอนสองนี้ผมยังคงไม่พูดถึงเรื่องการเขียน นะครับ แค่ดูว่า โปรแกรมมันทำอะไรได้บ้างอย่างไร ระหว่าง ที่เรา run โปรแกรมตัวอย่างเราก็ ลองดู function อื่น ดูนะครับว่ามีอะไรบ้างคราว ๆ</p>
<p style="text-align:left;">บนเมนู ด้านบนจะมีกลุ่มของ เมนูหลัก สำคัญอยู่ 2 กลุ่มคือ Edit และ View</p>
<p style="text-align:left;">    &#8211; Edit ใช้สำหรับการจัดการกับ code ตามรูปนะครับ ความสารถก็เหมือน Text Editor ทั่วไป  copy past select  ค้นหาและ วางแทน อะไรพวกเนี๊ยะก็พอมีให้สามารถแก้ไข code ได้ง่ายครับ</p>
<p style="text-align:left;"><a href="http://gpluspluss.files.wordpress.com/2011/07/editmenu.jpg"><img class="aligncenter size-full wp-image-534" title="editmenu" src="http://gpluspluss.files.wordpress.com/2011/07/editmenu.jpg?w=600" alt=""   /></a></p>
<p style="text-align:left;">   &#8211; View ให้สำหรับจัดการกับ หาจอแสดงผลครับ ก็ zoom in , zoom out  กำหนดการแสดง grid การแสดง radar หรือให้ capture screen ก็ OK นะ</p>
<p style="text-align:left;"><a href="http://gpluspluss.files.wordpress.com/2011/07/viewmenu.jpg"><img class="aligncenter size-full wp-image-535" title="viewmenu" src="http://gpluspluss.files.wordpress.com/2011/07/viewmenu.jpg?w=600" alt=""   /></a></p>
<p style="text-align:left;">มาดูเพิ่มเติมอีกนิดนะครับ ในหน้า Editor มันจะมี line number ใหัเอาให้อ่าน code ง่าย และยังสามารถแสดง error ที่เกิดขึ้นที่ บรรทัดนั้น ๆ ครับ และแสดงได้ด้วยว่ามันมี error อะไร</p>
<p style="text-align:left;"><a href="http://gpluspluss.files.wordpress.com/2011/07/error.jpg"><img class="aligncenter size-full wp-image-536" title="error" src="http://gpluspluss.files.wordpress.com/2011/07/error.jpg?w=600" alt=""   /></a></p>
<p style="text-align:left;"><a href="http://gpluspluss.files.wordpress.com/2011/07/robominderrorline.gif"><img class="aligncenter size-full wp-image-537" title="robomindErrorline" src="http://gpluspluss.files.wordpress.com/2011/07/robominderrorline.gif?w=600" alt=""   /></a></p>
<p style="text-align:left;">ก็น่าจะเป็น ภาพทั้งหมดของเจ้า โปรแกรม RoboMind นะครับ เรื่องการเขียนไว้ต่อกันคราวหน้านะครับ เพราะมันยาวเกินไปแล้ว หากต้องการอ่านล่วงหน้าหรือดูการเขียน ก็เชิญท่านไปสัมผัสกับ ตัวอย่างที่เข้าเตรียมไว้ให้เลยนะครับ ตาม linke นี้เลย</p>
<p style="text-align:left;">- <a href="http://www.robomind.net/en/docExamples.htm">Example scripts </a></p>
<p style="text-align:left;">- ส่วน เรื่อง คำสั่งต่าง ๆ หากต้องการอ่านเพิ่มเตอมก็เชิญตาม link นี้เลยครับ<a href="http://www.robomind.net/en/docProgrammingStructures.htm"> http://www.robomind.net/en/docProgrammingStructures.htm</a></p>
<p style="text-align:left;">ก็ได้แต่หวังว่าบทความนี้จะเป็นประโยชน์ต่อ ครูอาจารย์และเด็ก ๆ ที่ต้องการ จะเรียนรู้เรื่องการเขียนโปรแกรม ไม่มากก็น้อยหล่ะครับ หากมีอะไร อยากให้เพิ่มเติมก็ ติและชมมาได้นะครับ ถือว่าเป็นการแรกเปลี่ยนความรู้ กันครับ</p>
<p style="text-align:left;">s_teerapong2000@yahoo.com</p>
<p style="text-align:left;">teerapong Sontayaman</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/520/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=520&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2011/07/03/educational_programming2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomind2.jpg?w=300" medium="image">
			<media:title type="html">robomind2</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/installation.jpg" medium="image">
			<media:title type="html">installation</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomidn6.jpg" medium="image">
			<media:title type="html">robomidn6</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomind7.jpg" medium="image">
			<media:title type="html">robomind7</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomind8.jpg" medium="image">
			<media:title type="html">robomind8</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomind9.jpg" medium="image">
			<media:title type="html">robomind9</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomind10.jpg" medium="image">
			<media:title type="html">robomind10</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomind11.jpg" medium="image">
			<media:title type="html">robomind11</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/editmenu.jpg" medium="image">
			<media:title type="html">editmenu</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/viewmenu.jpg" medium="image">
			<media:title type="html">viewmenu</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/error.jpg" medium="image">
			<media:title type="html">error</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robominderrorline.gif" medium="image">
			<media:title type="html">robomindErrorline</media:title>
		</media:content>
	</item>
		<item>
		<title>ฝึกการเขียนโปรแกรม ด้วย Robo MIND</title>
		<link>https://gpluspluss.wordpress.com/2011/07/03/educational_programming/</link>
		<comments>https://gpluspluss.wordpress.com/2011/07/03/educational_programming/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 10:03:49 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C# .NET]]></category>
		<category><![CDATA[educational programming]]></category>
		<category><![CDATA[RoboMind]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=508</guid>
		<description><![CDATA[สำหรับผู้ที่อยู่ในแวดวงการศึกษา บรรดาครูอาจารย์ทั้งหลาย ผู้ที่ต้องสอนการเขียนโปรแกรมให้กับ เด็ก ๆ ในระดับชั้นปฐม ถึง มัธยม หากต้องการหาเครื่องมือดี ๆ สำหรับช่วยสอนและสร้าง วิธีคิดในการเขียนโปรแกรม ลองมาดูโปรแกรมช่วยฝึกหัดวิธีการคิด และพัฒนาทักษะในการเขียนโปรแกรมที่ชื่อ Robo MIND กันสักนิด สำหรับผมเองบางทีก็ได้มีโอกาส รับเชิญให้ไปสอนการเขียนโปรแกรมให้กับ เด็ก ๆ ซึ่งก็ได้ประสบการณ์ในการสอนเด็ก ๆ มากพอที่จะทราบว่าการสอนเด็ก ๆ นั้น ไม่ใช่เรื่องง่ายเลย โดยเฉพาะสอนการเขียนโปรแกรมด้วยแล้ว คงไม่ต้องบรรยาย มีสิ่งหนึ่งที่ผมพอสังเกตได้ก็คือ หากเรื่องหรือเนื้อหาที่เรา จัดมาสอนนั้นสนุกสนาน น่าสนใจแล้วละก็จัดการกับ เจ้าพวกลิงได้ชงัดนัก ฉะนั้นแล้ว ครูอาจารย์ทั้งหลาย ทางเลือกหนึ่งที่ท่านสามารถทำได้ และนำไปใช้ได้ ที่ผมมองเห็นก็เจ้า Robo MIND นี่แหละครับ pictures from http://www.robomind.net สำหรับเจ้า RoboMind นี้ เป็นโปรแกรมช่วยฝึกการเขียนโปรแกรมแบบ ง่าย ครับเหมาะสำหรับเด็กที่เริ่มฝึกเขียนโปรแกรม ในระดับชั้นปฐมถึงมัธยม นะครับ ก่อนที่เด็กเหล่านี้จะก้าว ไปเขียน programming [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=508&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://gpluspluss.files.wordpress.com/2011/07/robomind1.jpg"><img class="alignleft size-full wp-image-509" title="robomind1" src="http://gpluspluss.files.wordpress.com/2011/07/robomind1.jpg?w=600" alt=""   /></a>สำหรับผู้ที่อยู่ในแวดวงการศึกษา บรรดาครูอาจารย์ทั้งหลาย ผู้ที่ต้องสอนการเขียนโปรแกรมให้กับ เด็ก ๆ ในระดับชั้นปฐม ถึง มัธยม หากต้องการหาเครื่องมือดี ๆ สำหรับช่วยสอนและสร้าง วิธีคิดในการเขียนโปรแกรม ลองมาดูโปรแกรมช่วยฝึกหัดวิธีการคิด และพัฒนาทักษะในการเขียนโปรแกรมที่ชื่อ Robo MIND กันสักนิด</p>
<p>สำหรับผมเองบางทีก็ได้มีโอกาส รับเชิญให้ไปสอนการเขียนโปรแกรมให้กับ เด็ก ๆ ซึ่งก็ได้ประสบการณ์ในการสอนเด็ก ๆ มากพอที่จะทราบว่าการสอนเด็ก ๆ นั้น ไม่ใช่เรื่องง่ายเลย โดยเฉพาะสอนการเขียนโปรแกรมด้วยแล้ว คงไม่ต้องบรรยาย</p>
<p>มีสิ่งหนึ่งที่ผมพอสังเกตได้ก็คือ หากเรื่องหรือเนื้อหาที่เรา จัดมาสอนนั้นสนุกสนาน น่าสนใจแล้วละก็จัดการกับ เจ้าพวกลิงได้ชงัดนัก ฉะนั้นแล้ว ครูอาจารย์ทั้งหลาย ทางเลือกหนึ่งที่ท่านสามารถทำได้ และนำไปใช้ได้ ที่ผมมองเห็นก็เจ้า Robo MIND นี่แหละครับ</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/07/robomind2.jpg"><img class="aligncenter size-full wp-image-510" title="robomind2" src="http://gpluspluss.files.wordpress.com/2011/07/robomind2.jpg?w=600&#038;h=207" alt="" width="600" height="207" /></a></p>
<p style="text-align:center;">pictures from <a href="http://www.robomind.net/en/index.html">http://www.robomind.net</a></p>
<p>สำหรับเจ้า RoboMind นี้ เป็นโปรแกรมช่วยฝึกการเขียนโปรแกรมแบบ ง่าย ครับเหมาะสำหรับเด็กที่เริ่มฝึกเขียนโปรแกรม ในระดับชั้นปฐมถึงมัธยม นะครับ ก่อนที่เด็กเหล่านี้จะก้าว ไปเขียน programming language อย่างเช่น c หรือ pascal ต่อไป ในระดับที่สูงขึ้น</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/07/capture.jpg"><img class="alignleft size-thumbnail wp-image-512" title="Capture" src="http://gpluspluss.files.wordpress.com/2011/07/capture.jpg?w=82&#038;h=99" alt="" width="82" height="99" /></a></p>
<p>ลักษณะของโปรแกรมนั้น จะมี Robot ให้เราควบคุมการทำงานมันด้วย การพิมพ์คำสั่ง ทีละคำสั่งต่อเนื่องกันไป เพื่อให้ Robot น้อยเคลื่อนที่ ไปตามทิศทางที่ต้องการ และทำงาน ต่าง ๆ ตามชุดคำสั่งที่มีให้ ครับ  นอกจากนี้ยังมี คำสั่ง ให้ทำซ้ำ  และทดสอบเงื่อนไข เพื่อการเขียนมีความซับซ้อนเพิ่มขึ้นได้อีก</p>
<p>ผมกล่าวมาแค่นี้ ท่านที่กำลังอ่านอยู่ก็คงจะ Bingo แล้วใช่ไหมครับ มันยอดมากจริง ๆเอาละครับ ลองมาดูรายละเอียดกันหน่อย ครับว่าในบทความนี้จะมีอะไรกันบ้าง</p>
<ul>
<li>เรื่องของ หน้าตา และเครื่องมือสำหรับการใช้งาน (development environments )</li>
<li>คำสั่งพื้นฐาน  (Basic instructions)</li>
<li>โครงสร้างของโปรแกรม (Programming structures)</li>
<li>ตัวอย่างโปรแกรม ครับ</li>
</ul>
<p><strong>หน้าตา และเครื่องมือสำหรับการใช้งาน (development environments )</strong></p>
<p>โปรแกรม RoboMind นั้นสิ่งสำคัญก็คือ การเขียนคำสั่งและ ประมวลผลคำสั่ง ที่จะสั่งการ เจ้าหุ่ยน้อย หรือ เจ้า ROBO   หน้าตาโปรแกรมก็ง่ายๆ ครับ</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/07/robo11.jpg"><img class="aligncenter size-medium wp-image-514" title="robo1" src="http://gpluspluss.files.wordpress.com/2011/07/robo11.jpg?w=300&#038;h=206" alt="" width="300" height="206" /></a></p>
<p>หน้าจอด้านซ้าย จะเป็นหน้าต่างสำหรับการ เขียน code และหน้าจออีกด้านหนึ่งจะแสดงการทำงานของเจ้า ROBO ครับ เมื่อสั่งให้ run โดยการคลิกปุ่ม play โปรแกรมจะตรวจสอบ code ว่าถูกต้องหรือไม่ก่อน แล้วจึงทำงานให้</p>
<p>หน้าจอด้านซ้ายสำหรับการเขียน code นั้นเราเรียกว่า  Text Editor สว่นหน้าจอด้านขวาที่ใช้แสดงการทำงานนั้นเราเรียกมันว่า  Monitor</p>
<p><strong>Text Editor</strong> นั้นมีฟังก็ชั้นการทำงานเพิ่มเติมเช่น</p>
<ul>
<li>แสดง line number</li>
<li>แสดง ข้อความ error ที่เกิดขึ้นได้</li>
<li>สามารถทำ undo change ได้ไม่จำกัด</li>
<li>มี function ในการค้นหาและ แทนที่ได้ (สามารถใช้ regular expressions ได้ด้วย)</li>
<li>ในขณะทำงาน จะแสดงหัวลูกสอนที่บรรทัดที่กำลังทำงานอยู่ได้อีกด้วย</li>
</ul>
<p lang="en-US"><strong>Monitor</strong></p>
<ul>
<li>เป็นหน้าจอสำหรับ แสดง การทำงานของเจ้า ROBO และ โลกของมัน</li>
<li>สามารถ pan และ zoom ได้ และยังสามารถทำ screen shot เก็บไว้ได้ด้วย</li>
</ul>
<p><strong>การ Execute โปรแกรม</strong></p>
<p>ไม่ต้องทำอะไร มากครับ สามารถสั่งให้ code ที่ถูกต้องแล้ว ทำงานได้ด้วย คลิกเดียวครับ</p>
<p>เราแค่จัดการให้ code คำสั่ง ถูกต้อง ถูกลำดับการทำงานที่ ออกแบบไว้ หากมี error ใด โปรแกรมจะแจ้งให้ทราบและสามารถแก้ไขให้ถูกต้องก่อน ที่จำทำงานจริงทั้งหมด</p>
<p><strong>คำสั่งพื้นฐาน Basic instructions</strong></p>
<p style="text-align:center;"><a href="http://gpluspluss.files.wordpress.com/2011/07/robo2.jpg"><img class="size-medium wp-image-517 aligncenter" title="Robo2" src="http://gpluspluss.files.wordpress.com/2011/07/robo2.jpg?w=240&#038;h=228" alt="" width="240" height="228" /></a></p>
<p>ประกอบด้วยคำสั่งดังนี้ แยกตามกลุ่มคำสั่ง</p>
<ul>
<li><strong>คำสั่งเคลื่อนที่ Move</strong></li>
<ul>
<li>forward(n) เคลื่อนที่ไปข้างหน้า n steps</li>
<li>backward(n) ถอยหลังไป n steps</li>
<li>left() หมุนซ้าย 90 องศา</li>
<li>right() หมุนขวา 90 องศา</li>
<li>north(n) หันหัวไปด้านบน ของหน้าจอ และ เคลื่อนที่ไปข้างหน้า n steps</li>
<li>south(n) หันหัวลงล่าง ของหน้าจอ และ เคลื่อนที่ไปข้างหน้า n steps</li>
<li>east(n) หันหัวไปข้างขวา ของหน้าจอและ เคลื่อนที่ไปข้างหน้า n steps</li>
</ul>
<ul>
<li>west(n) หันหัวไปข้างซ้าย ของหน้าจอ และเคลื่อนที่ไปข้างหน้า n steps</li>
</ul>
</ul>
<ul>
<li><strong>คำสั่งระบายสี Paint</strong></li>
<ul>
<li>paintWhite() ลากแปรงสีขาว ไปบนพื้น</li>
<li>paintBlack() ลากแปรงสีดำ ไปบนพื้น</li>
</ul>
<ul>
<li>stopPainting() หยุดลากแปลง และเก็บแปรงสี</li>
</ul>
</ul>
<ul>
<li><strong>คำสั่งหยิบ Grab</strong></li>
<ul>
<li>pickUp()  หยิบ สิงของที่อยู่ด้านหน้า</li>
<li>putDown() วางสิ่งของที่ถือไว้ลง</li>
</ul>
</ul>
<ul>
<li><strong>คำสั่งโยนเหรียญ เพื่อเสี่ยงทาย Flop coin</strong></li>
<ul>
<li>coinflip() โดยเหรียญเพื่อ เลือกตัวเลือก</li>
</ul>
</ul>
<ul>
<li><strong>คำสั่งตรวจสอบ หรือ ตรวจการ See</strong></li>
<ul>
<li>leftIsObstacle() , frontIsobtacle(), rightIsObstracle()</li>
<li>leftIsClear(), frontIsClear(), rightIsClear()</li>
<li>leftIsBeacon(), frontIsBeacon(), rightIsBecan()</li>
<li>leftIswhite(), frontIsWhite() , rightIsWhite()</li>
<li>leftIsBlack(), frontIsBlack(), rightIsBlack()</li>
</ul>
</ul>
<p style="text-align:left;">โอโห้ น่าสนใจเป็นอย่างยิ่ง คงจะไม่สามารถ อดใจที่จะลงมือเขียน กันแล้วใช่ใหม่หล่ะเด็ก ๆ ทั้งหลาย เอาเป็น ต่อภาคสองก็แล้วกันนะครับ เพราะมันยาวเกินไปแล้วครับ สำหรับ ภาคดแรกนี้ ไปดู คลิป กระตุ้น อีกนิดนะครับ  ไปตาม link นี้เลยครับ</p>
<p style="text-align:left;"><a href="http://www.robomind.net/en/demo.html">http://www.robomind.net/en/demo.html</a></p>
<p style="text-align:left;">ตอนต่อไป เราจะไป load โปรแกรมแล้วลองมาเขียนเล่นกันนะครับ</p>
<p style="text-align:left;">s_teerapong2000@yahoo.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/508/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=508&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2011/07/03/educational_programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomind1.jpg" medium="image">
			<media:title type="html">robomind1</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robomind2.jpg" medium="image">
			<media:title type="html">robomind2</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/capture.jpg?w=122" medium="image">
			<media:title type="html">Capture</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robo11.jpg?w=300" medium="image">
			<media:title type="html">robo1</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/07/robo2.jpg?w=300" medium="image">
			<media:title type="html">Robo2</media:title>
		</media:content>
	</item>
		<item>
		<title>XNA first steps [ เริ่มต้นกับ XNA ]</title>
		<link>https://gpluspluss.wordpress.com/2011/06/12/xna-first-steps/</link>
		<comments>https://gpluspluss.wordpress.com/2011/06/12/xna-first-steps/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 06:08:29 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C# .NET]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=491</guid>
		<description><![CDATA[ช่วงนี้เป็นช่วงที่ผม เรียนเรื่องการเขียนเกมส์ อืม ไม่ได้ความว่าผมจะไปทำเกมส์ขายที่ไหน หรอก ผมทำงานอยู่ในทีมพัฒนาระบบจำลองยุทธ์ และเราก็เล็งเห็นแล้วว่าอีกไม่นาน เทคโนโลยีที่เราใช้กับ ระบบของเรามันกำลังล้าแล้ว เราก็มองหาเทคโนโลยีที่ดีกว่า ใหม่กว่า และยืนยาวกว่า นั่นเอง พูดแค่นี้ทุกคนก็คงเห็นด้วยเพราะการจะทำระบบอะไรสักอย่าง เงื่อนไขที่ผมกล่าวถือว่าเป็นพื้นฐานแลกที่เราจะมองกัน แล้วค่อยไปพิจาณาเรื่องอื่น ๆ ต่อไป ครับเอาเป็นว่า ตัวที่ผมสนใจก็คือ XNA กล่าวโดยย่อนะครับ XNA เป็น Framework ในการพัฒนาเกมส์ที่ผลิตโดย บริษัท Microsoft แน่นอนครับ มันเป็น เทคโนโลยีที่ทำงานบน .NET Framework ซึ่งตัว XNA นั่นประกอบด้วย library และเครื่งมือ ที่จะช่วยให้ผู้พัฒนาเกมส์สามารถทำงานได้รวดเร็ว และสามารถพัฒนาเกมส์ให้สามารถใช้งานได้ บน Windows Xbox 360 รวมถึง Windows Phone 7 ส่วนในรายละเอียดของ XNA ก็ไปอ่านเพิ่มเติมต่อที่นี่ก็แล้วกันนะครับ  http://en.wikipedia.org/wiki/Microsoft_XNA  [ อะไร อะไรก็ [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=491&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p><a href="http://gpluspluss.files.wordpress.com/2011/06/xna-tutorial.jpeg"><img class="alignleft size-thumbnail wp-image-488" title="xna-tutorial" src="http://gpluspluss.files.wordpress.com/2011/06/xna-tutorial.jpeg?w=105&#038;h=105" alt="" width="105" height="105" /></a>ช่วงนี้เป็นช่วงที่ผม เรียนเรื่องการเขียนเกมส์ อืม ไม่ได้ความว่าผมจะไปทำเกมส์ขายที่ไหน หรอก ผมทำงานอยู่ในทีมพัฒนาระบบจำลองยุทธ์ และเราก็เล็งเห็นแล้วว่าอีกไม่นาน เทคโนโลยีที่เราใช้กับ ระบบของเรามันกำลังล้าแล้ว เราก็มองหาเทคโนโลยีที่ดีกว่า ใหม่กว่า และยืนยาวกว่า นั่นเอง</p>
<p>พูดแค่นี้ทุกคนก็คงเห็นด้วยเพราะการจะทำระบบอะไรสักอย่าง เงื่อนไขที่ผมกล่าวถือว่าเป็นพื้นฐานแลกที่เราจะมองกัน แล้วค่อยไปพิจาณาเรื่องอื่น ๆ ต่อไป</p></blockquote>
<p>ครับเอาเป็นว่า ตัวที่ผมสนใจก็คือ <a href="http://en.wikipedia.org/wiki/Microsoft_XNA">XNA</a><br />
กล่าวโดยย่อนะครับ XNA เป็น Framework ในการพัฒนาเกมส์ที่ผลิตโดย บริษัท Microsoft แน่นอนครับ มันเป็น เทคโนโลยีที่ทำงานบน .NET Framework ซึ่งตัว XNA นั่นประกอบด้วย library และเครื่งมือ ที่จะช่วยให้ผู้พัฒนาเกมส์สามารถทำงานได้รวดเร็ว และสามารถพัฒนาเกมส์ให้สามารถใช้งานได้ บน Windows Xbox 360 รวมถึง Windows Phone 7 ส่วนในรายละเอียดของ XNA ก็ไปอ่านเพิ่มเติมต่อที่นี่ก็แล้วกันนะครับ  <a href="http://en.wikipedia.org/wiki/Microsoft_XNA">http://en.wikipedia.org/wiki/Microsoft_XNA</a>  [ อะไร อะไรก็ wiki นะครับเดี๊ยวนี้ ]</p>
<p>เอาเป็นว่าผมมองตัวนี้ก็เพราะว่า ผมไม่ต้องไปกังวลในเรื่องของการแสดงภาพ เสียง รวมถึงการจัดการกับ input device ต่าง ๆเลย และที่สำคัญ มันทำงานบน development platform ที่ผมใช้งานอยู่แล้ว แค่นี้เป็นอันว่า จบประเด็นข้อเหตุผลในการเลือก</p>
<p>ลองมามองในด้านของ การพัฒนาเกมส์กันบ้างครับ<br />
- เกมส์ programming นั้นจะแตกต่างจากการเขียนโปรแกรม windows  ตามที่เราทราบกันนะครับ การเขียน โปรแกรมบนwindows นั้นเป็นเขียนแบบ event driven หมายถึง code ที่เราเขียน จะอยู่ใน event handler ซึ่งจะถูกเรียกใช้ก็ต่อเมื่อ มีเหตุการณ์อะไรสักอย่างเกิดขึ้น กับ control เช่นการ click mouse เป็นต้น ขี้เกียจ<br />
- เกมส์ programming นั้นเป็น real-time ครับ และก็ไม่มีการรอ event เพื่อการทำงาน  การทำงานจะเป็น loop ที่เราเรียกว่า game loop มีการคำนวณ game status มีการตรวจสอบ input ภายใน loop ในแต่ระรอบของการทำงาน เพราะฉะนั้นการทำงาน programmer จะต้องเขียนโปรแกรมเพื่อ ตรวจสอบ และสั่งการภายใน loop นั่นเองครับ<br />
ดังนั้น typical game loop ประกอบด้วย ขั้นตอน ตามที่แสดงรูปด้านล่าง<br />
<a href="http://gpluspluss.files.wordpress.com/2011/06/tgamel.png"><img class="aligncenter size-full wp-image-495" title="tgamel" src="http://gpluspluss.files.wordpress.com/2011/06/tgamel.png?w=600" alt=""   /></a> จะเห็นว่า loop นั้นเกิดขึ้นใน ส่วนสีเหลือง ซึ่งก็จะมีการรับค่า input คำนวณสถานะต่าง ๆ ของเกมส์ ตรวจสอบ กฎเกณฑ์ต่าง ที่เกมส์กำหนด update ค่า แล้วจึง ให้ feedback กลับไป เช่นการแสดงหล หรือเสียงเป็นต้น ทำอย่างนี้ไปเรื่อย ๆ จนกว่าจะออกจากเกมส์<br />
ส่วน วงรอบเกมส์ของ XNA จะเห็นดังภาพ ครับ</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/06/xnagamel.png"><img class="aligncenter size-full wp-image-496" title="xnagamel" src="http://gpluspluss.files.wordpress.com/2011/06/xnagamel.png?w=600" alt=""   /></a><br />
อันที่จริง มันก็ไม่ได้ต่างกัน นัก เพียงแต่ XNA ทำ loop ไว้ให้ โดยทีกำหนดว่า ภายใน update() function ผู้พัฒนาต้อง ตรวจสอบ input คำนวณสถานะ และตรวจสอบ กฎ ต่าง ๆ  และการ feedback ต่าง ๆ ให้ทำใน Draw() function<br />
คงพอได้ concept นะครับ</p>
<p>ลองมาดูการ implement กันบ้างนะครับ</p>
<p>ก่อนที่เราจะทำงาน กับ XNA ได้ก็ต้องมีการ ติดตั้งกันเสียก่อนนะครับ สามารถไป download ได้ที่  <a href="http://creators.xna.com/en-US/downloads">http://creators.xna.com/en-US/downloads</a> ตรวจสอบให้ดีนะครับ ท่านควรจะ download version ไหน ขึ้นอยู่กับว่าท่านใช้ visual studio version ไหน ครับซึ่งมันก็หมายถึงท่านใช้ framework version ไหนนั่นเอง 2.0 3.5 หรือ 4.0 ท่าก็เลือก XNA ให้เหมาะสมกับท่าน ได้เลย หลังจากติดตั้งแล้ว ก็มาเริ่มกันเลยนะครับ ( ของผมเองใช้  version 4.0 เพราะผมใช้ visual studio 2010 .Net framework version 4.0  code เป็น C# .net นะครับ)</p>
<p>เริ่มด้วยการ Project ใหม่นะครับ แล้วเลือก Windows Game เราจะพบว่า template ได้มีการสร้าง ไฟล์ให้เรา หลายไฟล์ที่สำคัญก็คือ Game1.cs ซึ่งเป็น file ที่มี game loop และก็ยังมี Content folder ซึ่งมีไว้สำหรับเก็บ พวก resources ต่าง ๆเช่น รูป sprite ที่เราจะใช้งานเป็นต้น</p>
<p>การเพิ่ม หรือ เอารูปที่เตรียมไว้มาใส่ ใน content ก็เพียงแต่ click mouse ขวาที่ content แล้วเลือก &#8220;Add/Existing item…&#8221; แล้วก็วิ่งไปหา Image file ที่ต้องการ (<a href="http://gpluspluss.files.wordpress.com/2011/06/ship3.png?w=31">ship3 คลิก ขวาแล้วเลือก save linke as&#8230;</a>)  อ่านตรงนี้ให้ เข้าใจนะครับ เมื่อ เพิ่ม image เข้ามาใน content แล้วลอง click รูปแล้วดู properties จะเห็นว่า มี Asset Name ที่เป็นชื่อของ รูปภาพ ชื่อเหล่านี้จะเก็บไว้สำหรับอ้างอิงในการ เรียกใช้ต่อไป ครับ</p>
<p>สิ่งที่เราต้องการทำใน Project นี้ก็คือการ load ภาพแล้วแสดงในหน้าจอนั่นเอง ครับ ดังนั้นเราก็แค่ ใส่ code ลงใน LoadContent() method เพื่อ load รูป และใส่ code ใน UnloadContent() เพื่อ เอาสิ่งที่ load ออกไป เรายังไม่มีการ ทำอะไรใน Update() เพราะว่าเราแค่แสดงรูปเท่านั้น   และเพื่อแสดงภาพเราก็จะใส code ลงใน Draw() method ตามนี้เลย ครับ</p>
<p>เพื่อให้มันสั้น ผม ลบ comment ออกนะครับ code ที่เราเพิ่มจะอยู่ระหว่าง // &#8212; our code #1,2,3,4,5 นะครับ</p>
<p><pre class="brush: csharp;">

public class Game1 : Microsoft.Xna.Framework.Game
{
 GraphicsDeviceManager graphics;
 SpriteBatch spriteBatch;
 // -- our code #1 --------------------------
 private Texture2D ship;
 private Vector2 ship_pos;
 // -----------------------------------------
 public Game1()
 {
   graphics = new GraphicsDeviceManager(this);
   // -- our code #2------------------------------
   graphics.PreferredBackBufferHeight = 600;
   graphics.PreferredBackBufferWidth = 800;
   Window.Title = &quot;Game Test ver. 1.0 - Teerapong S.&quot;;
   // ------------------------------------------
   Content.RootDirectory = &quot;Content&quot;;
 }

 protected override void Initialize()
 {
   // TODO: Add your initialization logic here
   base.Initialize();
 }

 protected override void LoadContent()
 {
   // Create a new SpriteBatch, which can be used to draw textures.
   spriteBatch = new SpriteBatch(GraphicsDevice);

   // TODO: use this.Content to load your game content here
   // --- our code #3 ------------------------------------
    ship = Content.Load&lt;Texture2D&gt;(&quot;ship3&quot;);  // using asset name นะครับ
  // -----------------------------------------------------

 }

 protected override void UnloadContent()
 {
  // TODO: Unload any non ContentManager content here
  // --- our code #4 ------------
   ship.Dispose();     // free resources, and release memory ไม่มีก็ยังได้
  // -----------------------------
 }

 protected override void Update(GameTime gameTime)
 {
  // Allows the game to exit
  if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  this.Exit();

  // TODO: Add your update logic here
  base.Update(gameTime);
 }

 protected override void Draw(GameTime gameTime)
 {
   GraphicsDevice.Clear(Color.CornflowerBlue);

   // TODO: Add your drawing code here
   // --- our code # 5 ------------------------
   spriteBatch.Begin();
   spriteBatch.Draw(ship, ship_pos, Color.White);
   spriteBatch.End();
   // -----------------------------------------
   base.Draw(gameTime);
 }
}
</pre></p>
<p>จะเห็นว่าเราประกาศ ตัวแปร 2 ตัว  ship และ ship_pos นะครับ เป็น Texture2D กับ Vector2 จะยังไม่ขอ พูดอะไรเกี่ยว variable type ครับแล้วเรามีการกำหนด ค่าเริ่มต้น ใน constructor นิดหน่อย เป็นการกำหนด ขนาด windows สำหรับแสดงภาพ  our code #2</p>
<p>ต่อมาใน loadContent เราทำการ load resource ชื่อว่า ship3 ตรวจสอบ asset name ของresources ให้ดีนะครับ ไม่จะเป็นต้องตรงกับชื่อไฟล์ก็ได้ ถ้าหากเราไม่ได้มีการแกไขส่วนใหญ่จะต้องกลับชื่อไฟล์</p>
<p>ใน UnloadContent ใส่ไว้เพื่อ unload resource นั่น ๆ นะครับ ผมเข้าใจว่าอาจไม่ต้อง ก็ได้ ปล่อยให้ framework มันจัดการเอง [ ปกติถ้าเรา เขียน c++ หรือ c ต้องกำจัดให้หมด ]</p>
<p>สุดท้ายเรา draw เพื่อแสดงรูป นะครับ</p>
<p>สังเกตว่าการแสดงผลใด ๆ ก็ตามต้อง อยู่ระหว่าง spriteBatch.Begin() และ spriteBatch.End()</p>
<p>ลอง run ดู จะได้รูปเรือ ขนาดเท่าต้นฉบับบ แสดงอยู่ที่ตำแหน่ง x = 400 , y = 300  ( นับจากมุม บนซ้าย x เป็นแนวนอน y เป็น แนวตั้งนะครับ ,มุมบนซ้าย เป็นตำแหน่ง x = 0 , y = 0 )</p>
<p lang="th">พอได้ใหม  ครับ  ในหน้าจอเราก็จะเห็น การแสดงผล เรือ ค้างอยู่ตำแหน่งนั้น ไม่ย้ายไปไหน การแสดงผลที่เห็น ไม่ได้เป็นการสั่งการ ครั้งเดียวนะครับ เป็นสั่งการในรูป เพราะฉะนั้น จะถูกสั่งให้แสดงรูป ทุกรอบ และเร็วมาก ๆ ที่ตำแหน่งเดิม</p>
<p>หากต้องการให้มีการเคลื่อนที่จะต้องทำอย่างไร ลองคิดดูครับ …………………………….. ใช้แล้วเปลี่ยน ค่า ship_pos</p>
<p>Ship_pos instance ของ  class Vector2 เป็นซึ่ง coordinate ในระนาบ 2 มิติ มีแค่ค่า x,y เท่านั้น เพราะฉะนั้นการเคลือน ภาพก็ต้องทำการ บวกหรือ ลบ ค่า X หรือ Y นี่แหละครับ และจะต้องทำภายใน Update() mehtod ตาม code ที่แสดงด้านล่าง นะครับ</p>
<p><pre class="brush: csharp;">

protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
// ourcode #6 ----------------------------
KeyboardState keystate = Keyboard.GetState();
//ขึ้นบน
if (keystate.IsKeyDown(Keys.Up))
ship_pos = new Vector2(ship_pos.X, ship_pos.Y - 0.5f);
//ลงล่าง
if (keystate.IsKeyDown(Keys.Down))
ship_pos = new Vector2(ship_pos.X, ship_pos.Y + 0.5f);

// ไปซ้าย
if (keystate.IsKeyDown(Keys.Left))
ship_pos = new Vector2(ship_pos.X - 0.5f , ship_pos.Y );
// ไปขวา
if (keystate.IsKeyDown(Keys.Right))
ship_pos = new Vector2(ship_pos.X + 0.5f, ship_pos.Y );
// ---------------------------------------
base.Update(gameTime);
}

</pre></p>
<p>Code มีความหมาย ตาม remark ไว้ไห้</p>
<p style="text-align:center;">เป็นการตรวจจับ keyboard ว่ามีการ กดปุ่ม หัวลูกศรหรือป่าว และเป็น หัวลูกศรทิศไหน ก็ ดำเนินการกับ ดำแปร ship_pos ในด้านที่ ควรจะเป็น ถ้าไม่เข้าใจ ลอง ร่างหน้าจอใน กระดาษดูนะครับ แล้วจะเข้าใจเอง ขี้เกียจอธิบาย lazy  อะ<br />
เอาดูจากรูป ก็แล้วกัน<br />
<a href="http://gpluspluss.files.wordpress.com/2011/06/untitled-1.jpg"><img class="size-full wp-image-502 aligncenter" title="Untitled-1" src="http://gpluspluss.files.wordpress.com/2011/06/untitled-1.jpg?w=600" alt=""   /></a></p>
<p>ส่วนใคร ไม่เข้าใจการเพิ่มค่า shiop_pos.X และ ship_pos.Y ลองทำแบบนี้แทนก็ได้</p>
<p>Ship_pos.Y -= 0.5f ;</p>
<p lang="th">หรือ</p>
<p>Ship_pos.Y = Ship_pos.Y &#8211; 0.5f ;</p>
<p>ใครไม่เข้าใจอะไร ก็ลอง mail มาคุยกันก็ได้ หรือ คุยกันผ่านทาง blog ก็ได้</p>
<p>ขอให้สนุกสนานกับการเริ่มต้น กับ XNA  นะครับ</p>
<p>ธีระพงษ สนธยามาลย์</p>
<p>Teerapong Sontayaman</p>
<p>s_teerapong2000@yahoo.com</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/06/tgamel.png"><br />
</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/491/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=491&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2011/06/12/xna-first-steps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/xna-tutorial.jpeg?w=150" medium="image">
			<media:title type="html">xna-tutorial</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/tgamel.png" medium="image">
			<media:title type="html">tgamel</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/xnagamel.png" medium="image">
			<media:title type="html">xnagamel</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/untitled-1.jpg" medium="image">
			<media:title type="html">Untitled-1</media:title>
		</media:content>
	</item>
		<item>
		<title>XNA Game Development  [เริ่มต้นกับ XNA]</title>
		<link>https://gpluspluss.wordpress.com/2011/06/10/xna-game-development-%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%81%e0%b8%b1%e0%b8%9a-xna/</link>
		<comments>https://gpluspluss.wordpress.com/2011/06/10/xna-game-development-%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%81%e0%b8%b1%e0%b8%9a-xna/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 09:44:50 +0000</pubDate>
		<dc:creator>iamasimov</dc:creator>
				<category><![CDATA[game development]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=486</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=486&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://gpluspluss.files.wordpress.com/2011/06/xna-tutorial.jpeg"><img class="alignleft size-full wp-image-488" title="xna-tutorial" src="http://gpluspluss.files.wordpress.com/2011/06/xna-tutorial.jpeg?w=600" alt=""   /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/486/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=486&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2011/06/10/xna-game-development-%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%81%e0%b8%b1%e0%b8%9a-xna/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/8b7495cbfd386355a9c4606154bfd25c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">iamasimov</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/xna-tutorial.jpeg" medium="image">
			<media:title type="html">xna-tutorial</media:title>
		</media:content>
	</item>
		<item>
		<title>UML for C# programmers [ UML  สำหรับ C# โปรแกรมเมอร์ ]  ตอน 1</title>
		<link>https://gpluspluss.wordpress.com/2011/06/09/uml-for-c-programmers-uml-%e0%b8%aa%e0%b8%b3%e0%b8%ab%e0%b8%a3%e0%b8%b1%e0%b8%9a-c-%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1%e0%b9%80%e0%b8%a1%e0%b8%ad%e0%b8%a3%e0%b9%8c/</link>
		<comments>https://gpluspluss.wordpress.com/2011/06/09/uml-for-c-programmers-uml-%e0%b8%aa%e0%b8%b3%e0%b8%ab%e0%b8%a3%e0%b8%b1%e0%b8%9a-c-%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1%e0%b9%80%e0%b8%a1%e0%b8%ad%e0%b8%a3%e0%b9%8c/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 12:57:21 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C# .NET]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=463</guid>
		<description><![CDATA[   นี่คงจะเป็น บทความขนาดยาวที่ผมจะลองเขียนอีกสักที เพื่อแบ่งปันประสบการณ์ ให้กับเพื่อนโปรแกรมเมอร์ รวมถึง ขัดเกลาความรู้ให้มันอยู่เป็นระเบียบ หน่อย  ครับ เรื่องของเรื่อง ก็มาจากปัญหา นั่นแหละครับเมื่อใดก็ตามที่ต้องทำงานเป็นทีมไหญ่ การติดต่อสื่อสารเป็นเรื่องสำคัญและมักเป็นปัญหาจาก ขอบเขตเล็ก ๆ ไปสู่ขอบเขตใหญ่ ๆ ได้  ครับ สิ่งที่เราต้องการพูดถึง ก็คือ การทำงานกับ UML Diagram และสื่อสาร กันระหว่าง นักวิเคราะห์ระบบ กับโปรแกรมเมอ์ (หรือ นักเขียนรหัสโปรแกรม ฮิ ฮิ ตั้งชื่อให้มัน โก้ ๆ ) หลายคน เห็นคำพูดนี้ก็จะร้องว่า เออ ใช่ แล้วไงหล่ะ ก็ นักวิเคราะห์ระบบ วิเคราะห์ เสร็จก็จะเขียน UML diagram เช่น class diagram ซึ่งมันเป็น conceptual level มันไม่ได้ให้ความหมายใด ใด [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=463&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>   นี่คงจะเป็น บทความขนาดยาวที่ผมจะลองเขียนอีกสักที เพื่อแบ่งปันประสบการณ์ ให้กับเพื่อนโปรแกรมเมอร์ รวมถึง ขัดเกลาความรู้ให้มันอยู่เป็นระเบียบ หน่อย  ครับ เรื่องของเรื่อง ก็มาจากปัญหา นั่นแหละครับเมื่อใดก็ตามที่ต้องทำงานเป็นทีมไหญ่ การติดต่อสื่อสารเป็นเรื่องสำคัญและมักเป็นปัญหาจาก ขอบเขตเล็ก ๆ ไปสู่ขอบเขตใหญ่ ๆ ได้  ครับ</p></blockquote>
<p>สิ่งที่เราต้องการพูดถึง ก็คือ การทำงานกับ <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">UML Diagram</a> และสื่อสาร กันระหว่าง นักวิเคราะห์ระบบ กับโปรแกรมเมอ์ (หรือ นักเขียนรหัสโปรแกรม ฮิ ฮิ ตั้งชื่อให้มัน โก้ ๆ ) หลายคน เห็นคำพูดนี้ก็จะร้องว่า เออ ใช่ แล้วไงหล่ะ ก็ นักวิเคราะห์ระบบ วิเคราะห์ เสร็จก็จะเขียน UML diagram เช่น class diagram ซึ่งมันเป็น conceptual level มันไม่ได้ให้ความหมายใด ใด เกี่ยวกับ ข้อมูล หรือโปรแกรม เช่น ตัวอย่าง diagram ข้างล่าง</p>
<p style="text-align:center;"><a href="http://gpluspluss.files.wordpress.com/2011/06/uml1.jpg"><img class="size-full wp-image-465" title="uml1" src="http://gpluspluss.files.wordpress.com/2011/06/uml1.jpg?w=600" alt=""   /></a></p>
<p>   ในความหมายทาง OOP ของเรา ก็หมายถึง Dog is animal หรือ หมาเป็นสัตว์ ครับ diagram บอกแค่นี้แหละครับ แต่ในรายละเอียดของ Implementation level นั้น มันจะต้องถอดรหัสออกมา ให้แม่นยำมาก เพื่อให้ได้ตามความหมายที่ต้องการ ในที่นี้ ก็จะได้ออก มาเป็น  ( ท่านควรจะมีพื้นฐาน OOP ก่อน ที่ท่านจะมาอ่านเรื่องนี้นะครับ ขอบอก)</p>
<p><pre class="brush: csharp;">
  public class Animal { … }
  public class Dog : Animal { … }
</pre></p>
<p>ตาม code อธิบายได้ว่า มี class Animal และ class Dog โดยที่  class Dog สืบทอดมากจาก Animal ก็หมาย ฟามว่า Dog มีคุณสมบัติทุกอยาก รวมถึงพฤติกรรมเหมือน Animal และก็จะต้องคุณสมบัติบางอย่างหรือ พฤติกรรมบางอย่างที่บ่งบอก ว่ามันเป็น Dog ครับ นั่นนะซิ ( เช่น หมาต้องกิน ขี้ หรือป่าว ฮิ ฮิ อันนี้ไร้สาระ แล้ว)</p>
<p>ก็จะสรุปว่า Diagram นั้น มันเป็น conceptual level ครับ มันสามารถเป็นปัญหาใหญ่ได้หาก โปรแกรมเมอร์ ถอดรหัสออกมาเป็น code ได้ไม่ถูกต้อง</p>
<p>ในที่นี้ก็เลยอยากจะ แสดง การถอดรหัส จาก diagram ไปเป็น code ให้เพื่อน ๆ ได้ติดตามอ่าน กันก็แล้วกันครับ</p>
<p>สำหรับ UML diagram ที่เราจะกล่าวถึง ก็จะเป็น ตัวที่เราใช้ในการ วิเคราะห์ระบบ หลัก ๆ สวนที่ไม่ได้กล่าวถึง นั้น ก็ไม่ได้กล่าวถึง ฮิ ฮิ<br />
UML นั้นมีอยู่ 3 กลุ่ม diagrams นะครับ ประกอบด้วย</p>
<ul>
<li>Static diagram อธิบาย โครงสร้างที่มันไม่เป็นแปลงหรือเคลื่อนไหว โดยใช้ class โครงสร้างของข้อมูล รวมถึงความสัมพันธ์ระหว่าง กัน</li>
</ul>
<ul>
<li>Dynamic diagram อธิบาย การทำงานของ entities ต่าง ๆ ในระหว่างการประมวลผล โดยการแสดงภาพของ flow การประมวลผล</li>
</ul>
<ul>
<li>Physical diagrams อธิบายโครงสร้างที่ ไม่มีการเปลี่ยนแปลง ในภาพของ sources files  หรือ libraries และความสัมพันธ์ที่เกิดขึ้น ระหว่าง กัน ครับ</li>
</ul>
<p>ลองมาดูตัวอย่างกันนะครับ ด้านล่างแสดง code การทำ binary trees แบบหนึ่ง ดูให้เข้าใจแล้วค่อยไปดู ไปไล่ดู diagram กันนะครับ</p>
<p><pre class="brush: csharp;">
public class TreeMap{
  TreeMapNode topNode = null;
  public void add(Comparable key, Object value)
  {
    If(topNode == null)
      topNode = new TreeMapNode(key, value)
    else
      topNode.add(key,value)
   }

  public Object get(Comparable key)
  {
    return topNode == null ? null : topNode.find(key) ;
  }
}

class TreeMapNode {

  private final static int LESS = 0;
  private final static int GREATER = 1;
  private Comparable itsKey;
  private Object itsValue;
  private TreeMapNode nodes [] = new TreeMapNode[2]

  public TreeMapNode(Comprarable key, Object value)
  {
     itsKey = key;
     itsValue = value;
  }

  public Object find(Comparable key)
  {
     if(key.compareTo(itsKey) == 0) return itsValue;
     return findSubNodeForkey(selectSubNode(key),key);
  }

   public int selectSubNodeForKey(int node, Comparable key) {
     return node[nodes] == null ? null : node[node].find(key) ;
   }

  public void add(Comparable key, Object vlaue)
  {
     if(key.compareTo(itskey) == 0)
        itsValue = value;
     else
        addSubNode(selectSubNode(key),key,value);
   }

   public void addSubNode( int node, Comparable key, Object value){
      if( nodes[node] == null)
         nodes[node] = new TreeMap(key, vlaue);
      else
         nodes[node].add(key,value);
    }
}
</pre></p>
<p>เอาละครับ คราวนี้เรามาดูกันที่ diagram ว่าจะเป็น อย่างไรกันบ้าง</p>
<p lang="en-US"><strong>Class Diagram</strong></p>
<p>      class diagram จะแสดง class หลัก และความสัมพันธ์ของ class เหล่านั้น ครับ จากตัวอย่างโปรแกรม นะครับ เราจะเห็น ว่ามี class อยู่ 2 class  คือ TreeMap และ TreeMapNode  กล่าวคือ class TreeMap นั้น มีความสัมพันธ์เชื่อมโยง ไปยัง TreeeMapNode ในลักษณะที่ TreeMapNode เป็น member ของ TreeMap  ในตัวแปรที่ชื่อว่า topNode  ในขณะเดียวกัน TreeMapNode ก็ อ้างอิงไปที่ TreeMapNode ก็คือตัวเอง ลองมาดูว่าในลักษณะนี้เราจะเขียน class diagram และ relation ระหว่างกันอย่าไร</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/06/uml2.jpg"><img class="aligncenter size-full wp-image-466" title="uml2" src="http://gpluspluss.files.wordpress.com/2011/06/uml2.jpg?w=600&#038;h=180" alt="" width="600" height="180" /></a></p>
<p>จาก Code นั้นก็จะได้อย่าง diagram ที่เห็น ด้านบนนี้ นะครับ จากรูป สิ่งที่เราควรจะทราบก็คือ</p>
<ul>
<li>กล่องสี่เหลี่ยม จะแทน class ชื่อ class จะอยู่ด้านบนสุด ตามด้วย attribute และ method อยู่ล่างสุด</li>
</ul>
<ul>
<li>ใน diagram relationship ทั้งหมด เป็น association ซึ่งเป็น relation ship แบบง่ายสุด ใช้การสร้างตัวแปล object เพื่อที่จะ อ้างอิง และเรียกใช้ method ของ class ที่ต้องการ</li>
</ul>
<ul>
<li>ชื่อที่กำกับ association เป็นชื่อ ตัวแปร object ของ class  ที่ต้องการอ้างอิง</li>
</ul>
<ul>
<li>ตัวเลขที่กำกับ เป็นตัวเลขบอก จำนวน instance ที่ relationship สามารถอ้างอิง ได้</li>
</ul>
<p lang="en-US"><strong>Object diagram</strong></p>
<p>  ภาพด้านล่างเป็นการแสดง Object Diagram และ relation ship ในเวลาใดเวลาหนึ่งของการประมวลผล หรือเราอาจเรียกได้ว่าเป็นการทำ snapshot ของ memory มาแสดง นั่นเอง</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/06/uml3.jpg"><img class="aligncenter size-full wp-image-467" title="uml3" src="http://gpluspluss.files.wordpress.com/2011/06/uml3.jpg?w=600" alt=""   /></a></p>
<p>จากภาพ รูปสี่เหลี่ยมแทน Object นะครับ จะสังเกตุเห็นว่า เป็น ชื่อ class จะขีดเส้นใต้นะครับ  ซึ่งเป็น class ที่ เป็น object นั้น ๆ ด้านล่างของ object แทน ตัวแปร object ซึ่งจะเห็นว่าบ้างตัวจะถูกกำหนดค่าให้  และ  relation ระหว่าง object เราเรียกว่า link ซึ่งเป็นตัวเดียวกับ association ครับ</p>
<p lang="en-US"><strong>Sequence Diagrams</strong></p>
<p>    สำหรับ sequence diagram นั้น จะเป็นการแสดง ว่า method ต่าง ๆ นั้น implement อย่างไร</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/06/uml4.jpg"><img class="aligncenter size-full wp-image-468" title="uml4" src="http://gpluspluss.files.wordpress.com/2011/06/uml4.jpg?w=600" alt=""   /></a></p>
<p>จากรูปจะเห็น ว่า เริ่มแรกจะต้องมีการ เรียก add() method ของ TreeMap ถ้า topNode มีค่าเป็น null TreeMap จะresponse ด้วย การสร้าง TreeMapNode ใหม่ แล้วกำหนดให้ topNode ถ้า topNode มีค่าไม่เท่ากีบ null TreeMap จะเรียก add() method ของ topNode</p>
<p>นิพจน์ที่อยู่ในวงเล็บ สี่เหลี่ยม เรียกว่า guardห สำหรับการแสดง ทางเลือกกำกับ   และ หัวลูกศรที่จบที่  TreeMapNode icon นั้นแทน construction  และ bar สี่เหลี่ยม ใต้ Treemap เรียกว่า activation ใช้แสดงห้วงเวลาที่ add method ทำงาน</p>
<p lang="en-US"><strong>Collaboration Diagram</strong></p>
<p>      Diagram ต่อไปเรียกว่า collaboration Diagram ซึ่งเป็น diagram ที่แสดงข้อมูลคล้ายกันกับ Sequence diagram  กล่าวคือ sequence diagram นั้นเป็นตัวแสดงให้เห็นลำดับการทำงานของ การเรียก message แต่ใน collaboration diagram นั้นจะแสดงให้เห็น ความสัมพันธ์ระหว่าง object ดังรูป</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/06/uml5.jpg"><img class="aligncenter size-full wp-image-469" title="uml5" src="http://gpluspluss.files.wordpress.com/2011/06/uml5.jpg?w=600" alt=""   /></a></p>
<p>จากรูป object ถูกเชื่อมเข้าด้วยกัน ด้วย สัญลักษณ์ที่เรียกว่า link ดังนั้น link จะเกิดขึ้นได้ก็ต่อเมื่อ object หนึ่งสามารถ ส่ง message ถึง อีก object หนึ่งได้  สัญลักษณ์ หัวลูกศร คู่กับ message จะกำกับอยู่กับ link แสดงให้เห็น ชื่อ message และทิศทางที่เรียก หมายเลข ด้านหน้าและมี dot นั้นแสดงให้เห็น ลำดับของการเรียก เป็นชั้น</p>
<p>จะเห็นว่า TreeMap.add Function (message 1)  เรียก TreeMapNode.add Function (message 1.1)  พูดได้อีกอย่างหนึ่งว่า message 1.1 นั้น เป็น message แรกที่ ที่เรียกจาก message 1 ครับ</p>
<p>ครับ คงพอเห็นได้นะครับ ว่าเราได้ ทำความรู้จักกับส่วนหนึ่งของ  diagram ที่เรามักใช้งานบ่อย ๆ แล้ว จุดประสงค์ก็เพื่อเป็นการ ทำความคุ้นเคยนะครับ ต่อไปเราจะพูดถึงรายละเอียดในการถอดรหัส ของ diagram ออกเป็น code ที่ถูกต้องต่อไป นะครับ ติดตามตอนต่อไปนะครับ</p>
<p lang="en-US">s_teerapong2000@yahoo.com</p>
<p lang="en-US"><a href="http://www.facebook.com/people/Teerapong-Sontayaman/1424562984">Teerapong Sontayaman</a></p>
<p>ธีระพงษ์ สนธยามาลย์</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/463/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=463&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2011/06/09/uml-for-c-programmers-uml-%e0%b8%aa%e0%b8%b3%e0%b8%ab%e0%b8%a3%e0%b8%b1%e0%b8%9a-c-%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1%e0%b9%80%e0%b8%a1%e0%b8%ad%e0%b8%a3%e0%b9%8c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/uml1.jpg" medium="image">
			<media:title type="html">uml1</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/uml2.jpg" medium="image">
			<media:title type="html">uml2</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/uml3.jpg" medium="image">
			<media:title type="html">uml3</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/uml4.jpg" medium="image">
			<media:title type="html">uml4</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/06/uml5.jpg" medium="image">
			<media:title type="html">uml5</media:title>
		</media:content>
	</item>
		<item>
		<title>Fluent NHibernate  &#8211; to make your life a hell of a lot easier.</title>
		<link>https://gpluspluss.wordpress.com/2011/05/19/fluent-nhibernate-to-make-your-life-a-hell-of-a-lot-easier/</link>
		<comments>https://gpluspluss.wordpress.com/2011/05/19/fluent-nhibernate-to-make-your-life-a-hell-of-a-lot-easier/#comments</comments>
		<pubDate>Thu, 19 May 2011 08:40:34 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C# .NET]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=447</guid>
		<description><![CDATA[Fluent NHibernate นั้นเป็นเครื่องมือ ที่พัฒนา เพิ่มเติมมาจาก NHibernate   มาตรฐาน ซึ่งเดิมนั้น การทำการ Mapping จะเขียนด้วย XML     การพัฒนาของ Fluent NHibernate นั้น ทำให้เราสามารถ mapping ด้วยการเขียน C# code แทนที่จะเป็นการสร้าง XML documents(.hbm.xml files) นอกจากนี้  Fluent NHibernate ยังมีเครื่องมือ อื่น ๆ ที่น่าสนใจ เช่น Auto mappings – การ mapping ทำให้อัตโนมัติ โดยอ้างอิงจาก entities ที่ออกแบบและเขียนไว้ Presistence specification testing –  การ testing  สำหรับ entities ที่ออกแบบไว้  โดยไม่จำเป็นต้องเขียน CRUD แม้แต่บรรทัดเดียว Full [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=447&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Fluent NHibernate นั้นเป็นเครื่องมือ ที่พัฒนา เพิ่มเติมมาจาก NHibernate   มาตรฐาน ซึ่งเดิมนั้น การทำการ Mapping จะเขียนด้วย XML     การพัฒนาของ Fluent NHibernate นั้น ทำให้เราสามารถ mapping ด้วยการเขียน C# code แทนที่จะเป็นการสร้าง XML documents(.hbm.xml files)</p></blockquote>
<p>นอกจากนี้  Fluent NHibernate ยังมีเครื่องมือ อื่น ๆ ที่น่าสนใจ เช่น</p>
<ul>
<li>Auto mappings – การ mapping ทำให้อัตโนมัติ โดยอ้างอิงจาก entities ที่ออกแบบและเขียนไว้</li>
<li>Presistence specification testing –  การ testing  สำหรับ entities ที่ออกแบบไว้  โดยไม่จำเป็นต้องเขียน CRUD แม้แต่บรรทัดเดียว</li>
<li>Full application configuration การกำหนด configuration ทำผ่านทาง Fluent configuration API ได้เลย</li>
<li>Database configuration – เช่นเดียว กันสามารถกำหนด configuration ของ Database ผ่าน ทาง API ได้เลย</li>
</ul>
<p><strong>ความเป็นมาของ Fluent NHibernate</strong></p>
<p>NHibernate เป็น Object Relational Mapping framework ใช้สำหรับการจับคู่ ระหว่าง relational data และ objects   ซึ่ง NHibernate มีการกำหนด การ จับคู่ หรือ mapping ในรูปแบบ XML เรียกว่า HBM ดังนั้น class ทุก class จะต้องมี HBM XML file กำกับอยู่ด้วยเสมอ เพื่อที่จะป็นตัวกำกับ และเป็นตัวอธิบาย โครงสร้างของข้อมูล ในฐานข้อมูล ให้กับ class นั้น ๆ   ครับ  ก็ mapping file นี่แหละครับ ที่ Fluent NHibernate สร้างเครื่องมือมาแทนที่</p>
<p>พอเข้าใจนะครับ ผมรู้ว่าคนที่อ่าน บทความนี้น่าจะต้อง เข้าใจ ORM เป็นพื้นอยู่แล้วนะครับ</p>
<p>แต่ทำไมหล่ะครับ เหตุใดถึงต้องมีการสร้างเครื่องมือมาแทนที่ ในขณะที่ การแยก code ออกจาก <a href="http://en.wikipedia.org/wiki/XML">XML</a> นั้นเป็นวิธีการที่ดีอยู่แล้ว  คำตอบก็คือ มันดีก็จริงแต่มันก็นำไปสู่เหตุการณ์ที่ไม่พึงประสงค์มากมาย เช่น</p>
<ul>
<li> Compiler ไม่ได้ทำการ evaluate XML ให้  เมื่อมีการเปลี่ยนชื่อ properties ใน class แล้วไม่ได้ทำการ ปรับปรุง ใน mapping เราจะไม่รู้เลยจนกว่า mapping จะถูกอ่าน ตอน runtime</li>
<li>XML นั้น หยุมหยิม ครับ ถึงแม้ว่า NHibernate นั้นลด การใช้งาน XML elements ไปแล้ว แต่ก็ยังหนีไม่พ้น ครับ</li>
<li>Repetitive mapping  - NHibernate HBM mapping จะยิ่ง เยอะ หากเราต้องเขียนข้อกำหนด เดิม ๆ บ่อยครั้ง เช่น  ข้อกำหนดที่จะไม่ยอมให้ ข้อมูลแบบ string ให้รับค่า null และต้องมีความยาวไม่เกินกว่า 1000 ตัวอักษรเป็นต้น</li>
</ul>
<p><strong>แล้ว Fluent NHibernate จัดการกับ ข้อปัญหาเหล่านี้ได้อย่างไร</strong></p>
<p>ครับ มันทำได้ด้วยการ เปลี่ยนการเปขียน mapping ให้มาเป็นการ code แทน  และถูก compile ไปกับ app ที่เราเขียน ทำให้เมื่อเราแก้ไขหรือเปลี่ยนแปลง class ก็จะทำให้ ไปแก้ไข การ mapping ตามที่ควรจะเป็น ด้วย  สำหรับเรื่องการใช้งานซ้ำ ๆ    Fluent NHibernate มี configuration system   ทำให้เราสามารถกำหนด รูปแบบสำหรับการทำ override ได้  และ อื่น ๆ</p>
<p><strong>ตัวอย่าง ครับ</strong> &lt;สำหรับข้อมูลและตัวอย่างนำมาจาก  <a href="http://wiki.fluentnhibernate.org/Getting_started">http://wiki.fluentnhibernate.org/Getting_started</a> &gt;</p>
<p><strong>วิธีการ mapping แบบ เดิม</strong></p>
<p><pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;

&lt;hibernate-mapping xmlns=&quot;urn:nhibernate-mapping-2.2&quot; namespace=&quot;QuickStart&quot; assembly=&quot;QuickStart&quot;&gt;

&lt;class name=&quot;Cat&quot; table=&quot;Cat&quot;&gt;
  &lt;id name=&quot;Id&quot;&gt;
    &lt;generator /&gt;
  &lt;/id&gt;
  &lt;property name=&quot;Name&quot;&gt;
    &lt;column name=&quot;Name&quot; length=&quot;16&quot; not-null=&quot;true&quot; /&gt;
  &lt;/property&gt;
  &lt;property name=&quot;Sex&quot; /&gt;
  &lt;many-to-one name=&quot;Mate&quot; /&gt;
  &lt;bag name=&quot;Kittens&quot;&gt;
    &lt;key column=&quot;mother_id&quot; /&gt;
    &lt;one-to-many class=&quot;Cat&quot; /&gt;
   &lt;/bag&gt;
&lt;/class&gt;
&lt;/hibernate-mapping&gt;
</pre></p>
<p><strong>วิธีการ mapping แบบ Fluent NHibernate </strong></p>
<p><pre class="brush: csharp;">
public class CatMap : ClassMap&lt;Cat&gt;
{
  public CatMap()
  {
    Id(x =&gt; x.Id);
    Map(x =&gt; x.Name)
      .Length(16)
      .Not.Nullable();
    Map(x =&gt; x.Sex);
    References(x =&gt; x.Mate);
    HasMany(x =&gt; x.Kittens);
  }
}
</pre></p>
<p><strong> จบไว้แค่นี้ก่อนนะครับ ไว้ต่อ กันในรายละเอียดต่อไป ครับ s_teerapong2000@yahoo.com </strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/447/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/447/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/447/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=447&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2011/05/19/fluent-nhibernate-to-make-your-life-a-hell-of-a-lot-easier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate  Why ???</title>
		<link>https://gpluspluss.wordpress.com/2011/01/11/nhibernate-why/</link>
		<comments>https://gpluspluss.wordpress.com/2011/01/11/nhibernate-why/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 09:44:05 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C# .NET]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[software engineering]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=443</guid>
		<description><![CDATA[เป็นคำถามที่แรกที่หลายคนถามว่า ทำไมถึงต้อง NHibernate  สำหรับผู้พัฒนาระบบ ที่ทำงานมายาวนานแล้ว พอที่จะรู้คำตอบในใจอยู่แล้วว่า การเขียน code เพื่อจัดการกับ object persistence นั้นเป็นเรื่องที่สร้างความ เหน็ดเหนื่อยให้ผู้พัฒนาเป็นอย่างมาก ผมก็เห็นด้วย เพราะงานในการอ่านข้อมูลจากฐานข้อมูล มาสร้างเป็น Object และบันทึกข้อมูลที่เป็น Object กลับลงฐานข้อมูลนั้น ใช้เวลา มากพอสมควร บางท่านบอกว่า อาจต้องใช้ถึง 1 ใน 4 ของ เวลาที่ต้อง coding ทั้งหมด [ผมหมายถึงเวลาที่เราเขียน n-tier aplication นะครับ] และงานพวกนี้ก็ ทำซ้ำซาก ใช้เวลา น่าเบื่อเป็นที่สุด ครับได้มีการแก้ปัญหานี้กันอย่างกว้างขวาง อย่างเช่น การทำ code generator ให้กับ data acces layer สามารถสร้าง code ให้ได้ภายใน พริบตาเดียวแต่ปัญหาก็ยังคงอยู่เนื่องจาก หากมีการแก้ไขโครงสร้างฐานข้อมูลเมื่อใด ก็จำเป็นจะต้องมีการ re [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=443&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>เป็นคำถามที่แรกที่หลายคนถามว่า ทำไมถึงต้อง NHibernate  สำหรับผู้พัฒนาระบบ ที่ทำงานมายาวนานแล้ว พอที่จะรู้คำตอบในใจอยู่แล้วว่า การเขียน code เพื่อจัดการกับ object persistence นั้นเป็นเรื่องที่สร้างความ เหน็ดเหนื่อยให้ผู้พัฒนาเป็นอย่างมาก ผมก็เห็นด้วย เพราะงานในการอ่านข้อมูลจากฐานข้อมูล มาสร้างเป็น Object และบันทึกข้อมูลที่เป็น Object กลับลงฐานข้อมูลนั้น ใช้เวลา มากพอสมควร บางท่านบอกว่า อาจต้องใช้ถึง 1 ใน 4 ของ เวลาที่ต้อง coding ทั้งหมด [ผมหมายถึงเวลาที่เราเขียน n-tier aplication นะครับ] และงานพวกนี้ก็ ทำซ้ำซาก ใช้เวลา น่าเบื่อเป็นที่สุด</p></blockquote>
<p>ครับได้มีการแก้ปัญหานี้กันอย่างกว้างขวาง อย่างเช่น การทำ code generator ให้กับ data acces layer สามารถสร้าง code ให้ได้ภายใน พริบตาเดียวแต่ปัญหาก็ยังคงอยู่เนื่องจาก หากมีการแก้ไขโครงสร้างฐานข้อมูลเมื่อใด ก็จำเป็นจะต้องมีการ re &#8211; create ใหม่อีก</p>
<p>สำหรับ Object-relational managers หรือ ORM อย่างเจ้า NHibernate นั้นแตกต่างครับ ท่าน  มันสามารถจัดการกับ data acces ได้อย่างมีประสิทธิภาพ และสามารถเข้าถึงข้อมูลได้ง่าย เพียงไม่กี่บรรทัด</p>
<p><strong>แนะนำ NHibernate</strong></p>
<p>NHibernate เป็น เป็น persistence engine ในรูปของ Framworke  เอาว่ามันทำหน้าที่ load และ สร้าง business object จากฐานข้อมูล และบันทึกการเปลี่ยนแปลงจาก object กลับลงฐานข้อมูล ครับ และสามารถทำง่ายดังพริกฝ่ามือ เติมให้อีกนิด</p>
<p>เจ้า NHibernate มันจะใช้ข้อมูลใน mapping files [ XML ] สำหรับการแปลงจาก ข้อมูลในฐานข้อมูล เป็น Objects [ ไอ้เจ้า Object ที่สัมพันธ์กับ table ในฐานข้อมูลนี่แหละที่เรียกว่า persistence object ]</p>
<p><a href="http://gpluspluss.files.wordpress.com/2011/01/picture1.png"><a href="http://gpluspluss.files.wordpress.com/2011/01/picture1.png"><img class="alignleft size-full wp-image-445" title="Picture1" src="http://gpluspluss.files.wordpress.com/2011/01/picture1.png?w=600" alt=""   /></a><br />
</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>ดังนั้นทำให้เราแค่ เพิ่ม code สองสามบรรทัด และสร้าง mapping file ให้กับ persistent class [ class ที่สัมพันธ์กับ table ในฐานข้อมูล ] ที่เหลือ เช่น การจัดการกับข้อมูลทั้งหมด   NHibernate จะจัดการให้ สุดยอดไหมหล่ะครับ save เวลาไปเยอะนะครับ</p>
<p>ครับ NHibernate ไม่ใช่ ORM framework ที่มีอยู่เพียงอันเดียว ที่มีอยู่ ในโลกของ .NET นะครับ  มีตัวอื่น ๆอีกมากมาย ไม่ว่าจะเป็น Open source หรือ commercial ที่ทำงานในลักษณะเดียวกันครับ แต่เจ้า NHibernate เป็นตัวหนึ่งที่ค่อนข้างเป็นที่นิยมกันครับ อาจจะเป็นเพราะว่ามันมี บรรพบุรูษเป็น Hibernate ซึ่งเป็น ORM  Framework ยอดนิยมของ Java ก็เป็นได้ นอกจากนั้น Microsoft สัญญาว่าจะมี Entity Framework สำหรับ ADO.NET ที่มีความสามารถเป็น ORM แต่มันก็ยังไม่คลอดออกว่า คงต้องรอก็ต่อไปสักพักนะครับ</p>
<p>ครับ สำหรับเรื่องของ NHibernate นั้นคงต้องว่ากันต่อไป นะครับส่วนท่าที่ต้องการจะอ่านเพิ่มเติมก็สามารถไปตาม link นี้นะครับ<a href="http://nine69.wordpress.com/2010/04/22/orm-series-introduce-nhibernate/"> อ่านเพิ่มเติมได้ที่</a></p>
<p>ของผมเองก็มีเหมือนกันะครับ  <a href="http://gpluspluss.wordpress.com/2011/01/10/nhibernate-%E0%B8%AA%E0%B8%B0%E0%B8%9E%E0%B8%B2%E0%B8%99%E0%B9%80%E0%B8%8A%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%A1%E0%B8%A3%E0%B8%B0%E0%B8%AB%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%87-object-world-%E0%B9%81/">สะพานเชื่อมระหว่าง Object และ Database</a></p>
<p>s_teerapong2000@yahoo.com</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/443/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=443&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2011/01/11/nhibernate-why/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2011/01/picture1.png" medium="image">
			<media:title type="html">Picture1</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate สะพานเชื่อมระหว่าง Object world และ Database world</title>
		<link>https://gpluspluss.wordpress.com/2011/01/10/nhibernate-%e0%b8%aa%e0%b8%b0%e0%b8%9e%e0%b8%b2%e0%b8%99%e0%b9%80%e0%b8%8a%e0%b8%b7%e0%b9%88%e0%b8%ad%e0%b8%a1%e0%b8%a3%e0%b8%b0%e0%b8%ab%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-object-world-%e0%b9%81/</link>
		<comments>https://gpluspluss.wordpress.com/2011/01/10/nhibernate-%e0%b8%aa%e0%b8%b0%e0%b8%9e%e0%b8%b2%e0%b8%99%e0%b9%80%e0%b8%8a%e0%b8%b7%e0%b9%88%e0%b8%ad%e0%b8%a1%e0%b8%a3%e0%b8%b0%e0%b8%ab%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-object-world-%e0%b9%81/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 07:33:50 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C# .NET]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=432</guid>
		<description><![CDATA[นักพัฒนาทั้งหลายครับ สวัสดีปีใหม่ครับหวังว่าปีนี้คงจะมีอะไรที่ ใหม่ ๆ กับชีวิตนะครับ เงินทองหลั่งไหล สุภาพแข็งแรงนะครับ นับว่าเป็นเวลานานมากแล้วที่ผมไม่ได้เข้ามาเขียนบทความเลย ปีใหม่นี้ก็หวังว่าจะเริ่มเขียนให้มากขึ้น อยากจะแบ่งปัน ความรู้ให้กับเพื่อน ๆ โปรแกรมเมอร์ทั้งหลาย นะครับ เรื่องในวันนี้นับเป็นเรื่องแรกแห่งปีนี้ ครับ  อย่างที่ได้ขึ้นหัวไว้นะครับ  NHibernate ถือว่าเป็น นวัตกรรม ของการพัฒนาซอฟต์แวร์ แห่งปีก็ว่าได้นะครับ นักพัฒนาระบบอย่างเรา คงจะเข้าใจได้นะครับ ว่าระบบฐานข้อมูลส่วนใหญ่ที่เราใช้งานั้น จะเป็น relational database ซะส่วนใหญ่ และการพัฒนาระบบในภาษาใหม่นั้น เราก็จะเน้นการเขียน แบบ Object oriented  เมื่อเราทำงานในลักษณะ Object เราก็น่าจะสามารถมองเห็น ข้อมูลเป็น Object ด้วย แต่การ ทำ Data access Layer นั้น เป็นงานหนักทีเดียว ถ้าต้องการทำให้ การเขียนเป็น เชิง Object ทั้งหมด ทั้งนี้ผมกล่าวไปตามความเข้าใจ นะครับ และก็เข้าใจว่า [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=432&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>นักพัฒนาทั้งหลายครับ สวัสดีปีใหม่ครับหวังว่าปีนี้คงจะมีอะไรที่ ใหม่ ๆ กับชีวิตนะครับ เงินทองหลั่งไหล สุภาพแข็งแรงนะครับ นับว่าเป็นเวลานานมากแล้วที่ผมไม่ได้เข้ามาเขียนบทความเลย ปีใหม่นี้ก็หวังว่าจะเริ่มเขียนให้มากขึ้น อยากจะแบ่งปัน ความรู้ให้กับเพื่อน ๆ โปรแกรมเมอร์ทั้งหลาย นะครับ</p>
<p>เรื่องในวันนี้นับเป็นเรื่องแรกแห่งปีนี้ ครับ  อย่างที่ได้ขึ้นหัวไว้นะครับ  NHibernate ถือว่าเป็น นวัตกรรม ของการพัฒนาซอฟต์แวร์ แห่งปีก็ว่าได้นะครับ นักพัฒนาระบบอย่างเรา คงจะเข้าใจได้นะครับ ว่าระบบฐานข้อมูลส่วนใหญ่ที่เราใช้งานั้น จะเป็น relational database ซะส่วนใหญ่ และการพัฒนาระบบในภาษาใหม่นั้น เราก็จะเน้นการเขียน แบบ Object oriented  เมื่อเราทำงานในลักษณะ Object เราก็น่าจะสามารถมองเห็น ข้อมูลเป็น Object ด้วย แต่การ ทำ Data access Layer นั้น เป็นงานหนักทีเดียว ถ้าต้องการทำให้ การเขียนเป็น เชิง Object ทั้งหมด ทั้งนี้ผมกล่าวไปตามความเข้าใจ นะครับ และก็เข้าใจว่า NHibernate เป็นหนทางที่จะนำเราไปสู่การส้รางงานที่ง่ายขึ้น แต่จะเป็นอย่างไรนั้นคงจะต้องหาคำตอบ ไปด้วยกันนะครับ</p></blockquote>
<p>คงจะต้องกล่าวถึง NHibernate ก่อนที่จะลองสัมผัส กันสักนิด นะครับ สำหรับ NHibernate นี่นั้นเขาเรียกกันว่า <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">Object Relational Mapper (ORM) </a>ทำหน้าที่ Map จาก Relational database มาเป็น Object ให้เราครับ ทำให้เราทำงานได้ง่ายขึ้นครับเพราะเราไม่ต้องไปงุ่มง่ามอยู่กับการเขียน Data access layer  ง่ายอย่างไรนั้นคงต้อง ค่อย ๆ ดูตามผมไปก็แล้วกันนะครับ เพราะผมเองก็อยากรู้มากเหมือนกัน</p>
<p>เอาเป็นว่าเราเรียนรู้ NHibernate ผ่านทางต้วอย่างที่ผมจะรวบรวมมา จากง่ายไปหาอยากและเอาไปใช้งานจริง ๆ นะครับ</p>
<p>เครื่องมือที่เราจะใช้ใน ตัวอย่างแรกนี้ก็คงจะเป็น</p>
<ul>
<li> NHibernate version 2.1.2 ครับ load ตาม link นี้เลยครับ<a href="http://sourceforge.net/projects/nhibernate/files/NHibernate/2.1.2GA/NHibernate-2.1.2.GA-bin.zip/download"> NHibernate-2.1.2.GA-bin</a></li>
<li>Visual studio 2008 Express, C#</li>
<li>SQL Server 2005 Express</li>
</ul>
<p>ขั้นตอนการติดตั้ง NHibernate ก็ไม่ยากนะครับ ผมแตกออกแล้วเอาไว้ที่ c:\NHibernate-2.1.2 GA\ แล้ว ทำตามขั้นตอนต่อไปนี้นะครับ</p>
<p>ขั้นตอนที่ 1 :</p>
<ul>
<li>สร้าง Project ชื่อ Lesson3 แล้วสร้าง form แล้ววาง datagrideview ไว้ บน form นั้น นะครับแล้วทิ้งไว้ก่อน</li>
<li>Add Reference -&gt; NHibernate
<ul>
<li>Click ขวาที่ชื่อ Project เลือก Add Reference</li>
<li>Brows ไปยัง folder ที่แตกไว้แล้วเลือก NHibernate.dll ใน \Required_Bins</li>
</ul>
<ul>
<li>ทำอีกครั้ง เพื่อ Add    NHibernate.ByteCode.Castle.dll  ใน \Required_For_LazyLoading\Castle</li>
</ul>
</li>
</ul>
<p>ขั้นตอนที่ 2 :</p>
<ul>
<li>Add new class -&gt; company.cs</li>
</ul>
<p><pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lesson3
{
 public class company
 {
 public company() { }

 public virtual string companyid { get; set; }
 public virtual string companyname { get; set; }
 public virtual string companyemail { get; set; }
 public virtual string companysize { get; set; }

 }
}
</pre></p>
<ul>
<li> Add new XML -&gt;    Set as Embedded Resource [company.hbm.xml]</li>
<li>สำคัญมากสำหรับ ไฟล์นี้ ต้องกำหนด properties ให้เป็น  embedded resource</li>
</ul>
<p><pre class="brush: csharp;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;hibernate-mapping xmlns=&quot;urn:nhibernate-mapping-2.2&quot; assembly=&quot;Lesson3&quot; auto-import=&quot;true&quot;&gt;
 &lt;class name=&quot;Lesson3.company, Lesson3&quot; table=&quot;company&quot; lazy=&quot;true&quot;&gt;
 &lt;id name=&quot;companyid&quot; type=&quot;string&quot;&gt;
 &lt;generator/&gt;
 &lt;/id&gt;
 &lt;property name=&quot;companyname&quot; type=&quot;string&quot;/&gt;
 &lt;property name=&quot;companyemail&quot; type=&quot;string&quot;/&gt;
 &lt;property name=&quot;companysize&quot; type=&quot;string&quot;/&gt;

 &lt;/class&gt;

&lt;/hibernate-mapping&gt;
</pre></p>
<p>ขั้นตอนที่ 3 :</p>
<ul>
<li>config and Execute
<ul>
<li>Add using statment , เปิด form1 ที่เราวาง datagridview ไว้แล้วเพิ่ม using statement ตามนี้ครับ</li>
</ul>
</li>
</ul>
<p><pre class="brush: csharp;">
...
using NHibernate;
using NHibernate.Cfg;
using NHibernate.ByteCode.Castle;
using System.Collections;

</pre></p>
<ul>
<li>แล้ว เพิ่ม code ลงใน constructor ดังนี้</li>
</ul>
<p><pre class="brush: csharp;">
Configuration config = new Configuration();
ISessionFactory factory;

 config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, &quot;NHibernate.Connection.DriverConnectionProvider&quot;);
 config.SetProperty(NHibernate.Cfg.Environment.Dialect, &quot;NHibernate.Dialect.MsSql2005Dialect&quot;);
 config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, &quot;NHibernate.Driver.SqlClientDriver&quot;);
 config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, @&quot;Data Source=.\SQLEXPRESS;Initial Catalog=enterprise4;User ID=sa;Password=xxxx;Pooling=False&quot;);
 config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, &quot;NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle&quot;);

 config.AddAssembly(typeof(Lesson3.company).Assembly);

 factory = config.BuildSessionFactory();
 ISession session = null;
 try
 {
 session = factory.OpenSession();
 dataGridView1.DataSource = session.CreateCriteria(typeof(Lesson3.company)).List();
 }
 catch (Exception ex)
 {
 session.Close();
 MessageBox.Show(ex.Message);
 //throw;
 }

</pre></p>
<p>ลืมไปว่าท่านต้องทำการ สร้าง database ชื่อ enterprise4 โดยที่มี โครงส้รางข้อมูลดังนี้<br />

CREATE TABLE [dbo].[company](
 [companyid] [nchar](10) NOT NULL,
 [companyname] [nchar](150) NULL,
 [companyemail] [nchar](150) NULL,
 [companysize] [nchar](10) NULL,
 CONSTRAINT [PK_company] PRIMARY KEY CLUSTERED
(
 [companyid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

</p>
<p>หลังจากนี้ก็ลอง compile แล้วrun ดูนะครับ จะได้ข้อมูลขึ้นมาแสดง ให้ท่านเห็น อ้อ แต่อย่าลืม ใส่ข้อมูลลงตารางซะก่อนนะครับ<br />
จาก เห็นมั้ยครับ ว่ามันจัดการอะไรให้เราบ้างเราแค่เขียน แค่นี้เราก็สามารถที่จะแสดงข้อมูลจาก table ได้แล้ว ดังนั้น ต้องติดตามกันต่อไปนะครับว่า การทำ operation ต่าง ๆ กับข้อมูลทำได้อย่างไรบ้าง<br />
เช่นการ insert update และการ delete ซึ่งจะเก็บไว้เป็นตอนต่อไป ครับ ถ้ามีอะไรที่ต้องการ ถามก่อนก็ ว่ากันไปตามนี้นะครับ s_teerapong2000@yahoo.com ครับ Bye&#8230;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/432/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/432/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/432/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=432&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2011/01/10/nhibernate-%e0%b8%aa%e0%b8%b0%e0%b8%9e%e0%b8%b2%e0%b8%99%e0%b9%80%e0%b8%8a%e0%b8%b7%e0%b9%88%e0%b8%ad%e0%b8%a1%e0%b8%a3%e0%b8%b0%e0%b8%ab%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-object-world-%e0%b9%81/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>
	</item>
		<item>
		<title>How to embed a form in a control  &#8211; จับ from มาใส่ form</title>
		<link>https://gpluspluss.wordpress.com/2010/07/24/how-to-embed-a-form-in-a-control-%e0%b8%88%e0%b8%b1%e0%b8%9a-from-%e0%b8%a1%e0%b8%b2%e0%b9%83%e0%b8%aa%e0%b9%88-form/</link>
		<comments>https://gpluspluss.wordpress.com/2010/07/24/how-to-embed-a-form-in-a-control-%e0%b8%88%e0%b8%b1%e0%b8%9a-from-%e0%b8%a1%e0%b8%b2%e0%b9%83%e0%b8%aa%e0%b9%88-form/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 16:47:18 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C# .NET]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=411</guid>
		<description><![CDATA[it&#8217;s another time there is some asking about how to show form into another form. i have been trying to find around the web to get the example . but i found the answer myself as following example. . . [try to understand my bad English] . ha ha in this posting i will show [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=411&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>it&#8217;s another time there is some asking about how to show form into another form. i have been trying to find around the web to get the example . but i found the answer myself as following example. . . [try to understand my bad English] . ha ha</p></blockquote>
<p>in this posting i will show how to put existing  two form into one main form , by the way i&#8217;m doing this in main form i put the tab with two tab pages , first tabpage for first form and anther tab put second form. as following picture.</p>
<p style="text-align:center;"><a href="http://gpluspluss.files.wordpress.com/2010/07/fpic1.jpg"><img class="aligncenter size-full wp-image-413" title="fpic1" src="http://gpluspluss.files.wordpress.com/2010/07/fpic1.jpg?w=600&#038;h=365" alt="" width="600" height="365" /></a>figure 1. show two tab in main form</p>
<p style="text-align:left;">
<p>By doing this i  create the project   with main form name form1.cs and another two is anotherform.cs and moreform.cs</p>
<p>First &#8211; put two tab into mainform (form1.cs)  and place panel1 into tabpage1 and groupbox1 into tabpage2 [please note this the control must be a container control]</p>
<p>then &#8211; Create another two form , anotherform.cs and moreform.cs</p>
<p>anotherform.cs</p>
<p style="text-align:center;"><a href="http://gpluspluss.files.wordpress.com/2010/07/fpic3.jpg"><img class="aligncenter size-full wp-image-416" title="fpic3" src="http://gpluspluss.files.wordpress.com/2010/07/fpic3.jpg?w=600" alt=""   /></a>figure 2. show anotherform.cs</p>
<p style="text-align:left;">in this form show information of two textbox when you click  &#8216;show information&#8217;  button</p>
<p style="text-align:left;">moreform.cs</p>
<p style="text-align:center;"><a href="http://gpluspluss.files.wordpress.com/2010/07/fpic4.jpg"><img class="aligncenter size-full wp-image-417" title="fpic4" src="http://gpluspluss.files.wordpress.com/2010/07/fpic4.jpg?w=600" alt=""   /></a>figure 3. show moreform.cs</p>
<p style="text-align:left;">in this form the textbox will show the selected text of  above combobox&#8230;</p>
<p style="text-align:left;">I will not go in detail of how these two form work i will explain how it work  in the main form.</p>
<p style="text-align:left;">in main form (form1.cs)  , see the following code, better then  explain&#8230;</p>
<p style="text-align:left;">
<p><pre class="brush: csharp;">
public void ShowFormInControl(Control myctl, Form myfrm)
{

myfrm.TopLevel = false;
myfrm.FormBorderStyle = FormBorderStyle.None;
myfrm.Dock = DockStyle.Fill;
myfrm.Visible = true;
myctl.Controls.Add(myfrm);

 }

 private void button1_Click(object sender, EventArgs e)
 {
anotherForm myform = new anotherForm();
ShowFormInControl(panel1, myform);

moreForm myform2 = new moreForm();
ShowFormInControl(groupBox1, myform2);

 }
</pre></p>
<p style="text-align:left;">in the source code you can see  the technique of how to put the form into control  in the  &#8220;ShowformInControl(Control myctl, Form myfrm)  &#8220;    the function perform putting the form ( myfrm ) into Control( myctl ) as i mention earlier &#8211; the control must be container control.  without any explanation it&#8217;s obviously show in the code&#8230;</p>
<p style="text-align:left;">then the forms are load by the click event of button1.    &#8211; create form and put into control by calling ShowformInControl where ever you want to put , panel or groupbox or any contrainer control.</p>
<p style="text-align:left;">hope this will help &#8230;   s_teerapong2000@yahoo.com</p>
<p style="text-align:left;">you can download code example here<a href="http://sssolution.net/forum/download/file.php?id=2"> frmAdvance.zip</a></p>
<p style="text-align:left;">
<p style="text-align:left;">
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/411/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=411&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2010/07/24/how-to-embed-a-form-in-a-control-%e0%b8%88%e0%b8%b1%e0%b8%9a-from-%e0%b8%a1%e0%b8%b2%e0%b9%83%e0%b8%aa%e0%b9%88-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2010/07/fpic1.jpg" medium="image">
			<media:title type="html">fpic1</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2010/07/fpic3.jpg" medium="image">
			<media:title type="html">fpic3</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2010/07/fpic4.jpg" medium="image">
			<media:title type="html">fpic4</media:title>
		</media:content>
	</item>
		<item>
		<title>Real-Time Framework [ Single- to Multi-Server Online Game ]</title>
		<link>https://gpluspluss.wordpress.com/2010/07/07/real-time-framework-single-to-multi-server-online-game/</link>
		<comments>https://gpluspluss.wordpress.com/2010/07/07/real-time-framework-single-to-multi-server-online-game/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 03:05:53 +0000</pubDate>
		<dc:creator>Teerapong Sontayaman</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[Win32]]></category>

		<guid isPermaLink="false">http://gpluspluss.wordpress.com/?p=394</guid>
		<description><![CDATA[ได้มีโอกาสร่วมอยู่ในงานวิจัย และพัฒนาเกมที่เป็นกึ่ง ๆ online game  แบบ single-server ซึ่ง เดินมาถึงจุดที่ single &#8211; server ไม่สามารถให้บริการได้เนื่องจาก มี ผู้ใช้มากขึ้น และจำนวน object หรือ entity ก็มากขึ้นเป็นเงาตามตัวเช่นเดียวกัน  การพัฒนาก็เริ่มมอง หา solution ทำจะช่วยแก้ปัญหาโดยต้องใช้ เวลา และ แรงงาน  ไม่มากนัก  และ RTF ก็เป็น solution หนึ่งที่ น่าสนใจเป็นอย่างยิ่ง ครับ Real-Time Framework หรือ RTF คือ middleware ที่จะช่วยให้เราสามารถเปลี่ยน Single-Server ให้เป็น Multi-Server online game ครับ  อ้างจาก cast study ที่อ้างอิงในบทความนี้ นะครับว่า  game ประเภท [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=394&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>ได้มีโอกาสร่วมอยู่ในงานวิจัย และพัฒนาเกมที่เป็นกึ่ง ๆ online game  แบบ single-server ซึ่ง เดินมาถึงจุดที่ single &#8211; server ไม่สามารถให้บริการได้เนื่องจาก มี ผู้ใช้มากขึ้น และจำนวน object หรือ entity ก็มากขึ้นเป็นเงาตามตัวเช่นเดียวกัน  การพัฒนาก็เริ่มมอง หา solution ทำจะช่วยแก้ปัญหาโดยต้องใช้ เวลา และ แรงงาน  ไม่มากนัก  และ RTF ก็เป็น solution หนึ่งที่ น่าสนใจเป็นอย่างยิ่ง ครับ</p></blockquote>
<p>Real-Time Framework หรือ RTF คือ middleware ที่จะช่วยให้เราสามารถเปลี่ยน Single-Server ให้เป็น Multi-Server online game ครับ  อ้างจาก cast study ที่อ้างอิงในบทความนี้ นะครับว่า  game ประเภท Fast-paced action เช่น First Persons Shooters หรือ FPS นั้น หากต้องการความสามารถ ในการ ขยายระบบรองรับผู้เล่นจำนวนมาก แล้วละก็ ต้องมี สถาปัตยกรรม แบบ multi-server ถึง จะทำได้  แต่การทำ mult-server นั้นเป็นงานที่ท้าทายต่อผู้พัฒนา  เนื่องจาก การประมวลผลจะต้องเป็นการประมวลผลแบบ ขนาน และการ distribute game state  ก็ต้องทำอย่าง มีประสิทธิภาพ  ครับ สองงานหลัก ๆ ที่ game แบบ multi-server นั้นต้อง จัดการให้ได้ ก็คือ เรื่องของการ ทำให้เป็นการประมวลผลแบบขนาน และ การประสานงาน การแจกจ่ายสถานะของ game ให้ได้ประสิทธิภาพ</p>
<p>เนื่องจากว่า มุมมองที่เราจะนำ RTF มาใช้งานก็คือผู้พัฒนา ที่มี game ที่เป็น single-server เป็นของตัวเองอยู่แล้ว และต้องการ ปรับปรุง ให้เป็น multi-server โดยที่ไม่ต้องไปลือระบบของตัวเอง จนแทบจะเรียกได้ว่า ต้องทำกันไหม อะไร แบบนั้นอะครับ  เนื่องจากว่า RTF นั้น จะช่วย ในเรื่องของ การทำ parallelization  และ การจัดการกับ game state โดยเฉพาะในเรื่องของการแจกจ่าย game state ให้อัตโนมัติ  ผุ้พัฒนาที่ใช้ RTF ไม่ต้องเข้าไปดำเนินการเรื่องนี้ เพียงแค่เรียกใช้ผ่าน hight level support ของ RTF เท่านั้นเอง</p>
<p>เพื่อให้ภาพนะครับ ดูจากภาพ แรก</p>
<p><a href="http://gpluspluss.files.wordpress.com/2010/07/quake1.jpg"><img class="aligncenter size-medium wp-image-402" title="quake1" src="http://gpluspluss.files.wordpress.com/2010/07/quake1.jpg?w=317&#038;h=212" alt="" width="317" height="212" /></a>จากภาพเป็นโครงสร้างและการทำงานของ game แบบ single-server นะครับ จะเห็นว่า server เพียงตัวเดียวควบคุมการทำงานทั้งหมด  การคำนวน game states การโต้ตอบกับ ผู้ใช้ และการกระจาย game states กลับไปให้ client ทั้งหมด  ครับ รูปต่อไป</p>
<p style="text-align:left;"><a href="http://gpluspluss.files.wordpress.com/2010/07/quake2.jpg"></a><a href="http://gpluspluss.files.wordpress.com/2010/07/quake2.jpg"><img class="aligncenter size-full wp-image-403" title="quake2" src="http://gpluspluss.files.wordpress.com/2010/07/quake2.jpg?w=600" alt=""   /></a><br />
จากภาพแสดงให้เป็น สถาปัตยกรรมแบบ Multi-server game จะเห็นว่า งานการประมวลผล game state การโต้ตอบกับผู้ใช้และการ กระจาย game state นั้นถูกแบ่งออกไป ให้ server อื่น ๆ ช่วยทำงาน  ซึ่งจะเห็นได้ว่า แน่นอนครับการขยายระบบ การเพิ่มจำนวนผู้เล่น ย่อมเกิดขึ้นได้ โดยสถาปัตยกรรมแบบ mult-server</p>
<p style="text-align:left;">ปัญหาคือว่า ผู้พัฒนาที่มี game ที่เป็น single-server อยู่ในมือจะทำให้เป็น mult-server ได้ด้วย RTF อย่างไร     (ตามที่ได้กล่าวไปแล้วว่า RTF จะช่วยให้ เราเปลี่ยจาก single-server เป็นเป็น Multi-server ได้) จะขอไว้ต่อใน คราวหน้านะครับ</p>
<p style="text-align:left;">s_teerapong2000@yahoo.com &#8211; <a href="http://www.sssolution.net">Soft Speed Solution</a></p>
<p>Reference<br />
[From a Single- to Multi-Server Online Game: A Quake 3 Case Study Using RTF  , Alexander Ploss, Stefan Wichmann, Frank Glinka , and Sergei Gorlatch  University of Munster, Germany]</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gpluspluss.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gpluspluss.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gpluspluss.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gpluspluss.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gpluspluss.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gpluspluss.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gpluspluss.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gpluspluss.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gpluspluss.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gpluspluss.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gpluspluss.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gpluspluss.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gpluspluss.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gpluspluss.wordpress.com/394/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gpluspluss.wordpress.com&amp;blog=4155951&amp;post=394&amp;subd=gpluspluss&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://gpluspluss.wordpress.com/2010/07/07/real-time-framework-single-to-multi-server-online-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/e4c28aeaced12ec496a7165fb995826d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Teerapong S.</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2010/07/quake1.jpg?w=300" medium="image">
			<media:title type="html">quake1</media:title>
		</media:content>

		<media:content url="http://gpluspluss.files.wordpress.com/2010/07/quake2.jpg" medium="image">
			<media:title type="html">quake2</media:title>
		</media:content>
	</item>
	</channel>
</rss>
