Head first C # Chinese Version chapter 12th review and foresight page521

Source: Internet
Author: User

 

 

Any point used
You must add
Using system. Drawing
;.



③ Create a constructor


The constructor of the flower class must accept
Point
To specify the location of the flowers and accept
Random
Class. You should be able to use these variables to set the flower location and age
0
, Set the flower to live, and set its pollen volume to the initial pollen volume of the flower. Since the Division has not been collected, you need to set this variable. Finally, calculate the life of the flowers. The following code can help you:



Lifespan = random. Next (
Lifespanmin
,
Lifespanmax + 1
);

 



④ Write harvestnectar
() Method code



Each time this method is called, it checks whether the pollen volume collected in each lifecycle is greater than the remaining pollen volume. If yes, 0 is returned.
. Otherwise, the pollen volume collected in this lifecycle should be subtracted from the remaining pollen volume and the amount of pollen collected will be returned. Oh, don't forget to add this amount
Nectarharvested
It records the total amount of pollen collected from a flower.

Tip: we only use nectargatheredperturn in this method.
,
Nectar
And
Nectarharvested
.

 



⑤ Write go
() Method code



This method leads to flowers getting older. Assume that every time this method is called, a life cycle will pass away, so we need to update the age of flowers appropriately. You also need to see if the age is longer than the lifetime of the flowers. If yes, the flowers die.


If the flowers are still alive, you need to add them to the pollen volume that the flowers get in each lifecycle. Make sure to check the maximum amount of pollen that the flowers can hold. Do not exceed that value.


In the end, we will make it animated, and there will be pictures of bees flying around. Go
() The method is called every frame, and several frames are called every second.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.