using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Forms;
public partial class FormBallGame : Form
private string fontName = "HG教科書体";
private string correctText = "荻";
private string mistakeText = "萩";
private string circleText = "〇";
private double nowTime = 0;
private int ballCount = 5;
private int randomResult = 0;
private void label1_Click(object sender, EventArgs e)
private void restartButton_Click(object sender, EventArgs e)
private void selectPictureBox_MouseClick(object sender, MouseEventArgs e)
if(restartButton.Enabled)
if(e.Button == MouseButtons.Left)
int selectCircle = e.X / selectPictureBox.Height;
if(randomResult == selectCircle)
DrowMainPictureBox(Brushes.Red, circleText, true);
restartButton.Enabled = true;
DrowMainPictureBox(Brushes.Red, correctText, false);
for(int i = 0;i< ballCount; i++)
balls[i].pitch = balls[i].pitch - balls[i].pitch / 2;
private void mainPictureBox_MouseClick(object sender, MouseEventArgs e)
if(restartButton.Enabled)
private void timer1_Tick(object sender, EventArgs e)
for(int i = 0;i<ballCount;i++)
nowTime = nowTime + 0.02;
textTimer.Text = nowTime.ToString("0.00");
private void mainPictureBox_Click(object sender, EventArgs e)
private void FormBallGame_Load(object sender, EventArgs e)
private void DrowCirleSelectPictureBox()
int height = selectPictureBox.Height;
int width = selectPictureBox.Width;
Bitmap selectCanvas = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(selectCanvas))
for (int i = 0; i< ballCount; i++)
g.FillEllipse(brushes[i],i * height, 0, height, height);
selectPictureBox.Image = selectCanvas;
private void DrowMainPictureBox(Brush color, string text, bool trueFlag)
int height = mainPictureBox.Height;
int width = mainPictureBox.Width;
canvas = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(canvas))
g.FillRectangle(Brushes.LightPink, 0, 0, width, height);
g.FillRectangle(Brushes.White, 0, 0, width, height);
new Font(fontName, height - height / 4),
color, 0, 0, new StringFormat());
mainPictureBox.Image = canvas;
private void InitGraphics()
brushes = new Brush[ballCount];
kanjis = new string[ballCount];
balls = new Ball[ballCount];
brushes[0] = Brushes.LightPink;
brushes[1] = Brushes.LightBlue;
brushes[2] = Brushes.LightGray;
brushes[3] = Brushes.LightCoral;
brushes[4] = Brushes.LightGreen;
DrowCirleSelectPictureBox();
DrowMainPictureBox(Brushes.Gray, correctText, false);
restartButton.Enabled = false;
textHunt.Text = correctText;
private void SetStartPosition()
for (int i = 0; i < ballCount; i++)
randomResult = new Random().Next(ballCount);
kanjis[randomResult] = correctText;
for (int i = 0; i < ballCount; i++)
balls[i] = new Ball(mainPictureBox, canvas, brushes[i], kanjis[i]);
private void SetBalls(int x, int y)
int rndXMax = mainPictureBox.Width;
int rndYMax = mainPictureBox.Height;
for (int i = 0; i < ballCount; i++ )
rndX = new Random(i * x).Next(rndXMax);
rndY = new Random(i * y).Next(rndYMax);
balls[i].PutCircle(rndX, rndY);
SetBalls(new Random().Next(rndXMax), new Random().Next(rndYMax));