[Video] compile a Snake Game within half an hour

Source: Internet
Author: User

Outline of snake writing

Thanks:

ThanksRonnie MooneyAfter learning his video, you can find the video in [C #] Creating a Snake Game-Less than an Hour, please bring your own ladder ).

  • WriteInputStatic class

    • Initialize static variablesprivate static readonly Hashtable _keys = new Hashtable()
    • Writing Methodpublic static void ChangeState(Keys key, bool state)
    • Writing Methodpublic static bool Pressed(Keys key)
  • WriteSnakePartClass

    This class has only two variables.XAndYAnd a constructor, the role of the constructor isXAndYAssign values.

  • WriteDirectionEnumeration

  • WriteSnakeFormForm

    • AddPictureBoxControl, namedpbCanvasAnd set the size to 320*240, and the background colorLightSkyBlue
    • Resize a form
    • AddSnakeForm_KeyDownAndSnakeForm_KeyUpEvent
    • AddpbCanvas_PaintEvent. The event processing function is called.draw()
    • Add_scoreVariable
    • Add_gameoverVariable
    • Add_directionVariable
    • Add_snakeList Variables
    • Add_foodVariable
    • Add_gameLoopVariable
    • Add_snakeLoopVariable
    • Add_snakeRateVariable
    • Initialize each variable and set the callback method and callback interval of the timer variable (GameLoop: 1000/60,And start the timer to callstartGame
    • Writing MethodstartGame()
      • Reset variable
      • InstantiationheadAnd add_snake
      • CallgenerateFood
    • WritegenerateFood()
      • Generate a randomSnakePartAnd assigned_foodTo ensure that the newly generated_foodNot a snake
    • Writing Methodgameover()
      • Set_gameoverSettrue
    • Writing Methoddraw()
    • Writing MethodupdateGame()
    • Writing MethodupdateSnake()

Related Article

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.