Android game development-my little game 1-wuziqi Game 3 regret and start over

Source: Internet
Author: User

First, we will draw two buttons on the canvas. We will use two images for representation, one for regret, and the other for re-start. We will use the shortlist to store every step of our operations, then extract the operations of each step from the worker list.

// Bitmap [] button = new bitmap [2];
// Bind the resource button [0] = bitmapfactory to the two buttons. decoderesource (this. getresources (), R. drawable. restart); button [1] = bitmapfactory. decoderesource (this. getresources (), R. drawable. regret );
// Draw the canvas button. drawbitmap (Button [0], screenwidth/2-30-button [0]. getwidth (), 40, paint); canvas. drawbitmap (Button [1], screenwidth/2 + 30, 40, paint );

Add the record operation statement to the touch event function:

Struct list <Map <string, integer> List = new struct list <Map <string, integer> (); Map <string, integer> map = new hashmap <string, integer> (); map. put ("index_x", index_x); // map the X value in the two-dimensional array. put ("index_y", index_y); // list the values of Y in the two-dimensional array. add (MAP );

 

Listen on the touch action in the button range:

// Listen to the button event and restart if (touchx> screenwidth/2-30-button [0]. getwidth () & touchx <screenwidth/2-30 & touchy> 40 & touchy <40 + button [0]. getheight () {for (INT I = 0; I <grid_num; I ++) {for (Int J = 0; j <grid_num; j ++) {chess [I] [J] = 0; winflag = false; chess_flag = 0 ;}}} // regret if (touchx> screenwidth/2 + 30 & touchx <screenwidth/2 + 30 + button [1]. getwidth () & touchy> 40 & touchy <40 + button [1]. getheight () {int size = List. size (); If (chess [list. get (size-1 ). get ("index_x")] [list. get (size-1 ). get ("index_y")] = chess_black) {chess_flag = chess_white; chess [list. get (size-1 ). get ("index_x")] [list. get (size-1 ). get ("index_y")] = 0;} else if (chess [list. get (size-1 ). get ("index_x")] [list. get (size-1 ). get ("index_y")] = chess_white) {chess_flag = chess_black; chess [list. get (size-1 ). get ("index_x")] [list. get (size-1 ). get ("index_y")] = 0;} List. removelast (); // Delete the last operation winflag = false ;}

 

:

After regret:

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.