Commit 860fc2f3 authored by 花桃白音's avatar 花桃白音

test

parents 319885f7 34fd0cae
...@@ -385,8 +385,8 @@ namespace cardvisa ...@@ -385,8 +385,8 @@ namespace cardvisa
} }
private void button8_Click(object sender, EventArgs e) private void button8_Click(object sender, EventArgs e)
{ {
PuzzleGame pzg = new PuzzleGame(); PuzzleGame pzg = GenericSingleton<PuzzleGame>.CreateInstrance();
pzg.ShowDialog(); pzg.Show();
} }
public void refreshlist() public void refreshlist()
{ {
...@@ -1206,7 +1206,6 @@ namespace cardvisa ...@@ -1206,7 +1206,6 @@ namespace cardvisa
myListBox.Location = new Point(Location.X - myListBox.Width, Location.Y); myListBox.Location = new Point(Location.X - myListBox.Width, Location.Y);
} }
} }
[Table(Name = "main.datas")] [Table(Name = "main.datas")]
public class datas public class datas
...@@ -1325,6 +1324,22 @@ namespace cardvisa ...@@ -1325,6 +1324,22 @@ namespace cardvisa
public Int64 type { get; set; } public Int64 type { get; set; }
} }
public class GenericSingleton<T> where T : Form, new()
{
private static T t = null;
public static T CreateInstrance() {
if(t==null || t.IsDisposed)
{
t = new T();
}
else
{
t.Activate();
t.WindowState = FormWindowState.Normal;
}
return t;
}
}
public class LittleGame:Form public class LittleGame:Form
{ {
PictureBox pb = new PictureBox(); PictureBox pb = new PictureBox();
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0; this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false; this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
// //
// PuzzleGame // PuzzleGame
...@@ -53,9 +52,9 @@ ...@@ -53,9 +52,9 @@
this.Name = "PuzzleGame"; this.Name = "PuzzleGame";
this.Text = "PuzzleGame"; this.Text = "PuzzleGame";
this.Load += new System.EventHandler(this.PuzzleGame_Load); this.Load += new System.EventHandler(this.PuzzleGame_Load);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.PuzzleGame_Closed);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
......
...@@ -7,36 +7,63 @@ using System.Linq; ...@@ -7,36 +7,63 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using static System.Net.WebRequestMethods;
namespace cardvisa namespace cardvisa
{ {
public partial class PuzzleGame : Form public partial class PuzzleGame : Form
{ {
Graphics gf; Graphics gf;
Graphics gtp;
Graphics gftp;
Image src = new Bitmap(3000, 4200);
Image pictp = new Bitmap(2976, 4175);
Image block = new Bitmap(600,600);
Pen pc = new Pen(Color.Black, 5);
List<List<int>> list = new List<List<int>>{
new List<int>{ 11, 12, 13, 14, 15 },
new List<int>{ 21, 22, 23, 24, 25 },
new List<int>{ 31, 32, 33, 34, 35 },
new List<int>{ 41, 42, 43, 44, 45 },
new List<int>{ 51, 52, 53, 54, 55 },
new List<int>{ 61, 62, 63, 64, 65 },
new List<int>{ 71, 72, 73, 74, 75 }
};
bool picked = false; bool picked = false;
int pickx = 0; int px;
int picky = 0; int py;
int pickx;
int picky;
public PuzzleGame() public PuzzleGame()
{ {
InitializeComponent(); InitializeComponent();
} }
private void PuzzleGame_Load(object sender, EventArgs e) private void PuzzleGame_Load(object sender, EventArgs e)
{ {
pictureBox1.Image = Image.FromFile(Application.StartupPath + "//res//002.jpg"); src = Image.FromFile(Application.StartupPath + "//res//001.jpg");
gf = Graphics.FromImage(pictureBox1.Image); gf = Graphics.FromImage(src);
int imgwd = 2976;//30,5*600*scale gf.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
int imght = 4175;//42,7*600*scale gf.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
drawblock();
} }
private void pictureBox1_Click(object sender, EventArgs e) private void PuzzleGame_Closed(object sender, System.EventArgs e) {
{ gf.Dispose();
gtp.Dispose();
src.Dispose();
if (gftp != null) { gftp.Dispose(); }
pictp.Dispose();
block.Dispose();
src.Dispose();
pictp.Dispose();
block.Dispose();
list.Clear();
Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
} }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{ {
drawblock();
//判断窗体长宽比 //判断窗体长宽比
int px = e.X;
int py = e.Y;
if (pictureBox1.Height > pictureBox1.Width) if (pictureBox1.Height > pictureBox1.Width)
{ {
int picrcht = pictureBox1.Width * 4175 / 2976; int picrcht = pictureBox1.Width * 4175 / 2976;
...@@ -55,12 +82,13 @@ namespace cardvisa ...@@ -55,12 +82,13 @@ namespace cardvisa
py = (py - py % 600) / 600; py = (py - py % 600) / 600;
if (picked) if (picked)
{ {
Bitmap temp = new Bitmap(600,600); gftp = GfHandler(gftp,block);
Graphics gftp = Graphics.FromImage(temp); gftp.DrawImage(src, 0, 0, new Rectangle(pickx * 600, picky * 600, 600, 600), GraphicsUnit.Pixel);
gftp.DrawImage(pictureBox1.Image, 0, 0, new Rectangle(pickx * 600, picky * 600, 600, 600), GraphicsUnit.Pixel); gf.DrawImage(src, pickx * 600, picky * 600, new Rectangle(px * 600, py * 600, 600, 600), GraphicsUnit.Pixel);
gf.DrawImage(pictureBox1.Image, pickx * 600, picky * 600, new Rectangle(px * 600, py * 600, 600, 600), GraphicsUnit.Pixel); gf.DrawImage(block, px * 600, py * 600, new Rectangle(0, 0, 600, 600), GraphicsUnit.Pixel);
gf.DrawImage(temp, px * 600, py * 600, new Rectangle(0, 0, 600, 600), GraphicsUnit.Pixel);
picked = false; picked = false;
drawblock();
pictureBox1.Refresh();
} }
else else
{ {
...@@ -68,17 +96,25 @@ namespace cardvisa ...@@ -68,17 +96,25 @@ namespace cardvisa
picky = py; picky = py;
picked = true; picked = true;
} }
pictureBox1.Refresh();
} }
public void drawblock() public void drawblock()
{ {
Pen pc = new Pen(Color.Black,5); gtp = GfHandler(gtp,pictp);
gtp.DrawImage(src,new Rectangle(0, 0, 2976, 4175));
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
for (int j = 0; j < 7; j++) for (int j = 0; j < 7; j++)
{ {
gf.DrawRectangle(pc, (0 + i) * 600, (0 + j) * 600, 600, 600); gtp.DrawRectangle(pc, (0 + i) * 600, (0 + j) * 600, 600, 600);
} }
} }
pictureBox1.Image = pictp;
}
public Graphics GfHandler(Graphics srcgf,Image img)
{
srcgf = Graphics.FromImage(img);
srcgf.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
srcgf.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
return srcgf;
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment