public void init_graphics() { cons.score[0] = cons.score[1] = 0; int t_n = cons.n - cons.n_c; int i, j,sq=0; cons.c_height = (int)ContentPanel.Height; cons.c_width = (int)ContentPanel.Width - 16; cons.square_height = (cons.c_height - cons.edge_width) / cons.n_r; cons.square_width = (cons.c_width - cons.edge_width) / cons.n_c; if (cons.square_height < cons.square_width) cons.square_width = cons.square_height; else cons.square_height = cons.square_width; cons.edge_height = cons.square_width - cons.edge_width; //virtual cons.v_square_height = (cons.c_height - cons.virtual_width) / cons.n_r; cons.v_square_width = (cons.c_width - cons.virtual_width) / cons.n_c; if (cons.v_square_height < cons.v_square_width) cons.v_square_width = cons.v_square_height; else cons.v_square_height = cons.v_square_width; cons.virtual_height = cons.v_square_width - cons.virtual_width; int x = (cons.c_width - (cons.n_c * cons.square_width)) / 2 + 8; int y = (cons.c_height - (cons.n_r * cons.square_width)) / 2; ; cons.sq_corner = new Point(x, y); Debug.WriteLine(cons.sq_corner); can.Width = cons.c_width+16; can.Height = cons.c_height; can.Margin=new Thickness(0,0,0,0); can.HorizontalAlignment = HorizontalAlignment.Center; can.VerticalAlignment = VerticalAlignment.Center; this.ContentPanel.Children.Add(can); edge = new border[cons.n]; brick=new square[cons.n_boxes]; for (i = 0; i < cons.n; i++) { edge[i] = new border(i); } for(i=0;i<cons.n_boxes;i++) { brick[i] = new square(i); } //int x, y; y = (int)cons.sq_corner.Y; for (i = 0; i < cons.n_r; i++) { x = (int)cons.sq_corner.X; for (j = 0; j < cons.n_c; j++) { brick[i * cons.n_c + j].setCorner(new Point(x, y)); x += cons.square_width; } y += cons.square_height; } for (i = 0; i < cons.n_c; i++) { edge[i].add_s(0,i); brick[sq++].add_e(i); } //0=horizontal orientation sq = 0; int edge_index=0; for (i = 0; i < cons.n_r; i++) { sq = i * cons.n_c; for (j = 0; j < cons.n_c + 1; j++) { edge_index = cons.n_c * (i + 1) + (cons.n_c+1) * i + j; if (j == 0) { edge[edge_index].add_s(1, sq); brick[sq].add_e(edge_index); } else if (j == cons.n_c) { edge[edge_index].add_s(1, sq - 1); brick[sq-1].add_e(edge_index); } else { edge[edge_index].add_s(1, sq); brick[sq].add_e(edge_index); edge[edge_index].add_s(1, sq - 1); brick[sq-1].add_e(edge_index); } sq++; } } int squp, sqbelow; squp = 0; sqbelow = cons.n_c; for (i = 1; i < cons.n_r; i++) { for (j = 0; j < cons.n_c; j++) { edge_index = cons.n_c * i + (cons.n_c + 1) * i+j; edge[edge_index].add_s(0, squp); brick[squp].add_e(edge_index); edge[edge_index].add_s(0, sqbelow); brick[sqbelow].add_e(edge_index); squp++; sqbelow++; } } // edge_index = 0; for (i = edge_index+(cons.n_c+1)+1; i < cons.n; i++) { edge[i].add_s(0, squp); brick[squp++].add_e(i); } for (i = 0; i < cons.n; i++) edge[i].draw(can); init_mines(); /* Random rnd = new Random(); int temp = rnd.Next(cons.n_boxes); List<int> l = new List<int>(); for (i = 0; i < cons.num_mines; i++) { while (l.Contains(temp)) { temp = rnd.Next(cons.n_boxes); } l.Add(temp); brick[temp].mine = true; } */ }
public border conv_bor() { border t = new border(); t.index = index; t.left = left; t.top = top; t.orient = o; t.count = count; t.mark = mark; t.sq_index = new int[2]; for (int i = 0; i < count; i++) t.sq_index[i] = ar[i]; return t; }
public void load(border l, Canvas can) { index = l.index; left = l.left; top = l.top; orient = l.orient; count = l.count; mark = l.mark; for (int i = 0; i < count; i++) sq_index[i] = l.sq_index[i]; can.Children.Remove(rect); rect = new Rectangle(); rect.Margin = new Thickness(left, top, 0, 0); if (orient == 0) { rect.Height = cons.edge_width; rect.Width = cons.edge_height; } else { rect.Height = cons.edge_height; rect.Width = cons.edge_width; } if (mark == true) { //ImageBrush imgbrush = new ImageBrush(); //imgbrush.ImageSource = new BitmapImage(new Uri("edge_h.png", UriKind.Relative)); rect.Fill = cons.b_edge; } else { rect.Fill = new SolidColorBrush(Colors.Gray); } rect.MouseLeftButtonDown += new MouseButtonEventHandler(clicked); can.Children.Add(rect); }
public container(border t) { index = t.index; left = t.left; top = t.top; o = t.orient; count = t.count; mark = t.mark; ar = new int[2]; for (int i = 0; i < count; i++) ar[i] = t.sq_index[i]; }