Time_t time (time_t * timer );// Obtain the system time
Struct TM * gmtime (const time_t * timer );// Convert to TM format
Struct TM * localtime (const time_t * timer );// With Time Zone correction
Char * asctime (const struct TM * timeptr );//
Trial Run
You have done a lot of work. Compile yourCode, Correct all typing errors, and then run the simulator. What does it look like?
It is time for you to put your knowledge into practice. We need the bees to
■ If something goes wrong during running, any statement will throw an exception.
■ UseTry/catchBlock to handle exceptions. unhandled exceptions will be yours.ProgramStop and pop up the error window.
■TryAny exceptions in the
One class throws an exception and the other class captures
When you create a class, you do not know how it will be used. Sometimes others will use your class in a way that causes problems--Sometimes you do the same yourself! In this case,
The benefits of learning can be seen only when something is created.
before writing Code that can work, it's hard to know if you have mastered C # core concepts. In this chapter, we want to learn something
Timer will trigger events again and again
Remember how you used a loop to drive the hound? In fact, we have a better way. TimerIs a particularly useful control, which can trigger events again and again, thousands of times per second.
Do the
Bees need a new outofhoneyException
Your class can throw custom exceptions. For example, if you receive a null value in the methodParameter, but a value is required.. NetThe methods in throw the same exception is very common:
Throw new
The real code is written.
If you can write the code of a class, compile, test it, put it aside, and write another class at one time, it would be good. Unfortunately, this is impossible.
Generally, you will write the code as we do in this chapter. We
Your task is to give toolstripInStartsimulationAndResetButton to compile the event processing method. The following is what each button needs to do:
1.At the beginning, the first button should contain "Start simulation ".", Click it to enable the
Life and death
Our flowers will go through a basic process to grow, increase pollen, harvest pollen, and eventually die:
Q: nectarharvestedVariables seem to be useless in the class except for adding value to them. What is the purpose of
An important principle of object-oriented we use in simulators is encapsulation. Let's see if you can find two encapsulation examples in each class based on the observed classes we have already written.
Below is what we came up with. Have you
We already have four core classes. We need to do some work to connect them. Follow the steps below. But you must know that before you finish, you must modify almost all parts of each class.
① Modify beeTo acceptHiveAndWorld.
Now with
Q: UsingCan only be usedIdisposableInterface object?
A: Yes. IdisposableIs designed to workUsing.
Q: You can go to usingBlock to write any code?
A: Yes. UsingThe purpose is to help you finally dispose of the created object. And what you do with
P. A. H. B (programmers against homeless bees)
We already have bees and pollen-filled flowers. We need to write some code for the bees to collect pollen. But before that, where did the bees first be created? Where did they take pollen? Hive is
The temporary solution (short term) is OKOf
Sometimes you find a problem and know it is a problem, but you do not know how to handle it. In this case, you may want to record it and write down the situation. This is better than handling
Brian finally got a vacation....
Brian nowHe had an exception in control, his work went very smoothly, and he also got a "deserved" (or permitted by the boss) holiday.
... And work is going downhill!
Your exception handling
We already have four core classes. We need to do some work to connect them. Follow the steps below. But you must know that before you finish, you must modify almost all parts of each class.
① Modify beeTo acceptHiveAndWorld.
Now with
③ Update worldCode to pass yourselfHive
Update worldCode to create a newHiveWhen the instance is passed in.
④ Give hiveThe maximum number of bees that can be created
Hive class has oneMaximumbeesConstant, which determinesHiveNumber of bees
Graphics can solve our transparency problems
You may have come up with drawimage.() Method is the key to solving overlapping issues. Let's solve the problem!
①Add a drawbee() Method, which is used to use anyGraphicsObject To draw a bee. It
Use paintEvents to make your images persistent
If the image drawn to the form disappears when the form is blocked, it is not good. Fortunately, there is a simple way to make the image persistent: Write a paintEvent processor. The form is triggered
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