A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3,

Similar documents
cards.gif from Tkinter import * root = Tk() c0 = Canvas(root, width = 400, height = 300) c0.pack() image_data = PhotoImage(file = c1.gif ) c0.create_i

from Tkinter import * root = Tk() c0 = Canvas(root, width = 400, height = 300) c0.pack() image_data = PhotoImage(file = c1.gif ) c0.create_image(200,

GIMP

GIMP

Windows (L): D:\jyugyou\ D:\jyugyou\ D:\jyugyou\ (N): en2 OK 2

TOEIC

LogisticaTRUCKServer-Ⅱ距離計算サーバ/Active-Xコントロール/クライアント 概略   

Visual Studio2008 C# で JAN13 バーコードイメージを作成 xbase 言語をご利用の現場でバーコードの出力が必要なことが多々あります xbase 言語製品によっては 標準でバーコード描画機能が付加されているものもあるようで す C# では バーコードフォントを利用したりバー

@(h) Select.vb ver 1.1 ( Select.vb ver 1.0 ( Option Explicit Private Structure SYMBOLINFO Dim SyDataType As String Dim

Windows Web Windows Windows WinSock

OK Form PictureBox Panel RadioButton Panel RadioButton Label Button Form1 540, 440 PictureBox 360, 360 RadioButton1 Text Checked True RadioButton2 Tex

VB 資料 電脳梁山泊烏賊塾 音声認識 System.Speech の利用 System.Speech に依るディクテーション ( 音声を文字列化 ).NetFramework3.0 以上 (Visual Studio 2010 以降 ) では 標準で System.Speech が用意されて居るの

(一日目前半)2017SV演習C++CLI

C#の基本

C#の基本2 ~プログラムの制御構造~

スライド 1

プロセス間通信

GIMP import javafx.application.application; import javafx.scene.scene; import javafx.scene.canvas.canvas; import javafx.scene.canvas.graphicscontext;

C# ++ MASA C# ( ) XNA 1.1 C# ( ) VisualStuio XNA 4.0 VisualStuio XNA 3.1 * * *3 2.1 VisualStuio Windows ( TextGam

ウィンドウ操作 応用

PowerPoint プレゼンテーション

untitled

WPF アプリケーションの 多言語切替

// // GENES Version 1.00 突然変異と自然

Prog2_12th

PowerPoint プレゼンテーション

ICONファイルフォーマット

解きながら学ぶC++入門編

Java演習(4) -- 変数と型 --

6.StatusMemory-VS2010

DEMO1 まずはやってみよう アクティビティをダブルクリック 作成 - プロジェクト C# => Workflow CodeActivity をぽとぺ シーケンシャルと ステートマシン それぞれのコ ンソールアプリ あとライブラリがある びっくりマークは足りていないあかし プロパティをみると判別で


印刷

VB

3D回転体プログラム

Abstract Kinect for Windows RGB Kinect for Windows v Kinect for Windows v2

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

LogisticaTRUCKServer-Ⅱ距離計算サーバ/Active-Xコントロール/クライアント 概略   

アルゴリズムとデータ構造1

グラフィックトレーニング 概要.NET のグラフィック描画は どんなことができるのでしょうか? グラフィックオブジェクトやグラフィック環境 概念を理解するためには クラスを使って馴れることが近道です 本 書に記載されているコードをカットアンドペーストして 一つ一つの機能を体験してください 前提 グラ

「Android Studioではじめる 簡単Androidアプリ開発」正誤表

Java学習教材

8 if switch for while do while 2

Microsoft Word - vcs2010ee-wm2.doc

新・明解Java入門

...Visual Studio 2015\Projects\MyHomePage 用サンプル \Database(Access2)\Database(Access2)\MainForm.cs 2 れを含めておかないと Database への更新がきかない oadp.fill(dtbl); dgvk

ファイル操作

平成 29 年度卒業研究 初心者のためのゲームプログラミング用 教材の開発 函館工業高等専門学校生産システム工学科情報コース 5 年 25 番細見政央指導教員東海林智也

VB.NETコーディング標準


K227 Java 2

パターン化されたロジックのコンポーネント化

r08.dvi

WPF アプリケーションの 多言語切替

ブロック崩し風テニス

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

ohp08.dvi

アプリケーション

10-C.._241_266_.Z

Condition DAQ condition condition 2 3 XML key value

Microsoft Visual Studio 2010 Visual C++ Visual C++ Win32 Win32 (L): D:\jyugyou\ D:\jyugyou\ D:\jyugyou\ (N): hello 1

19 3!! (+) (>) (++) (+=) for while 3.1!! (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics;

2016 VOCALOID Group, Yamaha Corporation 2

GTMF_

ohp03.dvi

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

B Simon (Trump ) SimonU.pas SimonP.dpr Name FormSimon Caption Position podesktopcenter uses Windows, Messages, SysUtils,

2.2 Java C main Java main 2 C 6 C Java 3 C Java ( ) G101Hello.java G101Hello main G101Hello.java /* G101Hello */ class G101Hello { /* main */ public s


haskell.gby

ファイル監視

text_08.dvi

SystemC言語概論

パラパラ漫画

プログラミング方法論 II 第 14,15 回 ( 担当 : 鈴木伸夫 ) 問題 17. x 座標と y 座標をメンバに持つ構造体 Point を作成せよ 但し座標 は double 型とする typedef struct{ (a) x; (b) y; } Point; 問題 18. 問題 17 の

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

ブロック パニック

2 回路図

NetCOBOL for .NET 応用編

r03.dvi

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

presen.gby

新・明解C言語 ポインタ完全攻略

グラフィックス

新版明解C言語 実践編

神経衰弱ゲーム

sp2-2.indd

Java演習(2) -- 簡単なプログラム --

アプレットの作成

新・明解C言語 実践編

橡中元雅美

Thread

解きながら学ぶJava入門編

D:\Documents\Visual Studio 2015\Projects\MyHomePage 用サンプル \ExcelAndWord\ExcelAndWord\MainForm.cs 1 /* */ Excel や Word とやりとりする ~9,20 仕様 Excel

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

I java A

PowerPoint Presentation

Taro-リストⅢ(公開版).jtd

untitled

Public Grid As ReverseGrid Public Position As Point ' 論理位置 Public Rectangle As Rectangle ' 物理位置 Status; 黒 白 なしの状態 Grid; オセロの盤面 Position; 盤面内の説明 Rectan

Transcription:

40 2 1. 2 2. 52 3. A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2 4. 13 5. 6. 7. 8. 9. 13 10. 11. 12. 1

VC++ VC++ Visual C++ Professional 2010 Visual C++ 2010 express Windows whist 2

OK] 3

Form1 size 800, 500 PictureBox Form1 PictureBox 4

PictureBox size 600, 400 button Form1 button Text GAME START 5

GAME START private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) { private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) { srand( (unsigned)time( NULL)); card_set(); gameinitialize(); ShowBan(); 6

srand( (unsigned)time( NULL)); Form1.h #include <stdlib.h> #include <time.h> card_set(); 7

Card class Form1.h struct struct Card { int suit; int rank; int getsuit() { return suit; int getrank() { return rank; void setsuit(int s) { suit = s; void setrank(int r) { rank = r; ; Card carddeck[52]; Form1.h namespace whist { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; 8

card_set(); carddeck[52] private: void card_set() { for (int s=0; s<4; s++) { for (int r=0; r<13; r++) { carddeck[13*s+r].setsuit(s); carddeck[13*s+r].setrank(r); private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) { srand( (unsigned)time( NULL)); card_set(); gameinitialize(); ShowBan(); 9

gameinitialize(); private: void gameinitialize() { card_initialize(); int index =0; for (int i=0; i<13; i++) { comhand[i] = carddeck[index++]; n_comhand = 13; for (int i=0; i<13; i++) { userhand[i] = carddeck[index++]; n_userhand = 13; for (int i=0; i<26; i++) { YamaHand[i] = carddeck[index++]; n_yama = 26; n_getcom = 0; n_getuser = 0; gameoverp = false; complayp = false; n_dispcom = 0; 10

private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) { srand( (unsigned)time( NULL)); card_set(); gameinitialize(); ShowBan(); card_initialize(); private: void card_initialize() { for (int i=0; i<104; i++) { int s = (int)(rand() % 52); int t = (int)(rand() % 52); Card temp = carddeck[s]; carddeck[s] = carddeck[t]; carddeck[t] = temp; private: void gameinitialize() { card_initialize(); int index =0; for (int i=0; i<13; i++) { comhand[i] = carddeck[index++]; 11

n_comhand = 13; for (int i=0; i<13; i++) { userhand[i] = carddeck[index++]; n_userhand = 13; for (int i=0; i<26; i++) { YamaHand[i] = carddeck[index++]; n_yama = 26; n_getcom = 0; n_getuser = 0; gameoverp = false; complayp = false; n_dispcom = 0; int index =0; for (int i=0; i<13; i++) { comhand[i] = carddeck[index++]; n_comhand = 13; for (int i=0; i<13; i++) { userhand[i] = carddeck[index++]; n_userhand = 13; 12

for (int i=0; i<26; i++) { YamaHand[i] = carddeck[index++]; n_yama = 26; n_getcom = 0; n_getuser = 0; gameoverp = false; complayp = false; n_dispcom = 0; ShowBan() WW HH int n_comhand = 0; Card comhand[13]; int n_userhand = 0; Card userhand[13]; int n_yama = 0; Card Yama[26]; int n_getcom = 0; Card getcom[52]; int n_getuser = 0; Card getuser[52]; bool gameoverp = false; bool complayp = false; int n_dispcom = 0; Card dispcom[13]; int WW; int HH; struct Card { int suit; int rank; int getsuit() { return suit; 13

int getrank() { return rank; void setsuit(int s) { suit = s; void setrak(int r) { rank = r; ; Card carddeck[52]; ShowBan(); 14

card256.gif StandardDeck.jpg private: void ShowBan() { Graphics^ g = picturebox1->creategraphics(); System::Drawing::Font^ drawfont; drawfont = gcnew System::Drawing::Font("Arial", 10); Brush^ drawbrush; drawbrush = gcnew SolidBrush(Color::Blue); Bitmap^ bmap = gcnew Bitmap("c:/texsrc/ / /whist/card256.gif"); int w = bmap->width / 13; int h = bmap->height / 4; Bitmap^ bmap2 = gcnew Bitmap("c:/texsrc/ / /whist/standarddeck.jpg"); int w2 = bmap2->width / 13; int h2 = bmap2->height / 5; WW = w; HH = h; Brush^ brush = gcnew SolidBrush(Color::White); g->fillrectangle(brush, 0, 0, picturebox1->width, picturebox1->height); 15

int pos = 10; for (int i=0; i<n_comhand; i++) { Rectangle destrect = Rectangle(pos, 10+35, w, h); Rectangle srcrect = Rectangle(5*w2, 4*h2, w2, h2); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap2, destrect, srcrect, units); pos += 48; private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) { srand( (unsigned)time( NULL)); card_set(); gameinitialize(); ShowBan(); 16

17

YamaHand : 18

private: void gameinitialize() { card_initialize(); int index =0; for (int i=0; i<13; i++) { comhand[i] = carddeck[index++]; n_comhand = 13; for (int i=0; i<13; i++) { userhand[i] = carddeck[index++]; n_userhand = 13; for (int i=0; i<26; i++) { YamaHand[i] = carddeck[index++]; n_yama = 26; n_getcom = 0; n_getuser = 0; gameoverp = false; complayp = false; n_dispcom = 0; YamaHand[i] = carddeck[index++]; Yama[i] = carddeck[index++]; 19

GAME START Form1.h 20

Form PictureBox 13 ShowBan(); private: void ShowBan() { Graphics^ g = picturebox1->creategraphics(); System::Drawing::Font^ drawfont; drawfont = gcnew System::Drawing::Font("Arial", 10); 21

Brush^ drawbrush; drawbrush = gcnew SolidBrush(Color::Blue); Bitmap^ bmap = gcnew Bitmap("c:/texsrc/ / /whist/card256.gif"); int w = bmap->width / 13; int h = bmap->height / 4; Bitmap^ bmap2 = gcnew Bitmap("c:/texsrc/ / /whist/standarddeck.jpg"); int w2 = bmap2->width / 13; int h2 = bmap2->height / 5; WW = w; HH = h; Brush^ brush = gcnew SolidBrush(Color::White); g->fillrectangle(brush, 0, 0, picturebox1->width, picturebox1->height); int pos = 10; for (int i=0; i<n_comhand; i++) { Rectangle destrect = Rectangle(pos, 10+5, w, h); Rectangle srcrect = Rectangle(5*w2, 4*h2, w2, h2); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap2, destrect, srcrect, units); pos += 48; pos += 100; if (n_dispcom > 0) { int suit = dispcom[0].getsuit(); int rank = dispcom[0].getrank(); Rectangle destrect = Rectangle(pos, 10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos = 10; for (int i=0; i<n_getcom; i++) { int suit = getcom[i].getsuit(); int rank = getcom[i].getrank(); Rectangle destrect = Rectangle(pos, HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w2, h2); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos += 10; pos = 10; if (n_yama > 0) { int suit = getcom[n_yama-1].getsuit(); int rank = getcom[n_yama-1].getrank(); 22

Rectangle destrect = Rectangle(pos,2*HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos = 10; for (int i=0; i<n_getuser; i++) { int suit = getuser[i].getsuit(); int rank = getuser[i].getrank(); Rectangle destrect = Rectangle(pos, 3*HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos += 10; pos = 10; for (int i=0; i<n_userhand; i++) { int suit = userhand[i].getsuit(); int rank = userhand[i].getrank(); Rectangle destrect = Rectangle(pos, 4*HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos += 48; if (!gameoverp) { System::String^ drawstring = " "; g->drawstring(drawstring, drawfont, drawbrush, (float)250, (float)(2.5*hh+10+5)); else { int comvalue = n_getcom / 2; int uservalue = n_getuser / 2; System::String^drawString = "Game Over "; drawstring += uservalue + " : " + comvalue; if (comvalue > uservalue) { drawstring += " "; g->drawstring(drawstring, drawfont, drawbrush, (float)250, (float)(2.5*hh+10+5)); else if (comvalue < uservalue) { drawstring += " "; g->drawstring(drawstring, drawfont, drawbrush, (float)250, (float)(2.5*hh+10+5)); else { drawstring += " "; g->drawstring(drawstring, drawfont, drawbrush, (float)250, (float)(2.5*hh+10+5)); 23

GAME START PictureBox Form1.h PictureBox 24

MouseDown 25

private: System::Void picturebox1_mousedown(system::object^ System::Windows::Forms::MouseEventArgs^ e) { sender, struct Card { int suit; int rank; int getsuit() { return suit; int getrank() { return rank; void setsuit(int s) { suit = s; void setrank(int r) { rank = r; ; Card carddeck[52]; int n_comhand = 0; Card comhand[13]; int n_userhand = 0; 26

Card userhand[13]; int n_yama = 0; Card Yama[26]; int n_getcom = 0; Card getcom[52]; int n_getuser = 0; Card getuser[52]; bool gameoverp = false; bool complayp = false; int n_dispcom = 0; Card dispcom[13]; int WW; int HH; int trump; int trump; private: void gameinitialize() { card_initialize(); int index =0; for (int i=0; i<13; i++) { comhand[i] = carddeck[index++]; n_comhand = 13; for (int i=0; i<13; i++) { userhand[i] = carddeck[index++]; n_userhand = 13; for (int i=0; i<26; i++) { Yama[i] = carddeck[index++]; n_yama = 26; n_getcom = 0; n_getuser = 0; gameoverp = false; complayp = false; n_dispcom = 0; trump = Yama[n_Yama-1].getSuit(); 27

trump = Yama[n_Yama-1].getSuit(); private: System::Void picturebox1_mousedown(system::object^ System::Windows::Forms::MouseEventArgs^ e) { sender, private: System::Void picturebox1_mousedown(system::object^ sender, System::Windows::Forms::MouseEventArgs^ e) { int mx = e->x; int my = e->y; int userindex = -1; int pos = 10; for (int i=0; i<n_userhand; i++) { if ((mx>pos && mx<pos+ww)&& (my>4*hh+10+5 && my<4*hh+82+5)){ userindex = i; break; pos += WW; if (userindex < 0) return; if (!complayp) { int suit = userhand[userindex].suit; int rank = userhand[userindex].rank; int comindex = -1; for (int i=0; i<n_comhand; i++) { if (comhand[i].suit == suit) { comindex = i; break; if (comindex < 0) { for (int i=0; i<n_comhand; i++) { if (comhand[i].suit == trump) { comindex = i; break; if (comindex < 0) { 28

comindex = (int)(rand() % n_comhand); if (comhand[comindex].suit == userhand[userindex].suit) { if (comhand[comindex].rank == 0) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = comhand[comindex]; complayp = true; else if (userhand[userindex].rank == 0) { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = comhand[comindex]; complayp = false; else if (comhand[comindex].rank > userhand[userindex].rank) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = comhand[comindex]; complayp = true; else { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = comhand[comindex]; complayp = false; else if (comhand[comindex].suit == trump) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = comhand[comindex]; complayp = true; else if (userhand[userindex].suit == trump) { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = comhand[comindex]; complayp = false; else { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = comhand[comindex]; complayp = false; for (int i=userindex; i<n_userhand-1; i++) userhand[i] = userhand[i+1]; n_userhand--; for (int i=comindex; i<n_comhand-1; i++) comhand[i] = comhand[i+1]; n_comhand--; else { int suit = userhand[userindex].suit; int rank = userhand[userindex].rank; 29

if (suit!= dispcom[0].suit) { bool flag = false; for (int i=0; i<n_userhand; i++) { if (userhand[i].suit == dispcom[0].suit) { flag = true; break; if (flag) { System::String^ str =" "; switch (dispcom[0].suit) { case 0: str += " "; break; case 1: str += " "; break; case 2: str += " "; break; case 3: str += " "; break; str += " "; MessageBox::Show(str); return; if (dispcom[0].suit == userhand[userindex].suit) { if (dispcom[0].rank == 0) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = dispcom[0]; complayp = true; else if (userhand[userindex].rank == 0) { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = dispcom[0]; complayp = false; else if (dispcom[0].rank > userhand[userindex].rank) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = dispcom[0]; complayp = true; else { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = dispcom[0]; complayp = false; else if (dispcom[0].suit == trump) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = dispcom[0]; complayp = true; else if (userhand[userindex].suit == trump) { 30

getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = dispcom[0]; complayp = false; else { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = dispcom[0]; complayp = true; for (int i=userindex; i<n_userhand-1; i++) userhand[i] = userhand[i+1]; n_userhand--; if (n_yama > 0) { if (complayp) { comhand[n_comhand++] = Yama[n_Yama-1]; n_yama--; userhand[n_userhand++] = Yama[n_Yama-1]; n_yama--; else { userhand[n_comhand++] = Yama[n_Yama-1]; n_yama--; comhand[n_userhand++] = Yama[n_Yama-1]; n_yama--; if (n_comhand == 0) { gameoverp = true; n_dispcom = 0; else if (complayp) { int comindex = (int)(rand() % n_comhand); dispcom[0] = comhand[comindex]; n_dispcom = 1; for (int i=comindex; i<n_comhand-1; i++) comhand[i] = comhand[i+1]; n_comhand--; else { n_dispcom = 0; ShowBan(); 31

ShowBan() pos = 10; for (int i=0; i<n_getcom; i++) { int suit = getcom[i].getsuit(); int rank = getcom[i].getrank(); Rectangle destrect = Rectangle(pos, HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w2, h2); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos += 10; pos = 10; if (n_yama > 0) { int suit = getcom[n_yama-1].getsuit(); int rank = getcom[n_yama-1].getrank(); Rectangle destrect = Rectangle(pos,2*HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos = 10; for (int i=0; i<n_getcom; i++) { int suit = getcom[i].getsuit(); 32

int rank = getcom[i].getrank(); Rectangle destrect = Rectangle(pos, HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos += 10; pos = 10; if (n_yama > 0) { int suit = Yama[n_Yama-1].getSuit(); int rank = Yama[n_Yama-1].getRank(); Rectangle destrect = Rectangle(pos,2*HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); Form1.h #pragma once #include <stdlib.h> #include <time.h> namespace whist { using namespace System; using namespace System::ComponentModel; 33

using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; struct Card { int suit; int rank; int getsuit() { return suit; int getrank() { return rank; void setsuit(int s) { suit = s; void setrank(int r) { rank = r; ; Card carddeck[52]; int n_comhand = 0; Card comhand[13]; int n_userhand = 0; Card userhand[13]; int n_yama = 0; Card Yama[26]; int n_getcom = 0; Card getcom[52]; int n_getuser = 0; Card getuser[52]; bool gameoverp = false; bool complayp = false; int n_dispcom = 0; Card dispcom[13]; int WW; int HH; int trump; 34

{ /// <summary> /// Form1 /// </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::PictureBox^ picturebox1; private: System::Windows::Forms::Button^ button1; protected: private: /// <summary> /// /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// /// /// </summary> void InitializeComponent(void) { this->picturebox1 = (gcnew System::Windows::Forms::PictureBox()); 35

this->button1 = (gcnew System::Windows::Forms::Button()); (cli::safe_cast<system::componentmodel::isupportinitialize^ > (this->picturebox1))->begininit(); this->suspendlayout(); // // picturebox1 // this->picturebox1->location = System::Drawing::Point(38, 31); this->picturebox1->name = L"pictureBox1"; this->picturebox1->size = System::Drawing::Size(756, 400); this->picturebox1->tabindex = 0; this->picturebox1->tabstop = false; this->picturebox1->mousedown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox1_MouseDown); // // button1 // this->button1->location = System::Drawing::Point(818, 31); this->button1->name = L"button1"; this->button1->size = System::Drawing::Size(102, 65); this->button1->tabindex = 1; this->button1->text = L"GAME START"; this->button1->usevisualstylebackcolor = true; this->button1->click += gcnew System::EventHandler(this, &Form1::button1_Click); // // Form1 // this->autoscaledimensions = System::Drawing::SizeF(6, 12); this->autoscalemode = System::Windows::Forms::AutoScaleMode::Font; this->clientsize = System::Drawing::Size(945, 461); this->controls->add(this->button1); this->controls->add(this->picturebox1); this->name = L"Form1"; this->text = L"Form1"; (cli::safe_cast<system::componentmodel::isupportinitialize^ > (this->picturebox1))->endinit(); this->resumelayout(false); #pragma endregion private: void card_set() { for (int s=0; s<4; s++) { for (int r=0; r<13; r++) { 36

carddeck[13*s+r].setsuit(s); carddeck[13*s+r].setrank(r); private: void card_initialize() { for (int i=0; i<104; i++) { int s = (int)(rand() % 52); int t = (int)(rand() % 52); Card temp = carddeck[s]; carddeck[s] = carddeck[t]; carddeck[t] = temp; private: void gameinitialize() { card_initialize(); int index =0; for (int i=0; i<13; i++) { comhand[i] = carddeck[index++]; n_comhand = 13; for (int i=0; i<13; i++) { userhand[i] = carddeck[index++]; n_userhand = 13; for (int i=0; i<26; i++) { Yama[i] = carddeck[index++]; n_yama = 26; n_getcom = 0; n_getuser = 0; gameoverp = false; complayp = false; n_dispcom = 0; trump = Yama[n_Yama-1].getSuit(); private: void ShowBan() { Graphics^ g = picturebox1->creategraphics(); System::Drawing::Font^ drawfont; drawfont = gcnew System::Drawing::Font("Arial", 10); 37

Brush^ drawbrush; drawbrush = gcnew SolidBrush(Color::Blue); Bitmap^ bmap = gcnew Bitmap("c:/texsrc/ / /whist/card256.gif"); int w = bmap->width / 13; int h = bmap->height / 4; Bitmap^ bmap2 = gcnew Bitmap("c:/texsrc/ / /whist/standarddeck.jpg"); int w2 = bmap2->width / 13; int h2 = bmap2->height / 5; WW = w; HH = h; Brush^ brush = gcnew SolidBrush(Color::White); g->fillrectangle(brush, 0, 0, picturebox1->width, picturebox1->height); int pos = 10; for (int i=0; i<n_comhand; i++) { Rectangle destrect = Rectangle(pos, 10+5, w, h); Rectangle srcrect = Rectangle(5*w2, 4*h2, w2, h2); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap2, destrect, srcrect, units); pos += 48; pos += 100; if (n_dispcom > 0) { int suit = dispcom[0].getsuit(); int rank = dispcom[0].getrank(); Rectangle destrect = Rectangle(pos, 10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos = 10; for (int i=0; i<n_getcom; i++) { int suit = getcom[i].getsuit(); int rank = getcom[i].getrank(); Rectangle destrect = Rectangle(pos, HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos += 10; pos = 10; if (n_yama > 0) { int suit = Yama[n_Yama-1].getSuit(); int rank = Yama[n_Yama-1].getRank(); 38

Rectangle destrect = Rectangle(pos,2*HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos = 10; for (int i=0; i<n_getuser; i++) { int suit = getuser[i].getsuit(); int rank = getuser[i].getrank(); Rectangle destrect = Rectangle(pos, 3*HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos += 10; pos = 10; for (int i=0; i<n_userhand; i++) { int suit = userhand[i].getsuit(); int rank = userhand[i].getrank(); Rectangle destrect = Rectangle(pos, 4*HH+10+5, w, h); Rectangle srcrect = Rectangle(rank*w, suit*h, w, h); GraphicsUnit units = GraphicsUnit::Pixel; g->drawimage(bmap, destrect, srcrect, units); pos += 48; if (!gameoverp) { System::String^ drawstring = " "; g->drawstring(drawstring, drawfont, drawbrush, (float)250, (float)(2.5*hh+10+5)); else { int comvalue = n_getcom / 2; int uservalue = n_getuser / 2; System::String^drawString = "Game Over "; drawstring += uservalue + " : " + comvalue; if (comvalue > uservalue) { drawstring += " "; g->drawstring(drawstring, drawfont, drawbrush, (float)250, (float)(2.5*hh+10+5)); else if (comvalue < uservalue) { drawstring += " "; g->drawstring(drawstring, drawfont, drawbrush, (float)250, (float)(2.5*hh+10+5)); else { drawstring += " "; g->drawstring(drawstring, drawfont, drawbrush, (float)250, (float)(2.5*hh+10+5)); 39

private: System::Void button1_click(system::object^ sender, System::EventArgs^ e) { srand( (unsigned)time( NULL)); card_set(); gameinitialize(); ShowBan(); private: System::Void picturebox1_mousedown(system::object^ sender, System::Windows::Forms::MouseEventArgs^ e) { int mx = e->x; int my = e->y; int userindex = -1; int pos = 10; for (int i=0; i<n_userhand; i++) { if ((mx>pos && mx<pos+ww)&& (my>4*hh+10+5 && my<4*hh+82+5)){ userindex = i; break; pos += WW; if (userindex < 0) return; if (!complayp) { int suit = userhand[userindex].suit; int rank = userhand[userindex].rank; int comindex = -1; int cand[13]; int n_cand = 0; for (int i=0; i<n_comhand; i++) { if (comhand[i].suit == suit) { comindex = i; break; if (comindex < 0) { for (int i=0; i<n_comhand; i++) { if (comhand[i].suit == trump) { comindex = i; break; 40

if (comindex < 0) { comindex = (int)(rand() % n_comhand); if (comhand[comindex].suit == userhand[userindex].suit) { if (comhand[comindex].rank == 0) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = comhand[comindex]; complayp = true; else if (userhand[userindex].rank == 0) { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = comhand[comindex]; complayp = false; else if (comhand[comindex].rank > userhand[userindex].rank) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = comhand[comindex]; complayp = true; else { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = comhand[comindex]; complayp = false; else if (comhand[comindex].suit == trump) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = comhand[comindex]; complayp = true; else if (userhand[userindex].suit == trump) { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = comhand[comindex]; complayp = false; else { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = comhand[comindex]; complayp = false; for (int i=userindex; i<n_userhand-1; i++) userhand[i] = userhand[i+1]; n_userhand--; for (int i=comindex; i<n_comhand-1; i++) comhand[i] = comhand[i+1]; n_comhand--; else { int suit = userhand[userindex].suit; 41

int rank = userhand[userindex].rank; if (suit!= dispcom[0].suit) { bool flag = false; for (int i=0; i<n_userhand; i++) { if (userhand[i].suit == dispcom[0].suit) { flag = true; break; if (flag) { System::String^ str =" "; switch (dispcom[0].suit) { case 0: str += " "; break; case 1: str += " "; break; case 2: str += " "; break; case 3: str += " "; break; str += " "; MessageBox::Show(str); return; if (dispcom[0].suit == userhand[userindex].suit) { if (dispcom[0].rank == 0) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = dispcom[0]; complayp = true; else if (userhand[userindex].rank == 0) { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = dispcom[0]; complayp = false; else if (dispcom[0].rank > userhand[userindex].rank) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = dispcom[0]; complayp = true; else { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = dispcom[0]; complayp = false; else if (dispcom[0].suit == trump) { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = dispcom[0]; complayp = true; 42

; else if (userhand[userindex].suit == trump) { getuser[n_getuser++] = userhand[userindex]; getuser[n_getuser++] = dispcom[0]; complayp = false; else { getcom[n_getcom++] = userhand[userindex]; getcom[n_getcom++] = dispcom[0]; complayp = true; for (int i=userindex; i<n_userhand-1; i++) userhand[i] = userhand[i+1]; n_userhand--; if (n_yama > 0) { if (complayp) { comhand[n_comhand++] = Yama[n_Yama-1]; n_yama--; userhand[n_userhand++] = Yama[n_Yama-1]; n_yama--; else { userhand[n_comhand++] = Yama[n_Yama-1]; n_yama--; comhand[n_userhand++] = Yama[n_Yama-1]; n_yama--; if (n_comhand == 0) { gameoverp = true; n_dispcom = 0; else if (complayp) { int comindex = (int)(rand() % n_comhand); dispcom[0] = comhand[comindex]; n_dispcom = 1; for (int i=comindex; i<n_comhand-1; i++) comhand[i] = comhand[i+1]; n_comhand--; else { n_dispcom = 0; ShowBan(); 43

Java VC++ 1 500 ENCYCLOPEDIA of CARD GAME David Parlett The Penguin Encyclopedia of Card Games 2 44