别踩白块.docx

上传人:b****4 文档编号:3733795 上传时间:2022-11-25 格式:DOCX 页数:21 大小:597.41KB
下载 相关 举报
别踩白块.docx_第1页
第1页 / 共21页
别踩白块.docx_第2页
第2页 / 共21页
别踩白块.docx_第3页
第3页 / 共21页
别踩白块.docx_第4页
第4页 / 共21页
别踩白块.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

别踩白块.docx

《别踩白块.docx》由会员分享,可在线阅读,更多相关《别踩白块.docx(21页珍藏版)》请在冰豆网上搜索。

别踩白块.docx

别踩白块

别踩白块C#代码页面一共有三个进入页面,游戏开始页面

游戏运行页面,游戏结束页面

游戏进入页面代码

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.IO;

usingSystem.Linq;

usingSystem.Reflection;

usingSystem.Text;

usingSystem.Windows.Forms;

namespaceNotTheWhite

{

publicpartialclassGameShow:

Form

{

publicGameShow()

{

InitializeComponent();

}

privatevoidbutton1_Click(objectsender,EventArgse)

{

Form1game=newForm1();

game.Show();

//GameShowgashow=newGameShow();

//gashow.Hide();

this.Hide();

//Application.Run(Form1);

}

privatevoidGameShow_Load(objectsender,EventArgse)

{

PicChange();

}

//打包图片文件,使其在脱离其运行环境时也可以运行

publicvoidPicChange()

{

Assemblyasm=Assembly.GetExecutingAssembly();

Streampre=asm.GetManifestResourceStream(@"NotTheWhite.bin.Debug.image.1384480949246.jpg");

this.BackgroundImage=Image.FromStream(pre);

}

}

}

游戏开始页面代码

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.IO;

usingSystem.Linq;

usingSystem.Reflection;

usingSystem.Text;

usingSystem.Windows.Forms;

namespaceNotTheWhite

