c# 屌丝的游戏,是男人就坚持20秒

加旋仔 2012-05-19 05:02:19
昨晚花了2个小时,今天花了4个小时完成的.就是自娱自乐,还有很多问题.自己看吧.
链接:http://download.csdn.net/detail/hlxcoo2007/4314240


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace ManGame
{
public partial class FMain : Form
{
public int[,] ballarray = new int[40, 40];
public FMain()
{
InitializeComponent();
}

private bool _isStart = false;
private bool isStart
{
get { return _isStart; }
set { _isStart = value; }
}

private void tsmExit_Click(object sender, EventArgs e)
{
this.Close();
}

private void tsmChoose_Click(object sender, EventArgs e)
{
FrmDiffcultChoose _fchoose = new FrmDiffcultChoose(this);
_fchoose.ShowDialog();
}

private void tsmAbout_Click(object sender, EventArgs e)
{
FrmAbout _about = new FrmAbout();
_about.ShowDialog();
}

Timer _startTime;
private void tsmNewGame_Click(object sender, EventArgs e)
{
setEnable(false);
ts = 1;
Graphics g = this.CreateGraphics();
drawString(g, "1");
_startTime = new Timer();
_startTime.Interval = 1000;
_startTime.Tick += new EventHandler(OnTick);
_startTime.Start();
}

private void drawString(Graphics _g, string _s)
{
float px = this.ClientSize.Width / 2;
float py = (this.ClientSize.Height / 2) - 40;
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
_g.DrawString(_s, new Font(this.Font.FontFamily, 72), new SolidBrush(Color.Red), px, py, drawFormat);
}

double OverTime = 0;
int ts = 1;
void OnTick(object sender, EventArgs e)
{
this.Refresh();
Graphics g = this.CreateGraphics();
ts += 1;
drawString(g, ts.ToString());
if (ts == 4)
{
this.Refresh();
drawString(g, "翻滚吧,屌丝..");
}
if (ts == 5)
{
isStart = true;
this.timer1.Start();
Random r = new Random();
for (int i = 1; i <= SaveParam.BallNum; i++)
{
ballarray[i, 1] = +r.Next(10) + 5;
ballarray[i, 2] = +r.Next(10) + 5;
ballarray[i, 3] = +r.Next(10) + 5;
ballarray[i, 4] = +r.Next(10) + 5;
}
_startTime.Stop();
}
}

private int x1;
private int y1;
protected override void OnMouseMove(MouseEventArgs m)
{
x1 = m.X;
if (x1 + 40 >= this.Width)
{
x1 = this.Width - 25;
}
else if (x1 - 15 <= 0)
{
x1 = 15;
}
y1 = m.Y;
if (y1 + 60 >= this.Height)
{
y1 = this.Height - 45;
}
else if (y1 - 60 <= 0)
{
y1 = 40;
}
}

private void setEnable(bool _enable)
{
this.tsmAbout.Enabled = _enable;
this.tsmChoose.Enabled = _enable;
this.tsmNewGame.Enabled = _enable;
}

Rectangle _rect;
bool ifOver = false;
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
if (isStart)
{
_rect = new Rectangle();
_rect.X = x1;
_rect.Y = y1;
_rect.Width = 30;
_rect.Height = 30;
int strX = 0;
int strY = 0;
for (int i = 1; i <= SaveParam.BallNum; i++)
{
strX = ballarray[i, 1];
strY = ballarray[i, 2];
g.FillEllipse(new SolidBrush(Color.White), strX, strY, 15, 15);
if (_rect.Contains(strX, strY) || _rect.Contains(strX + 15, strY + 15))
{
timer1.Stop();
ifOver = true;
isStart = false;
break;
}
}
g.FillRectangle(new SolidBrush(Color.Yellow), x1 - 15, y1 - 15, 30, 30);
if (ifOver)
{
MessageBox.Show("能不能坚持久点,是男人就重来,才坚持了" + Convert.ToDouble(OverTime / 1000) + "s", "提示");
g.Clear(Color.Black);
setEnable(true);
ifOver = false;
}
}
}

private void timer1_Tick(object sender, EventArgs e)
{
OverTime += timer1.Interval;
for (int i = 1; i <= SaveParam.BallNum; i++)
{
ballarray[i, 1] = ballarray[i, 1] + ballarray[i, 3];
ballarray[i, 2] = ballarray[i, 2] + ballarray[i, 4];
if ((ballarray[i, 1] + 10) >= this.ClientSize.Width)
{
ballarray[i, 1] = ballarray[i, 1] - ballarray[i, 3];
ballarray[i, 3] = -ballarray[i, 3];
}
else if ((ballarray[i, 2] + 10) >= this.ClientSize.Height)
{
ballarray[i, 2] = ballarray[i, 2] - ballarray[i, 4];
ballarray[i, 4] = -ballarray[i, 4];
}
else if (ballarray[i, 1] <= 1)
{
ballarray[i, 1] = ballarray[i, 1] - ballarray[i, 3];
ballarray[i, 3] = -ballarray[i, 3];
}
else if (ballarray[i, 2] <= 1)
{
ballarray[i, 2] = ballarray[i, 2] - ballarray[i, 4];
ballarray[i, 4] = -ballarray[i, 4];
}
}
this.Refresh();
}
}
}


只发关键代码.
下面上图



...全文
240 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
续写经典 2012-05-19
  • 打赏
  • 举报
回复
貌似很强大
加旋仔 2012-05-19
  • 打赏
  • 举报
回复
正在研究另类的坚持20秒游戏....
Shadow_Gui_Love 2012-05-19
  • 打赏
  • 举报
回复
屌丝只能悄悄旁观……
xboxeer 2012-05-19
  • 打赏
  • 举报
回复
屌丝默泪~
  • 打赏
  • 举报
回复
翻滚吧,屌丝们
doubleu2005 2012-05-19
  • 打赏
  • 举报
回复
怎么玩法?
加旋仔 2012-05-19
  • 打赏
  • 举报
回复
装了.net4.0就行
加旋仔 2012-05-19
  • 打赏
  • 举报
回复
我也是Xp阿..我能玩..
Conmajia 2012-05-19
  • 打赏
  • 举报
回复
另外,能不能不用4.0,搞的我XP都玩不了,还得用2.0重新编译一遍
Conmajia 2012-05-19
  • 打赏
  • 举报
回复
可以哈。让我想起了以前日本人那个坚持20秒。

楼主做个.net复刻版吧,让大家乐呵乐呵
加旋仔 2012-05-19
  • 打赏
  • 举报
回复


cnfixit 2012-05-19
  • 打赏
  • 举报
回复
大家现在都4.0了……
加旋仔 2012-05-19
  • 打赏
  • 举报
回复
图都挂了..
cnfixit 2012-05-19
  • 打赏
  • 举报
回复
试试看……

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