X01.Weiqi. 7: Adjust the re-painting, x01.weiqi. 7

Source: Internet
Author: User

X01.Weiqi. 7: Adjust the re-painting, x01.weiqi. 7

GitHub

Who is convenient, who is important. A good ecosystem is particularly important in this age of bricks and mortar.

   Blushing and small hair, it's easy.

Maybe it's just because of the fire of fish.

When yao beifuwa leaves, it is also important to live and do meaningful things in addition to lamenting the impermanence of life.

I wrote the go program to learn AI a few years ago, but I found that it was more difficult than I thought. Put it on GitHub. I hope someone can make an axe. Note that it is an ax, not a minor fix.

Adjust re-painting

When the window size changes, the Board must be re-painted accordingly. This is relatively simple. My method is to change the m_sbSteps field in the BoardBase class to public and save it in the MainWindows main window. For specific operations, refer to the methods in the StepBoard class, copy and paste, and make slight modifications. The Code is as follows:

1 // For Size Change and Show Number 2 3 List <StepContent> m_steps = new List <StepContent> (); 4 public void FillSteps () 5 {6 m_steps.Clear (); 7 string s = m_sbSteps.ToString (); 8 if (s. length <1) return; 9 string [] steps = s. substring (0, s. length-1 ). split (','); 10 StepContent step = new StepContent (); 11 for (int I = 0; I <steps. length; I ++) 12 {13 if (I % 3 = 0) 14 {15 step = new StepContent (); 1 6 step. col = Convert. toInt32 (steps [I]); 17} 18 else if (I % 3 = 1) 19 {20 step. row = Convert. toInt32 (steps [I]); 21} 22 else if (I % 3 = 2) 23 {24 step. count = Convert. toInt32 (steps [I]); 25 m_steps.Add (step); 26} 27} 28} 29 public void RenderChess () 30 {31 m_sbSteps.Clear (); 32 foreach (var item in m_steps) 33 {34 NextOne (); 35} 36} 37 38 int m_count = 1; 39 public void NextOne () 40 {41 if (m_count> m_steps. Count) 42 {43 return; 44} 45 46 foreach (var item in m_steps) 47 {48 if (item. count = m_count) 49 {50 int col = item. col; 51 int row = item. row; 52 53 if (Steps [col, row]. color! = ChessColor. empty) 54 {55 return; 56} 57 58 if (NotInPos. X = col & NotInPos. Y = row) 59 {60 return; 61} 62 else63 {64 // If Pos (struct) is property, must use new.65 NotInPos = new Pos (-1, -1); 66} 67 68 DrawChess (col, row); 69 70 Eat (col, row); 71} 72} 73 m_count ++; 74} 75 76 public bool IsShowNumber {get; set ;}For size change

Display steps

In order to display the number of steps, several attributes are added to the Chess class, and corresponding adjustments are made in the DrawChess method of BoardBase. The Code is as follows:

1 public string NumberText 2 {3 get {return m_TxtNumber.Text;} 4 set {m_TxtNumber.Text = value;} 5} 6 7 public double NumberFontSize 8 {9 get {return m_TxtNumber.FontSize ;} 10 set {m_TxtNumber.FontSize = value;} 11} 12 13 public System. windows. thickness NumberPadding14 {15 get {return m_TxtNumber.Padding;} 16 set {m_TxtNumber.Padding = value;} 17}Chess properties 1 if (Steps [col, row]. chess = null) 2 {3 Chess chess = new Chess (brush, ChessSize); 4 if (IsShowNumber) 5 {6 double size = (double) ChessSize; 7 chess. numberFontSize = (m_StepCount + 1)> 99 8? Size/2: (m_StepCount + 1)> 9 9? Size/1.6: size/1.2; 10 chess. NumberPadding = (m_StepCount + 1)> 9911? New Thickness (size/28, size/5.5, 0, 0): (m_StepCount + 1)> 912? New Thickness (size/8, size/8, 0, 0): new Thickness (size/4, 0, 0, 0); 13 chess. numberText = (m_StepCount + 1 ). toString (); 14 chess. numberBrush = (m_StepCount % 2 = 1 )? Brushes. black: Brushes. white; 15} 16 chess. setShow (IsShowNumber); 17 Canvas. setLeft (chess, left); 18 Canvas. setTop (chess, top); 19 m_Canvas.Children.Add (chess); 20 Steps [col, row]. chess = chess; 21}In the DrawChess ()

Code download link:Https://github.com/chinax01/x01.Weiqi

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.