Commit 34fd0cae authored by 花桃白音's avatar 花桃白音

chache offset

parent f30b86c7
No preview for this file type
......@@ -324,8 +324,8 @@ namespace cardvisa
}
private void button8_Click(object sender, EventArgs e)
{
PuzzleGame pzg = new PuzzleGame();
pzg.ShowDialog();
PuzzleGame pzg = GenericSingleton<PuzzleGame>.CreateInstrance();
pzg.Show();
}
public void refreshlist()
{
......@@ -1095,7 +1095,6 @@ namespace cardvisa
{
picViewer.Location = new Point(Location.X + Size.Width, Location.Y);
}
}
[Table(Name = "main.datas")]
......@@ -1215,6 +1214,22 @@ namespace cardvisa
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
{
PictureBox pb = new PictureBox();
......
......@@ -41,7 +41,6 @@
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// PuzzleGame
......@@ -53,9 +52,9 @@
this.Name = "PuzzleGame";
this.Text = "PuzzleGame";
this.Load += new System.EventHandler(this.PuzzleGame_Load);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.PuzzleGame_Closed);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
......
......@@ -7,36 +7,63 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.WebRequestMethods;
namespace cardvisa
{
public partial class PuzzleGame : Form
{
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;
int pickx = 0;
int picky = 0;
int px;
int py;
int pickx;
int picky;
public PuzzleGame()
{
InitializeComponent();
}
private void PuzzleGame_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(Application.StartupPath + "//res//002.jpg");
gf = Graphics.FromImage(pictureBox1.Image);
int imgwd = 2976;//30,5*600*scale
int imght = 4175;//42,7*600*scale
}
private void pictureBox1_Click(object sender, EventArgs e)
{
src = Image.FromFile(Application.StartupPath + "//res//001.jpg");
gf = Graphics.FromImage(src);
gf.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
gf.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
drawblock();
}
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)
{
drawblock();
//判断窗体长宽比
int px = e.X;
int py = e.Y;
{
//判断窗体长宽比
if (pictureBox1.Height > pictureBox1.Width)
{
int picrcht = pictureBox1.Width * 4175 / 2976;
......@@ -55,30 +82,39 @@ namespace cardvisa
py = (py - py % 600) / 600;
if (picked)
{
Bitmap temp = new Bitmap(600,600);
Graphics gftp = Graphics.FromImage(temp);
gftp.DrawImage(pictureBox1.Image, 0, 0, new Rectangle(pickx * 600, picky * 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(temp, px * 600, py * 600, new Rectangle(0, 0, 600, 600), GraphicsUnit.Pixel);
gftp = GfHandler(gftp,block);
gftp.DrawImage(src, 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(block, px * 600, py * 600, new Rectangle(0, 0, 600, 600), GraphicsUnit.Pixel);
picked = false;
drawblock();
pictureBox1.Refresh();
}
else
{
pickx = px;
picky = py;
picked = true;
}
pictureBox1.Refresh();
}
}
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 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;
}
}
}
11d8a6c81bf023b013372db283fc0eabd2d9dd57
7031c411217b86b1091719eb16b03e49c28e3de44249a7088da78caf0a610903
......@@ -54,3 +54,4 @@ C:\Users\Administrator\source\repos\cardvisa\cardvisa\bin\Debug\cardvisa.pdb
E:\project\visa\cardvisa\cardvisa\obj\Debug\cardvisa.PicViewer.resources
C:\Users\Administrator\source\repos\cardvisa\cardvisa\obj\Debug\cardvisa.PicViewer.resources
E:\project\visa\cardvisa\cardvisa\obj\Debug\cardvisa.PuzzleGame.resources
C:\Users\Administrator\source\repos\cardvisa\cardvisa\obj\Debug\cardvisa.PuzzleGame.resources
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