2009年7月23日木曜日

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;

namespace WindowsFormsApplication1
{
public partial class mainForm : Form
{
//ゲームレベルの最高値を表す定数
private const int MAX_GAME_LEVEL = 15;
//動物の種類の数を表す定数
private const int ANIMAL_COUNT = 6;

private int gamelevel = 1; //ゲームレベル
private int score = 0; //スコア

private int clickcount = 0; //クリック回数
private bool isAnswering = false; //解答中を示すフラグ

//規定の背景画像
private Image defaultbackgroundImage;
//○と×の画像
private Image correctImage;
private Image uncorrectImage;
//ポイント(点数)として表示する画像からなる配列
private Image[] pointimageArray = new Image[10];
//解答歴に表示する画像からなる配列
private Image[] answerimageArray = new Image[ANIMAL_COUNT];
//動物の画像を保持しているピクチャボックスからなる配列
private PictureBox[] showuppictureArray = new PictureBox[ANIMAL_COUNT];
//正解を示す数値からなる配列
private int[] answerArray = new int[MAX_GAME_LEVEL];

public mainForm()
{
InitializeComponent();
}

private void ResetBackGround()
{
this.backgroundPicture.Image = defaultbackgroundImage;
}
private void HideAnswerPictures()
{
foreach (PictureBox answerbox in this.answerpicturesGroup.Controls)
{
answerbox.Visible = false;
}
}
private void DrawImageOnBackGround(Image drawimage, int x, int y)
{
Bitmap canvasbitmap = new Bitmap(this.backgroundPicture.Image);
Graphics.FromImage(canvasbitmap).DrawImage(drawimage, x - this.backgroundPicture.Left, y - this.backgroundPicture.Top);
this.backgroundPicture.Image = canvasbitmap;
}
private void DrawImageOnBackGround(PictureBox drawpicture)
{
DrawImageOnBackGround(drawpicture.Image, drawpicture.Left, drawpicture.Top);
}
private void DrawImageOnBackGround(Image drawimage, PictureBox locationpicture)
{
int x = locationpicture.Left;
int y = locationpicture.Top;
DrawImageOnBackGround(drawimage, x, y);

}

private void DrawClearBonus(int clearbonus)
{
int temp = clearbonus / 10;
if (temp / 10 > 0)
{
DrawImageOnBackGround(pointimageArray[temp / 10], this.clearbonuspoint1Picture);
}
if (temp % 10 > 0 || temp / 10 > 0)
{
DrawImageOnBackGround(pointimageArray[temp % 10], this.clearbonuspoint2Picture);
}
DrawImageOnBackGround(pointimageArray[clearbonus % 10],
this.clearbonuspoint3Picture);
}
private void DrawTimeBonus(int timebonus)
{
int temp = timebonus / 10;
if (temp / 10 > 0)
{
DrawImageOnBackGround(pointimageArray[temp / 10], this.timebonuspoint1Picture);
}
if ( temp % 10 > 0 || temp / 10 > 0)
{
DrawImageOnBackGround(pointimageArray[temp % 10], this.timebonuspoint2Picture);
}
DrawImageOnBackGround(pointimageArray[timebonus % 10],this.timebonuspoint3Picture);
}
private void QuestionStart()
{
this.levelLabel.Text = gamelevel.ToString();
ResetBackGround();
this.Refresh();
System.Threading.Thread.Sleep(500);
for (int i = 0; i < gamelevel; i++)
{
DrawImageOnBackGround(showuppictureArray[answerArray[i]]);
this.Refresh();
System.Threading.Thread.Sleep(500);
ResetBackGround();
this.Refresh();
System.Threading.Thread.Sleep(500);
}
this.timerProgress.Value = gamelevel * 2000;
foreach (PictureBox temppicture in showuppictureArray)
{
DrawImageOnBackGround(temppicture);
}
clickcount = 0;
isAnswering = true;
this.limittimeTimer.Start();
}
private void GameStart()
{
this.gamestartMenu.Enabled = false;
this.playerMenu.Enabled = false;
Random r = new Random();
for (int i = 0; i < MAX_GAME_LEVEL; i++)
{
answerArray[i] = r.Next(0, ANIMAL_COUNT);
((PictureBox)this.answerpicturesGroup.Controls[i]).Image =
answerimageArray[answerArray[i]];
}
HideAnswerPictures();
score = 0;
this.scoreLabel.Text = score.ToString();
gamelevel = 1;
QuestionStart();
}
private void GameClear()
{
ResetBackGround();
HideAnswerPictures();
DrawImageOnBackGround(this.gameclearPicture);
this.standbyTimer.Start();
}
private void GameOver()
{
ResetBackGround();
HideAnswerPictures();
DrawImageOnBackGround(this.gameoverPicture);
this.standbyTimer.Start();
}
private void QuestionClear()
{
isAnswering = false;
this.limittimeTimer.Stop();
int clearbonus = gamelevel * 30;
int timebonus = this.timerProgress.Value / 100;
DrawImageOnBackGround(this.clearPicture);
DrawImageOnBackGround(this.clearbonusPicture);
DrawImageOnBackGround(this.timebonusPictrue);
DrawClearBonus(clearbonus);
DrawTimeBonus(timebonus);
this.Refresh();
System.Threading.Thread.Sleep(1000);
score += clearbonus + timebonus;
this.scoreLabel.Text = score.ToString();
this.timerProgress.Value = 0;
HideAnswerPictures();
gamelevel++;
if (gamelevel > MAX_GAME_LEVEL)
{
GameClear();
}
else
{
QuestionStart();
}
}

private void pictureBox9_Click(object sender, EventArgs e)
{

}

private void label3_Click(object sender, EventArgs e)
{

}

private void label4_Click(object sender, EventArgs e)
{

}

private void プレToolStripMenuItem_Click(object sender, EventArgs e)
{

}

private void toolStripSeparator1_Click(object sender, EventArgs e)
{

}
}
}

p.144,第5章まで終了。

0 コメント:

コメントを投稿