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 square conv_sq() { square t = new square(); t.index = index; t.left = left; t.top = top; t.own = o; t.count = count; t.mark = mark; t.num_e = num_e; t.mine = mine; // t.corner = corner; t.edge = new int[4]; for (int i = 0; i < count; i++) t.edge[i] = ar[i]; return t; }
public void load(square l, Canvas can) { index = l.index; left = l.left; top = l.top; count = l.count; num_e = l.num_e; mark = l.mark; own = l.own; //1- user 2-computer mine = l.mine; corner = l.corner; rect = l.rect; for (int i = 0; i < count; i++) edge[i] = l.edge[i]; can.Children.Remove(rect); rect = new Rectangle(); rect.Margin = new Thickness(left, top, 0, 0); rect.Height = rect.Width = cons.square_width - cons.edge_width; if (mark == true) { if (mine == true) { rect.Fill = cons.bomb; } else if (own == cons.broken) { rect.Fill = cons.burst; } else if (own == Player.User) { rect.Fill = cons.user; } else if (own == Player.comp) { rect.Fill = cons.comp; } can.Children.Add(rect); } refresh(); }
public container(square t) { index = t.index; left = t.left; top = t.top; o = t.own; count = t.count; mark = t.mark; num_e = t.num_e; mine = t.mine; //corner = t.corner; ar = new int[4]; for (int i = 0; i < count; i++) ar[i] = t.edge[i]; }