{

publicpartialclassForm1:

Form

{

string[,]labels=newstring[,]{{"label00","label01","label02","label03"},{"label10","label11","label12","label13"},{"label20","label21","label22","label23"},{"label30","label31","label32","label33"}};

//状态数组,0表示为白色,1便是为黑色,2表示被点击过,应该设置为灰色

int[,]state=newint[,]{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};

publicForm1()

{

InitializeComponent();

}

privatevoidForm1_Load(objectsender,EventArgse)

{

PicChange();

//Label[,]labelstate=newLabel[,]{{label00,label01,label02,label03},{label10,label11,label12,label13},{label,label,label,label},{label,label,label,label}};

intsran;

Randommyrandom=newRandom();

for(inti=0;i<4;i++)

{

sran=myrandom.Next(0,4);

state[i,sran]=1;

}

ShowColor();

//初始界面,最下面一行为黄色

boolnotYellow=true;

for(inti=0;i<4&¬Yellow;i++)

{

if(state[3,i]==1)

{

InitYellow(i);

notYellow=false;

}

}

}

 

privatevoidForm1_MouseClick(objectsender,MouseEventArgse)

{

//Console.WriteLine(MousePosition);

judgewhichClick();

ShowColor();

}

///summary

///判断应该显示什么颜色

///

///summary

publicvoidShowColor()

{

for(inti=0;i<4;i++)

{

for(intj=0;j<4;j++)

{

stringlabelname=labels[i,j];

if(state[i,j]==1)

{

judgewhichBlack(labelname);

}

elseif(state[i,j]==2)

{

judgeGray(labelname);

}

elseif(state[i,j]==0)

{

judgewhichWhite(labelname);

}

}

}

}

///

///判断是哪一个label应该是黑色

///

///

privatevoidjudgewhichBlack(stringlabelname)

{

Control[]con=this.Controls.Find(labelname,true);

for(inti=0;i

{

if(con[i].Name==labelname)

{

con[i].BackColor=Color.Black;

//returncon[i];

}

}

}

///

///判断是哪一个label应该是白色

///

///

privatevoidjudgewhichWhite(stringlabelname)

{

Control[]con=this.Controls.Find(labelname,true);

for(inti=0;i

{

if(con[i].Name==labelname)

{

con[i].BackColor=Color.White;

//returncon[i];

}

}

}

///

///判断是哪一个label应该是灰色

///

///

privatevoidjudgeGray(stringlabelname)

{

Control[]con=this.Controls.Find(labelname,true);

for(inti=0;i

{

if(con[i].Name==labelname)

{

con[i].BackColor=Color.Gray;

}

}

}

///

///判断是哪一个是点错的,点错的设为红色

///

///

///

privatevoidjudgeRed(stringlabelred)

{

Control[]con=this.Controls.Find(labelred,true);

for(inti=0;i

{

if(con[i].Name==labelred)

{

con[i].BackColor=Color.Red;

}

}

}

 

///

///判断是不是第二次点击

///

///

privatevoidjudgewhichClick()

{

boolisgray=true;

//boolisSecend=false;

for(inti=0;i<4;i++)

{

intm;

if(state[2,i]==2)

{

//找出第一个,将第一次点击的灰色变白色

for(m=0;m<4&&isgray;m++)

{

if(state[3,m]==2)

{

state[3,m]=0;

isgray=false;

}

}

MoveTheLast();

//isSecend=true;

}

}

}

///

///将最后一行消失,其余的下移

///

///

privatevoidMoveTheLast()

{

for(inti=2;i>=0;i--)

{

for(intj=0;j<4;j++)

{

//判断是不是黑色的,是就将X坐标加一(即下移)

if(state[i,j]==1)

{

state[i,j]=0;

state[i+1,j]=1;

}

//判断倒数第二行的灰色,并下移

elseif(state[2,j]==2)

{

state[3,j]=2;

state[2,j]=0;

}

}

}

//将设置第一行(如果起一行没有任何黑色的)

boolfirsthave=false;

for(intnotb=0;notb<4;notb++)

{

if(state[0,notb]==1)

{

firsthave=true;

}

}

if(firsthave==false)

{

Randomsran=newRandom();

intran;

ran=sran.Next(4);

state[0,ran]=1;

}

}

///

///判断点击的是白块,若是,则报错

///

privatevoidClickWhite(inti,intj)

{

if(state[i,j]==0)

{

stringlabelred=labels[i,j];

judgeRed(labelred);

//显示错误消息

Control[]con=this.Controls.Find("BtnStop",true);

for(intwhi=0;whi

{

if(con[whi].Name=="BtnStop")

{

con[whi].BackColor=Color.Red;

con[whi].Text="失败!

";

//Form1game=newForm1();

ResultShowresult=newResultShow();

//game.Hide();

this.Hide();

result.Show();

}

}

}

}

///

///初始化界面时,最下面的黄色显示部分的设置

///

privatevoidInitYellow(intred)

{

stringredshow=labels[3,red];

Control[]con1=this.Controls.Find("label30",true);

for(inti=0;i

{

if(con1[i].Name=="label30")

{

con1[i].BackColor=Color.Yellow;

//con1[i].Text="";

}

}

Control[]con2=this.Controls.Find("label31",true);

for(inti=0;i

{

if(con2[i].Name=="label31")

{

con2[i].BackColor=Color.Yellow;

//con2[i].Text="始";

}

}

Control[]con3=this.Controls.Find("label32",true);

for(inti=0;i

{

if(con3[i].Name=="label32")

{

con3[i].BackColor=Color.Yellow;

}

}

Control[]con=this.Controls.Find("label33",true);

for(inti=0;i

{

if(con[i].Name=="label33")

{

con[i].BackColor=Color.Yellow;

}

}

//将本是黑色的在显示为黑色

Control[]conred=this.Controls.Find(redshow,true);

for(inti=0;i

{

if(conred[i].Name==redshow)

{

conred[i].BackColor=Color.Black;

}

}

}

///

///将点击过的label的状态变为2

///

///

///

privatevoidlabel1_Click(objectsender,EventArgse)

{

ClickWhite(0,0);

state[0,0]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel01_Click(objectsender,EventArgse)

{

ClickWhite(0,1);

state[0,1]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel02_Click(objectsender,EventArgse)

{

ClickWhite(0,2);

state[0,2]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel03_Click(objectsender,EventArgse)

{

ClickWhite(0,3);

state[0,3]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel10_Click(objectsender,EventArgse)

{

ClickWhite(1,0);

state[1,0]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel11_Click(objectsender,EventArgse)

{

ClickWhite(1,1);

state[1,1]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel12_Click(objectsender,EventArgse)

{

ClickWhite(1,2);

state[1,2]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel13_Click(objectsender,EventArgse)

{

ClickWhite(1,3);

state[1,3]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel20_Click(objectsender,EventArgse)

{

ClickWhite(2,0);

state[2,0]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel21_Click(objectsender,EventArgse)

{

ClickWhite(2,1);

state[2,1]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel22_Click(objectsender,EventArgse)

{

ClickWhite(2,2);

state[2,2]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel23_Click(objectsender,EventArgse)

{

ClickWhite(2,3);

state[2,3]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel30_Click(objectsender,EventArgse)

{

ClickWhite(3,0);

state[3,0]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel31_Click(objectsender,EventArgse)

{

ClickWhite(3,1);

state[3,1]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel32_Click(objectsender,EventArgse)

{

ClickWhite(3,2);

state[3,2]=2;

judgewhichClick();

ShowColor();

}

privatevoidlabel33_Click(objectsender,EventArgse)

{

ClickWhite(3,3);

state[3,3]=2;

judgewhichClick();

ShowColor();

}

publicvoidPicChange()

{

Assemblyasm=Assembly.GetExecutingAssembly();

Streampre=asm.GetManifestResourceStream(@"NotTheWhite.bin.Debug.image.1234.png");

this.BackgroundImage=Image.FromStream(pre);

}

}

}

 

游戏结束页面代码

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.IO;

usingSystem.Linq;

usingSystem.Reflection;

usingSystem.Text;

usingSystem.Windows.Forms;

namespaceNotTheWhite

{

publicpartialclassResultShow:

Form

{

publicResultShow()

{

InitializeComponent();

}

privatevoidbutton1_Click(objectsender,EventArgse)

{

Form1game=n

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1