Оценить:
 Рейтинг: 0

Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 7: Программирование на Visual C# искусственного интеллекта. Издание 2

Год написания книги
2023
Теги
<< 1 ... 28 29 30 31 32 33 34 >>
На страницу:
32 из 34
Настройки чтения
Размер шрифта
Высота строк
Поля

new Bitmap(myAssembly.GetManifestResourceStream(

myName_of_project + "." + "tomato.gif"));

//We initialize an array of new objects and rectangles,

//described around these objects:

initialiseTomatoes();

//We place new objects in an upper part of the screen:

placeTomatoes();

//We create and initialize a font for record of points:

messageFont = new Font(FontFamily.GenericSansSerif, 10,

FontStyle.Regular);

//We reserve a rectangle on the screen

//for record of points:

messageRectangle = new Rectangle(0, 0,

this.ClientSize.Width, scoreHeight);

//We set the color of a brush for record of points:

messageBrush = new SolidBrush(Color.Black);

//We turn on the timer:

timer1.Enabled = true;

} //End of the method Form1_Load.

И наконец, вместо приведённого выше метода updatePositions записываем следующий метод, дополненный новым кодом для изменения координат, обнаружения столкновений объектов, уничтожения помидоров и подсчёта очков.

Листинг 5.11. Метод для изменения координат и обнаружения столкновения объектов.

private void updatePositions()

{

if (goingRight)

{

cx += xSpeed;

}

else

{

cx -= xSpeed;

}

if ((cx + cheeseImage.Width) >= this.Width)

{

goingRight = false;

//At the time of collision, the Beep signal is given:

Microsoft.VisualBasic.Interaction.Beep();

}

if (cx <= 0)

{

goingRight = true;

//At the time of collision, the Beep signal is given:

Microsoft.VisualBasic.Interaction.Beep();

}

if (goingDown)

{

cy += ySpeed;

}

else

{

cy -= ySpeed;
<< 1 ... 28 29 30 31 32 33 34 >>
На страницу:
32 из 34

Другие электронные книги автора Валерий Алексеевич Жарков