【发布时间】:2016-04-04 08:44:12
【问题描述】:
`int[,] board = new int[6, 7]; 图片框板pb =新图片框(); 图片框[] pb = 新图片框[42]; 图像表,红色,蓝色; int c = 0;
public Form1()
{
InitializeComponent();
red = Properties.Resources.red; red = (Image)(new Bitmap(red, new Size(110, 110)));
blue = Properties.Resources.blue; blue = (Image)(new Bitmap(blue, new Size(110, 110)));
table = Properties.Resources.Board; table = (Image)(new Bitmap(table, new Size(700, 700)));
boardpb.Location = new Point(0, 0);
boardpb.Image = table;
boardpb.Size = table.Size;
boardpb.BackColor = Color.Transparent;
boardpb.MouseClick += new MouseEventHandler(Human_Play);
this.Controls.Add(boardpb);
}
void PlayCircle(int x, int y, Image im) //plays a red/blue circle in the corresponding (y,x) position
{
pb[c] = new PictureBox();
pb[c].Location = new Point((int)(-2 + 98.8 * x), (int)(83 + 94.4 * y));
pb[c].Image = im;
pb[c].Size = im.Size - new Size(10, 10);
pb[c].BackColor = Color.Transparent;
pb[c].MouseClick += new MouseEventHandler(Human_Play);
boardpb.Controls.Add(pb[c]);
c++;
}
int Y(int x) // gives the lowest empty space in the column, or -1 if the column is full.
{
for (int y = 5; y >= 0; y--)
if (board[y, x] == 0) return y;
return -1;
}
void Human_Play(object sender, MouseEventArgs e)
{
int x, y;
x = (Cursor.Position.X) / 99;
if ((x <= 6) && (x >= 0))
{
y = Y(x);
if (y != -1)
{
PlayCircle(x, y, red);
board[y, x] = -1;
}
}
}`
我正在使用 WinForms C# 在我的 uni 项目中制作一个 connect 4 游戏。在试图让棋子落入棋盘时,它们就像在棋盘图像下移动,将棋盘线隐藏在它们身后。 知道如何使棋子图像在板后面移动,但仍然可以通过板孔看到(如以下链接中的图片)? PS:板子和2张图片确实有透明背景。 提前谢谢^^ http://mathworld.wolfram.com/images/gifs/connect4.gif 更新:我添加了代码。 (表格,红色,蓝色是我资源中的 3 张图片) 如何编辑这段代码,让棋子落在棋盘后面而不是直接弹出?
【问题讨论】:
-
请描述更多关于您解决问题的编码方法...thanx
-
在我看来,您可能只需要 2 个动画,一个用于红色,一个用于黑色穿过一个单元格。
-
您的问题解决了吗?
-
你给我的解决方案听起来不错,但我没有尝试过,但我专注于项目中的其他功能,比这个动画更重要。非常感谢:D @TaW
-
好吧,如果你回来有问题,一定要问!