2009年7月25日土曜日

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)
        {

        }

        private void mainForm_Load(object sender, EventArgs e)
        {
            const int DOG_INDEX = 0;
            const int SQUIRREL_INDEX = 1;
            const int BIRD_INDEX = 2;
            const int SNAKE_INDEX = 3;
            const int FROG_INDEX = 4;
            const int FISH_INDEX = 5;
            defaultbackgroundImage = this.backgroundPicture.Image;
            showuppictureArray[DOG_INDEX] = this.showupdogPicture;
            showuppictureArray[SQUIRREL_INDEX] = this.showupsquirrelPicture;
            showuppictureArray[BIRD_INDEX] = this.showupbirdPicture;
            showuppictureArray[SNAKE_INDEX] = this.showupsnakePicture;
            showuppictureArray[FROG_INDEX] = this.showupdogPicture;
            showuppictureArray[FISH_INDEX] = this.showupfishPicture;
            correctImage = Properties.Resources.Correct;
            uncorrectImage = Properties.Resources.Uncorrect;
            pointimageArray[0] = Properties.Resources.Number0;
            pointimageArray[1] = Properties.Resources.Number1;
            pointimageArray[2] = Properties.Resources.Number2;
            pointimageArray[3] = Properties.Resources.Number3;
            pointimageArray[4] = Properties.Resources.Number5;
            pointimageArray[5] = Properties.Resources.Number5;
            pointimageArray[6] = Properties.Resources.Number6;
            pointimageArray[7] = Properties.Resources.Number7;
            pointimageArray[8] = Properties.Resources.Number8;
            pointimageArray[9] = Properties.Resources.Number9;
            answerimageArray[DOG_INDEX] = Properties.Resources.AnswerDog;
            answerimageArray[SQUIRREL_INDEX] = Properties.Resources.AnswerSquirrel;
            answerimageArray[BIRD_INDEX] = Properties.Resources.AnswerBird;
            answerimageArray[SNAKE_INDEX] = Properties.Resources.AnswerSnake;
            answerimageArray[FROG_INDEX] = Properties.Resources.AnswerFrog;
            answerimageArray[FISH_INDEX] = Properties.Resources.AnswerFish;
        }

        private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("ゲームを終了しますか?", "終了", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                DialogResult.No)
            {
                e.Cancel = true;
            }
        }
    }
}

p.124まで終了。

0 コメント:

コメントを投稿