ハルhal
デジタル コンテンツ

pc2

作って学ぶ
ハードとソフト

アルゴリズム
電子回路

 






このサイトはHPです
ブログではありません
要望・意見は
下記の掲示場を利用して
下さいまたブログも見て下さい

 

ロボット・DOSV掲示板兼Blog

懐かしのコンピュータ
Apple II Apple2
PC9801 PC9821

roboto

Topに戻る

ララ Lara
アナログ コンテンツ

Lara座れ
動画で学ぶ
躾と訓練
動画メニュー


工作


集団練習メニュー


しつけ 訓練コラム




最後にララについて

このサイトはHPです
ブログではありません
要望・意見は
下記の掲示場を利用して
下さいまたブログも見て下さい

Laraララの
ブログ

犬のしつけと訓練
掲示板


掲示板の利用規則

 

 

 

 

Lara伏せ
Topに戻る
松本 ワンワンクラブ
わんわんクラブ

 

Visual Studio 2010 Express Edition で神経衰弱ゲームを作ろう

マウスの位置をを読み取る

マウスの準備

private: System::Void Form1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
int mx1=e->X;
int my1=e->Y;
int X0,Y0;
int x;
for(x=1;x<=13;x++){
X0=80*x;
Y0=100;
//読み取る範囲を指定
if(mx1>X0 && mx1<X0+80 && my1>Y0 && my1<Y0+100){
if(e->Button==System::Windows::Forms::MouseButtons::Left)
mx1d=x; //左クリック
crcm++;
if(e->Button==System::Windows::Forms::MouseButtons::Right)
mx1d=0; //右クリック
textBox2->Text=Convert::ToString(x);
}
}

赤字が入力


#pragma once

namespace test4 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Form1 の概要
///
/// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた
/// マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを
/// 変更する必要があります。この変更を行わないと、
/// デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、
/// 正しく相互に利用できなくなります。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: ここにコンストラクタ コードを追加します
//
}
protected:
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private: System::Windows::Forms::TextBox^ textBox1;

private:
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
System::ComponentModel::Container ^components;
//--------------------
public: static array <int>^ noh =gcnew array<int>(14);
public: static array <int>^ nos =gcnew array<int>(14);
public: static array <int>^ nou1 =gcnew array<int>(14);
public: static array <int>^ nou2 =gcnew array<int>(14);
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
public:
public: static int no;
public: static int mx1,my1;
public: static int mx1d,my1d,mold,flag1,crc,crcm;
private: System::Windows::Forms::TextBox^ textBox4;
public:
//--------------------

#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button2 = (gcnew System::Windows::Forms::Button());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(259, 28);
this->button1->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(139, 42);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(76, 15);
this->textBox1->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(157, 22);
this->textBox1->TabIndex = 1;
//
// button2
//
this->button2->Location = System::Drawing::Point(425, 32);
this->button2->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(140, 38);
this->button2->TabIndex = 2;
this->button2->Text = L"button2";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(79, 52);
this->textBox2->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(153, 22);
this->textBox2->TabIndex = 3;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(77, 90);
this->textBox3->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(153, 22);
this->textBox3->TabIndex = 4;
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(625, 48);
this->textBox4->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::Drawing::Size(208, 22);
this->textBox4->TabIndex = 5;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 15);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1152, 535);
this->Controls->Add(this->textBox4);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->button2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button1);
this->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint);
this->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseDown);
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
Graphics^ g=this->CreateGraphics();
Bitmap^ bmap1;
String^ filename;

int x;
for(x=1;x<=13;x++){
no=noh[x];
if(no==0) no=1;
filename="c:\\card\\"+no+"_he.gif";
if(nou1[x]==100) filename="c:\\card\\0_r1.gif";
bmap1=gcnew Bitmap(filename);
if(x<=crc) g->DrawImage(bmap1,80*x,100);
no=nos[x];
if(no==0) no=1;
filename="c:\\card\\"+no+"_sp.gif";
if(nou2[x]==100) filename="c:\\card\\0_r1.gif";
bmap1=gcnew Bitmap(filename);
if(x<=crc) g->DrawImage(bmap1,80*x,220);
}
//textBox2->Text=Convert::ToString(xx);
//textBox3->Text=Convert::ToString(yy);
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if(flag1==0){
flag1=1;
crcm=0;
crc++;
if (crc==13) crc=13;
int x,d,y,flag;
for(x=1;x<=13;x++) {
noh[x]=0;
nos[x]=0;
nou1[x]=0;
nou2[x]=0;
}
x=1;
do { d=(rand()%crc)+1;
flag=0;
for(y=1;y<=crc;y++) if(noh[y]==d) flag=1;
if(flag==0) { noh[x]=d;
x++; }
} while(x<=crc);
x=1;
do { d=(rand()%crc)+1;
flag=0;
for(y=1;y<=crc;y++) if(nos[y]==d) flag=1;
if(flag==0) { nos[x]=d;
x++; }
} while(x<=crc);

textBox1->Text=Convert::ToString(no);
Invalidate();

}
flag1=0;

}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
mx1d=0;
my1d=0;
flag1=0;
crc=2;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
int x;
for(x=1;x<=13;x++){
nou1[x]=100;
nou2[x]=100;
}
Invalidate();
}
private: System::Void Form1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
int mx1=e->X;
int my1=e->Y;
int X0,Y0;
int x;
if(crcm>crc*2) {textBox4->Text="再挑戦";
for(x=1;x<=13;x++){
nou1[x]=100;
nou2[x]=100;
}
Invalidate();
crcm=0;
}
for(x=1;x<=13;x++){
X0=80*x;
Y0=100;
if(mx1>X0 && mx1<X0+80 && my1>Y0 && my1<Y0+100){
if(e->Button==System::Windows::Forms::MouseButtons::Left)
mx1d=x;
crcm++;
if(e->Button==System::Windows::Forms::MouseButtons::Right)
mx1d=0;
textBox2->Text=Convert::ToString(x);
}
}
for(x=1;x<=13;x++){
X0=80*x;
Y0=200;
if(mx1>X0 && mx1<X0+80 && my1>Y0 && my1<Y0+100){
if(e->Button==System::Windows::Forms::MouseButtons::Left)
my1d=x;
crcm++;
if(e->Button==System::Windows::Forms::MouseButtons::Right)
mx1d=0;
textBox3->Text=Convert::ToString(x);
}
}
if ( noh[mx1d]==nos[my1d]) {textBox1->Text="同じ";
nou1[mx1d]=noh[mx1d];
nou2[my1d]=nos[my1d];
if(crc*2==crcm) textBox4->Text="合格";
}
else textBox1->Text="異なる";
//mold=noh[mx1d];
Invalidate();
}
};
}

実行 ソース 参照 プログラムダウンロード

test4
c:\card 必要


 

 
動画が旨くご覧いただけない場合は最新のFlash Playerをインストールしてください
web ブラウザがインターネットエクスプローラ6(IE6)以下の場合メニューが崩れてしまうことがあります。
インターネットエクスプローラ7、Sleipnir、Mozilla Firefoxをご使用ください。