"Original" Pure oo: Write a flappybird from design to coding (vi)

Source: Internet
Author: User
Tags gety

Part V please see here

Finally to the last part!

The Simplejudge class is used here to implement the Judge interface.

The first is the instance variable that Simplejudge needs:

0, Final linkedlist<pillar> tmp; Log list of columns returned by obstacle
1, Pillar now; Mark the current column
2, private int bottom; Mark Bottom

Simplejudge There is a more important method, that is Isgameover (Bing bing,obstacle obs), the method returns 0 o'clock, the game is over; back to 1 o'clock, the game continues; return 2 o'clock, continue to add a point at the same time.

Each case is discussed below.

End of game:

0, the bird (Shore) hit the bottom.

1, the bird (shore) hit the pillar.

Game Bonus points:

0, just through the "Current" column (the concept of the current pillar is more important, one will say. )

The game continues:

0, other than the circumstances

Now focus on the concept of "current" pillars.

The so-called current column refers to or is going through, or will be the first to cross a pillar. Gee, that's a bit of a mouthful, for instance. For example, the first pillar at the beginning of the game is the current pillar, and the second pillar becomes the current pillar after it has finished.

The original idea is to use iterators, the result of dynamic modification of the container, Java iterator will throw Exception,damn. Coach, I need to change python!.

This can only be retreated. Second, use a now variable to mark the current column, and when passing through the current column, Traverse LinkedList, returning the first column with a value greater than Bing as the new current column, plus points.

This also makes the coupling between the Simplejudge class and the Simpleobstacle class greatly increased. The design here is not very satisfied, but there is no other solution, save the rectification bar.

How to judge the death and death, you can refer to the source code.

Simplejudge all the code:

ImportJava.util.*;InterfaceJudge { Public intisgameover (Bing fang,obstacle obs);}classSimplejudgeImplementsJudge {FinalLinkedlist<pillar>tmp;    Pillar now; Private intBottom; Simplejudge (Bing fang,obstacle obs) {tmp=Obs.getobstacles ();  This. Bottom = 600-fang.getheight (); now=Tmp.peek (); }         Public intIsgameover (Bing fang,obstacle obs)//0 means dead, 1 is live, 2 means score.    {        if(Fang.gety () + fang.getheight () >= bottom)//hit the bottom            return0; if(NOW.GETWIDLMT () + now.getx () <= fang.getx ())//just scored .        {             for(Pillar p:tmp) {if(P.getx () >Fang.getx ()) { Now=p;  Break; }            }            return2; }        if(Fang.getx () < Now.getx ())//Not dead or scored .            return1; if(Fang.gety () > Now.getheight () && fang.gety () + fang.getheight () < Now.getheight () + now.getheigap ())//To die with a pillar .            return1; Else            return0; }}

Well, this series is over.

Finish

"Original" Pure oo: Write a flappybird from design to coding (vi)

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.