概要
cscの作法、調べてみた。
練習問題やってみた。
練習問題
もぐら叩きを作れ。
方針
pictureboxとtimer使う
一秒毎に動かす。
一匹叩くと消える、一点追加
10秒でタイムアップ
写真
サンプルコード
using System;
using System.Drawing;
using System.Windows.Forms;
namespace App
{
public partial class Form1 : Form {
Random r = new Random();
int k = 0;
int j = 0;
int ten = 0;
PictureBox pictureBox1;
public Form1() {
Text = "mogura";
ClientSize = new Size(450, 450);
pictureBox1 = new PictureBox();
pictureBox1.Width = 100;
pictureBox1.Height = 100;
pictureBox1.Left = 200;
pictureBox1.Top = 200;
pictureBox1.Image = Image.FromFile("sakana.png");
Controls.Add(pictureBox1);
pictureBox1.Click += pictureBox1_Click;
Timer timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timerTick);
timer.Start();
}
void timerTick(object sender, EventArgs e) {
if (j == 0 && k > 9)
{
j = 1;
MessageBox.Show("おしい!" + ten + "点");
}
if (j == 0)
{
k = k + 1;
pictureBox1.Left = r.Next(300);
pictureBox1.Top = r.Next(300);
pictureBox1.Visible = true;
}
}
void pictureBox1_Click(object sender, System.EventArgs e) {
ten = ten + 1;
//Console.WriteLine("ok0");
//Console.Beep(262, 300);
pictureBox1.Visible = false;
}
[STAThread]
static void Main(string[] args) {
Application.Run(new Form1());
}
}
}
以上。
↧