protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics dc = e.Graphics; for (int i = 0; i < COLPICS; i++) { for (int j = 0; j < ROWPICS; j++) { PicState ps = picState[i * ROWPICS + j]; if (ps.bShown == false) { continue; } Image image = pics[ps.nPicId]; dc.DrawImage(image, ps.picRectangle); } } //绘制选中线 if (picSelector.curSelector == 0 && picState[picSelector.picStateId[1]].bShown) { dc.DrawRectangle(LinePen, picState[picSelector.picStateId[1]].picRectangle); } if (picSelector.curSelector == 1) { dc.DrawRectangle(LinePen, picState[picSelector.picStateId[0]].picRectangle); } //绘制连通线 if (picSelector.bLinkOk) { dc.DrawRectangle(LinePen, picState[picSelector.picStateId[1]].picRectangle); dc.DrawLines(LinePen, picSelector.linkPoints); } }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); //隐藏已经连通的图片 if (picSelector.bLinkOk) { picSelector.bLinkOk = false; picSelector.curSelector = 0; for (int i = 0; i < 2; i++) { PicState ps = picState[picSelector.picStateId[i]]; ps.bShown = false; sceneState[ps.sceneX, ps.sceneY].bLinkable = true; } force_redraw(); if (!check_pic_match()) { if (check_win()) { this.GameTimer.Enabled = false; this.lbl_win.Show(); } else { lbl_nomatch.Show(); showNoMatchTime = UseTime + 1; } } } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); //初始化场景全部点坐标 for (int i = 0; i < COLPICS + 2; i++) { for (int j = 0; j < ROWPICS + 2; j++) { sceneState[j, i] = new SceneState(); sceneState[j, i].scenePoint = new Point(j * (PICSIZE + 2) + PICSIZE / 2 + 1, i * (PICSIZE + 2) + PICSIZE / 2 + 1); } } //加载图片资源 for (int i = 0; i < PICCOUNT; i++) { //pics[i] = Image.FromFile(string.Format("item/war ({0}).gif", i + 1)); pics[i] = this.picList.Images[i]; } //选出图片id for (int i = 0; i < usePicIds.Length; i++) { int id = ran.Next(0, PICCOUNT); usePicIds[i] = id; } //分配图片id for (int i = 0; i < ROWPICS * COLPICS; i++) { picState[i] = new PicState(); picState[i].nPicId = usePicIds[i % usePicIds.Length]; } //图片定位 for (int i = 0; i < COLPICS; i++) { for (int j = 0; j < ROWPICS; j++) { picState[i * ROWPICS + j].sceneX = j + 1; picState[i * ROWPICS + j].sceneY = i + 1; sceneState[j + 1, i + 1].bLinkable = false; picState[i * ROWPICS + j].picRectangle = new Rectangle(PICSIZE + j * (PICSIZE + 2), PICSIZE + i * (PICSIZE + 2), PICSIZE, PICSIZE); } } //打乱图片 shuffle_pics(); while (!check_pic_match()) { shuffle_pics(); } }