using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Arkanoid2
{
public partial class FormGame : Form
{
static Random rnd = new Random();
int racket_x, racket_y;
int racket_shift_x = 8;
int ball_x, ball_y;
int ball_shift_x = 4; // max ball shift
int ball_shift_y = 3;
int ball_sx, // current ball shift
ball_sy;
int side_lx,// left x
side_rx,// right x
side_uy;// up y
int total_bricks;
private static Timer atimer;
public FormGame()
{
InitializeComponent();
}
private void FormGame_Shown(object sender, EventArgs e)
{
init_game();
}
private void init_game()
{
racket_x = racket.Location.X;
racket_y = racket.Location.Y;
side_lx = label_left.Location.X + label_left.Width;
side_rx = label_right.Location.X;
side_uy = label_top.Location.X + label_top.Height;
ball_x = ball.Location.X;
ball_y = ball.Location.Y;
ball_sx = ball_shift_x;
ball_sy = -ball_shift_y;
total_bricks = 5;
}
private void FormGame_KeyDown(object sender, KeyEventArgs e)
{
Keys key = e.KeyCode;
switch (key)
{
case Keys.Left: shift_racket(-racket_shift_x); break;
case Keys.Right: shift_racket(racket_shift_x); break;
case Keys.Enter: timer.Enabled = true; break;
}
}
private void shift_racket(int sx)
{
int ax1 = racket_x += sx;
int ax2 = ax1 + racket.Width;
if (side_lx > ax1) ax1 = side_lx;
if (side_rx < ax2) ax1 = side_rx - racket.Width;
racket_x = ax1;
racket.Location = new Point(racket_x, racket_y);
}
private void move_ball()
{
int bx1, by1,
bx2, by2;
bx1 = ball_x;
bx2 = ball_x + ball.Width;
by1 = ball_y;
by2 = ball_y + ball.Height;
if (bx1 + ball_sx < side_lx)
ball_sx = ball_shift_x + rnd.Next(-1, 2);
if (bx2 + ball_sx > side_rx)
ball_sx = -ball_shift_x + rnd.Next(-1, 2);
if (by1 + ball_sy < side_uy)
ball_sy = ball_shift_y + rnd.Next(-1, 2);
if (by2 + ball_sy > racket_y)
{
int bx0, by0;
bx0 = (bx1 + bx2) / 2;
by0 = (by1 + by2) / 2;
int rx1, rx2;
rx1 = racket_x;
rx2 = racket_x + racket.Width;
if (rx1 <= bx0 && bx0 <= rx2)
{
ball_sy = -ball_shift_y + rnd.Next(-1, 2);
}
else
if (rx1 <= bx2 + ball.Width && bx2 + ball.Width <= rx2)
{
ball_sy = -ball_shift_y + rnd.Next(-1, 2);
ball_sx = -ball_shift_x + rnd.Next(-1, 2);
}
else
if (rx1 <= bx1 - ball.Width && bx1 - ball.Width <= rx2)
{
ball_sy = -ball_shift_y + rnd.Next(-1, 2);
ball_sx = ball_shift_x + rnd.Next(-1, 2);
}
else
lose_ball();
}
ball_x += ball_sx;
ball_y += ball_sy;
ball.Location = new Point(ball_x, ball_y);
cross_brick(brick1);
cross_brick(brick2);
cross_brick(brick3);
cross_brick(brick4);
cross_brick(brick5);
}
private void timer1_Tick(object sender, EventArgs e)
{
cont_brick();
}
private void timer_Tick(object sender, EventArgs e)
{
move_ball();
}
private void lose_ball()
{
timer.Enabled = false;
MessageBox.Show("LOST");
DialogResult = System.Windows.Forms.DialogResult.Abort;
}
private void cross_brick(Label brick)
{
if (!brick.Visible) return;
int bx1, bx0, bx2,
by1, by0, by2;
int rx1, rx2,
ry1, ry2;
bx1 = ball_x;
bx2 = ball_x + ball.Width;
bx0 = (bx1 + bx2) / 2;
by1 = ball_y;
by2 = ball_y + ball.Height;
by0 = (by1 + by2) / 2;
rx1 = brick.Location.X;
rx2 = rx1 + brick.Width;
ry1 = brick.Location.Y;
ry2 = ry1 + brick.Height;
if (rx1 <= bx0 && bx0 <= rx2 &&
ry1 <= by2 && by2 <= ry2)
{
drop_brick(brick);
ball_sy = -ball_sy;
return;
}
if (rx1 <= bx2 && bx2 <= rx2 &&
ry1 <= by0 && by0 <= ry2)
{
drop_brick(brick);
ball_sx = -ball_sx;
return;
}
if (rx1 <= bx1 && bx1 <= rx2 &&
ry1 <= by0 && by0 <= ry2)
{
drop_brick(brick);
ball_sx = -ball_sx;
return;
}
if ((rx1 <= bx2 && bx2 <= rx2 && ry1 <= by2 && by2 <= ry2) ||
(rx1 <= bx1 && bx1 <= rx2 && ry1 <= by2 && by2 <= ry2) ||
(rx1 <= bx1 && bx1 <= rx2 && ry1 <= by1 && by1 <= ry2) ||
(rx1 <= bx2 && bx2 <= rx2 && ry1 <= by1 && by1 <= ry2))
{
drop_brick(brick);
ball_sx = -ball_sx;
ball_sy = -ball_sy;
return;
}
}
private void drop_brick(Label brick)
{
brick.Visible = false;
total_bricks--;
if (total_bricks == 0)
{
timer.Enabled = false;
MessageBox.Show("WIN!!!!");
DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
private void end_brick(Label brick);
{
if(brick1 =)
}
private void last_brick()
{
atimer= new System.Windows.Forms.Timer();
atimer.Interval = 10000;
if (total_bricks == 1) ;
{
atimer.Enabled = true;
}
if (atimer.Interval == 0) ;
{
timer1.Enabled = true;
}
}
}
}
Не могу разобраться с кодом у меня выскакивает ошибка CS0103 CS0103 The name 'cont_brick' does not exist in the current context то же самое относится и к "atimer" . Прошу помощи.
Метод cont_brick();
не существует в вашем коде .
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Всем привет, буду благодарен, если кто то поможет с генерацией случайных чисел в Visual C# и их вывод в label
В WPF у окна есть несколько свойств, отвечающие за его расположение на экране: Left, TopКак в рамках MVVM изменять эти свойства, учитывая, что обычная...
Чтобы не вдаваться в детали самого кода, приведу более абстрактную ситуациюКак мы все прекрасно знаем, следующий код вполне себе рабочий: