Learn VB .NET Through Game Programming [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Learn VB .NET Through Game Programming [Electronic resources] - نسخه متنی

Matthew Tagliaferri

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید





Putting the Die in Its Place

The program can now handle drawing a single die frame onto a PaintPanel control, but it hasn’t decided yet where to draw it or how to select which frame to draw. The initial location of the die is selected in the Form_Load event, as shown in Listing 1-11.

Listing 1.11: Choosing the Initial Die Location



oRand = New Random(Now.Ticks Mod 100)
<code deleted>
diexPos = oRand.Next(0, pnLower.Width - w)
dieyPos = oRand.Next(0, pnLower.Height - h)
DrawDie()



Here, the event uses the variable named oRand. The variables diexPos and dieyPos are initialized to some random number between 0 and the width/height of the panel less the width/height of a die frame (stored in the constants w and h, respectively). If the width/height of a die frame isn’t subtracted, the die could easily be plopped partially off the right/bottom edge of the panel, as shown in Figure 1-13.


Figure 1-13: This shows why the range for placement of the die is the width of the panel less the width of the die frame. Ditto for the height.

/ 106