www.pudn.com > LINkSee.rar > Game.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using LinkSee.Properties;
using System.IO;
using System.Drawing.Drawing2D;
namespace LinkSee
{
public partial class Game : Form
{
protected Graphics gcPhisical = null;//前
protected Graphics gcOff = null;//离屏
protected Bitmap bitmapoff = null;// 位图
protected Bitmap bitmapBack = null;//背景
protected Bitmap bitchange = null;//交换暂存
private Image[] bomb = new Image[6];
protected bool paused = false;
public int lasttime =0;
public int time = 0;
public int type_max = 5;
private Cards Cards = null;
protected ImageAttributes imageAttr = null;
protected ImageAttributes imageAttr1 = null;
protected Random random = new Random();
protected Congratulation infor = new Congratulation();
protected Victory vict = new Victory();
protected bool running = true;
public Sound sound = new Sound(@"Resouces\camera.wav");
public Random Random
{
get
{
return this.random;
}
}
public Game()
{
InitializeComponent();
this.WriteFile();
this.lasttime = this.vict.ReadMark();//*******************************8
Init();
Mainloop();
}
private void Mainloop()
{
while (running)
{
if (this.Cards.isAllcardHide())
{
this.timer.Enabled = false;
this.timer1.Enabled = false;
this.infor = new Congratulation(this.time,this.type_max);
this.vict = new Victory(this.time ,this.type_max);
if (this.time < this.lasttime)
{
this.vict.ShowDialog();
}
this.infor = new Congratulation(this.time, this.type_max);
this.time = 0;
DialogResult dr = this.infor.ShowDialog();
if (dr== DialogResult.No)
{
this.gcPhisical.Dispose();
this.Close();
this.running = false;
}
else
{
this.type_max = this.infor.Type;
this.vict = new Victory(this.time, this.type_max);
//MessageBox.Show(this.type_max.ToString());
this.lasttime = this.vict.ReadMark();
Init();
Mainloop();
}
}
Application.DoEvents();//响应用户操作
processAll();
DrawAll();
}
Close();//关闭窗体
}
private void processAll()
{
this.Cards.process();
}
private void DrawAll()
{
try
{
this.gcOff.DrawImage(this.bitmapBack, 0, 0);
this.Cards.Draw(this.gcOff);
this.gcPhisical.DrawImage(this.bitmapoff, 0, 0);
}
catch (Exception e)
{
//MessageBox.Show(e.ToString());
}
}
private void Init()
{
this.gcPhisical = this.CreateGraphics();//为gcPhisical创建用于绘制图像的 Graphics
this.bitmapoff = Resources.bg;
this.bitmapBack = Resources.bg;//背景图片-bg
this.gcOff = Graphics.FromImage(this.bitmapoff);//为gcOff创建用于绘制图像的Graphics
this.bomb[5] = Resources.B6;
MessageBox.Show("上一次时间:"+this.lasttime.ToString());
this.imageAttr = new ImageAttributes();
this.imageAttr1 = new ImageAttributes();
this.imageAttr.SetColorKey(Color.FromArgb(0,0,0), Color.FromArgb(0, 0,0));
this.imageAttr1.SetColorKey(Color.FromArgb(255,255,255), Color.FromArgb(255, 255,255));
this.Cards = new Cards(this, Resources._28, this.imageAttr);
this.timer.Enabled = true;
this.timer1.Enabled = true;
this.Show();//窗体的显示
}
public void DrawLines(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
Pen pen = new Pen(Color.Red, 5);
this.gcPhisical.DrawLine(pen, x1, y1, x2, y2);
this.gcPhisical.DrawLine(pen, x2, y2, x3, y3);
this.gcPhisical.DrawLine(pen, x3, y3, x4, y4);
}
public void DrawSide(int left, int top, int width, int height)
{
Pen pen = new Pen(Color.Blue, 2);
this.gcPhisical.DrawRectangle(pen, new Rectangle(left, top, width, height));
}
public void DrawBomb(int left, int top)
{
this.gcPhisical.DrawImage(bomb[5], new Rectangle(left-12, top-12, 70, 70), 0, 0, 35, 35, GraphicsUnit.Pixel, this.imageAttr1);
}
private void Game_Load(object sender, EventArgs e)
{
}
private void Game_MouseDown(object sender, MouseEventArgs e)
{
if (e.Y < 28 && e.X > 212)
{
DialogResult dr = MessageBox.Show("你要关闭游戏??", "LinkSee", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
if (dr == DialogResult.Yes)
this.running = false;
}
else
{
this.Cards.Hit(e.X, e.Y);
}
}
private void timer_Tick(object sender, EventArgs e)
{
this.timer.Enabled = false;
this.timer1.Enabled = false;
DialogResult dr = MessageBox.Show("时间到了!!!重新开始 ???", "LinkSee", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
if (dr == DialogResult.Yes)
{
this.time = 0;
Init();
Mainloop();
}
else
{
this.gcPhisical.Dispose();
this.Close();
MessageBox.Show("D字头工作室 Email:tianyi00tiyan@hotmail.com", "LinkSee");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
this.time += 1;
this.minuteshow.Text = (this.time / 60).ToString()+" :";
this.secondshow.Text = (this.time % 60).ToString();
}
catch(Exception a){}
}
private void pause_Click(object sender, EventArgs e)
{
if (this.paused == false)
{
this.timer.Enabled = false;
this.timer1.Enabled = false;
this.gcPhisical = this.CreateGraphics();
this.bitchange = this.bitmapoff;
this.bitmapoff = Resources.over;
this.gcPhisical.DrawImage(this.bitmapoff, 0, 0);
this.paused = true;
}
else
{
this.timer.Enabled = true;//注意时间是否缩水了
this.timer1.Enabled = true;
this.bitmapoff = this.bitchange;
this.gcPhisical.DrawImage(this.bitmapoff, 0, 0);
this.paused = false;
}
}
private void restart_Click(object sender, EventArgs e)
{
this.timer.Dispose();
this.time = 0;
this.type_max = this.infor.Type;
Init();
Mainloop();
}
private void exit_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.Cards.count - 1; i++)
{
this.Cards.cards[i].Visible = false;
}
this.time = 1000000;//**比较大的值就行了
}
public void WriteFile()
{
for (int i=0; i < 4; i++)
{
string path = @"topmark"+i+".txt";
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine((i+1)*5);
sw.WriteLine("yiyi");
sw.WriteLine("100");
}
}
}
}
}
}