はてなキーワード: Blocksとは
結構面倒
int blocks[100][100];
BOOL WriteBoxOLDBox() { int width = 24; HDC hdc = GetDC(hWnd); HBRUSH hBrush = CreateSolidBrush(RGB(48, 48, 48)); for (int y = 0; y < 30; y++) { for (int x = 0; x < 8; x++) { if (blocks[y][x] == 0) { continue; } RECT Rect = { 0,0,48,48 }; BOOL ret; Rect.left = width * x + 1; Rect.right = width * (x + 1) - 1; Rect.top = width * y + 1; Rect.bottom = width * (y + 1) - 1; ret = FillRect(hdc, &amp;Rect, hBrush); } } DeleteObject(hBrush); return FALSE; }
この辺は めんどくさくはあるけど みてわかってほしい
描画したWriteBoxとおなじ BOXが落ちた場所(BOXの有無)を保存しておく
ここがわかりにくいといえば わかりにくい
BOOL SaveBoxI() { blocks[y ][x] = 1; blocks[y+1][x] = 1; blocks[y+2][x] = 1; blocks[y+3][x] = 1; return TRUE; }
// WindowsProject7.cpp: アプリケーションのエントリ ポイントを定義します。 // #include "stdafx.h" #include "WindowsProject7.h" #define MAX_LOADSTRING 100 // グローバル変数: HINSTANCE hInst; // 現在のインターフェイス WCHAR szTitle[MAX_LOADSTRING]; // タイトル バーのテキスト WCHAR szWindowClass[MAX_LOADSTRING]; // メイン ウィンドウ クラス名 // このコード モジュールに含まれる関数の宣言を転送します: //ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); #include <list> class MyWindow; std::list< MyWindow *> windows; class MyWindow { public: HWND hWnd; MyWindow() :hWnd(NULL) { windows.push_back(this); } virtual ~MyWindow() { std::list< MyWindow *>::iterator it; for (it = windows.begin(); it != windows.end(); it++) { if (*it == this) { windows.erase(it); break; } } } static MyWindow * find(HWND key) { std::list< MyWindow *>::iterator it; for (it = windows.begin(); it != windows.end(); it++) { MyWindow *target = *it; if (target->hWnd == key) { return target; } } return NULL; } // // 関数: MyRegisterClass() // // 目的: ウィンドウ クラスを登録します。 // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEXW wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSPROJECT7)); wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WINDOWSPROJECT7); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassExW(&amp;wcex); } // // 関数: InitInstance(HINSTANCE, int) // // 目的: インスタンス ハンドルを保存して、メイン ウィンドウを作成します。 // // コメント: // // この関数で、グローバル変数でインスタンス ハンドルを保存し、 // メイン プログラム ウィンドウを作成および表示します。 // int blocks[100][100]; BOOL InitInstance() { hInst = hInstance; // グローバル変数にインスタンス処理を格納します。 ATOM c = MyRegisterClass(hInstance); x = 0; y = 0; boxType = 0; hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); for(int x = 0 ; x < 100 ; x++) { for (int y = 0; y < 100; y++) { blocks[y][x] = 0; } } if (!hWnd) { return FALSE; } return TRUE; } BOOL ShowWindow() { BOOL ret; ret = ::ShowWindow(hWnd, SW_SHOW); ::UpdateWindow(hWnd); return ret; } HINSTANCE hInstance; MSG msg; BOOL run; int x; int y; BOOL Main() { HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINDOWSPROJECT7)); run = true; int rc; // メイン メッセージ ループ: while (run) { DWORD obj = MsgWaitForMultipleObjectsEx(0, NULL, 100 , QS_PAINT| QS_ALLEVENTS,0); if (obj <= WAIT_OBJECT_0) { while (PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &amp;msg)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } if (msg.message == WM_QUIT) { run = FALSE; } if (msg.message == WM_CLOSE) { run = FALSE; } } } else if (obj == WAIT_TIMEOUT) { y++; PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &amp;ps); this->OnPaint(ps); EndPaint(hWnd, &amp;ps); ::UpdateWindow(hWnd); RECT Rect2 = { 0,0,48*9,48 * 100 }; InvalidateRect(hWnd, &amp;Rect2, TRUE); } else if (obj == WAIT_FAILED) { rc = GetLastError(); } else { } } return TRUE; } int boxType; BOOL WriteBoxOLDBox() { int width = 24; HDC hdc = GetDC(hWnd); HBRUSH hBrush = CreateSolidBrush(RGB(48, 48, 48)); for (int y = 0; y < 30; y++) { for (int x = 0; x < 8; x++) { if (blocks[y][x] == 0) { continue; } RECT Rect = { 0,0,48,48 }; BOOL ret; Rect.left = width * x + 1; Rect.right = width * (x + 1) - 1; Rect.top = width * y + 1; Rect.bottom = width * (y + 1) - 1; ret = FillRect(hdc, &amp;Rect, hBrush); } } DeleteObject(hBrush); return FALSE; } BOOL WriteBox() { WriteBoxOLDBox(); switch (boxType) { case 0: return WriteBoxI(); case 1: return WriteBoxL(); case 2: return WriteBoxZ(); } return TRUE; } BOOL WriteBoxZ() { HDC hdc = GetDC(hWnd); HBRUSH hBrush = CreateSolidBrush(RGB(48, 48, 246)); int width = 24; RECT Rect = { 0,0,48,48 }; BOOL ret; Rect.left = width * x + 1; Rect.right = width * (x + 1) - 1; Rect.top = width * y + 1; Rect.bottom = width * (y + 1) - 1; ret = FillRect(hdc, &amp;Rect, hBrush); Rect.top += width; Rect.bottom += width; ret = FillRect(hdc, &amp;Rect, hBrush); Rect.left += width; Rect.right += width; ret = FillRect(hdc, &amp;Rect, hBrush); Rect.top += width; Rect.bottom += width; ret = FillRect(hdc, &amp;Rect, hBrush); DeleteObject(hBrush); return TRUE; } BOOL WriteBoxL() { HDC hdc = GetDC(hWnd); HBRUSH hBrush = CreateSolidBrush(RGB(48, 246 , 48)); int width = 24; RECT Rect = { 0,0,48,48 }; BOOL ret; Rect.left = width * x + 1; Rect.right = width * (x + 1) -1 ; Rect.top = width * y + 1; Rect.bottom = width * (y + 1) -1; ret = FillRect(hdc, &amp;Rect, hBrush); Rect.top += width; Rect.bottom += width; ret = FillRect(hdc, &amp;Rect, hBrush); Rect.top += width; Rect.bottom += width; ret = FillRect(hdc, &amp;Rect, hBrush); Rect.left += width; Rect.right += width; ret = FillRect(hdc, &amp;Rect, hBrush); DeleteObject(hBrush); return TRUE; } BOOL WriteBoxI() { HDC hdc = GetDC(hWnd); HBRUSH hBrush = CreateSolidBrush(RGB( 246 , 48 , 48)); int width = 24; RECT Rect = { 0,0,48,48 }; BOOL ret; Rect.left = width * x + 1; Rect.right = width * (x + 1) - 1; Rect.top = width * y + 1; Rect.bottom = width * (y + 1) - 1; ret = FillRect(hdc, &amp;Rect, hBrush); //Rect.left += width; //Rect.right += width; Rect.top += width; Rect.bottom += width; ret = FillRect(hdc, &amp;Rect, hBrush); Rect.top += width; Rect.bottom += width; ret = FillRect(hdc, &amp;Rect, hBrush); Rect.top += width; Rect.bottom += width; ret = FillRect(hdc, &amp;Rect, hBrush); DeleteObject(hBrush); return TRUE; } BOOL SaveBoxI() { blocks[y ][x] = 1; blocks[y+1][x] = 1; blocks[y+2][x] = 1; blocks[y+3][x] = 1; return TRUE; } BOOL OnPaint(PAINTSTRUCT &amp;ps) { if (x > 8) { x = 0; } if (x <0) { x = 8; } if (y > 20) { switch (boxType) { case 0: SaveBoxI(); break; case 1: break; case 2: break; } y = 0; boxType++; if (boxType > 2) { boxType = 0; } } this->WriteBox(); return TRUE; } BOOL OnKey(WPARAM wParam) { if (wParam == VK_LEFT) { x++; } if (wParam == VK_RIGHT) { x--; } return TRUE; } }; int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: ここにコードを挿入してください。 // グローバル文字列を初期化しています。 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadStringW(hInstance, IDC_WINDOWSPROJECT7, szWindowClass, MAX_LOADSTRING); //MyRegisterClass(hInstance); MyWindow win; win.hInstance = hInstance; // アプリケーションの初期化を実行します: if (!win.InitInstance()) { return FALSE; } BOOL ret; win.ShowWindow(); ret = win.Main(); if (ret) { return 0; }else { return (int)win.msg.wParam; } } // // 関数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: メイン ウィンドウのメッセージを処理します。 // // WM_COMMAND - アプリケーション メニューの処理 // WM_PAINT - メイン ウィンドウの描画 // WM_DESTROY - 中止メッセージを表示して戻る // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: { int wmId = LOWORD(wParam); // 選択されたメニューの解析: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } } break; case WM_KEYDOWN: { MyWindow *target = MyWindow::find(hWnd); target->OnKey(wParam); } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &amp;ps); MyWindow *target = MyWindow::find(hWnd); target->OnPaint(ps); // TODO: HDC を使用する描画コードをここに追加してください... EndPaint(hWnd, &amp;ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // バージョン情報ボックスのメッセージ ハンドラーです。 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; }
日本語化された公式ドキュメント。全てを読むのは難しいが、「Objective-C プログラミング言語」「Objective-Cによるプログラミング」を読めば、大半の入門書より網羅的に解説している。
ろくに書籍化されていない情報を日本語で読むにはここしかない。
某androidでは一切ドキュメントが日本語化されず、公式チュートリアルの日本語化でさえ有難がられる(そして一般の開発者が理解していない)惨状なので、日本語資料の存在を有難がるべき。
XCode内で調べたいクラスでOption+右クリックでクイックヘルプを開き、更にクラス名をクリックすると、オーガナイザにクラスリファレンスが表示される。
ここで概要を読めばおおよそは分かる。
リファレンスに使われている単語は限られているので、英語が苦手で文法が不明瞭でも、読み続けさえすればある程度意味は把握できるようになる。
福井高専の有志による日本語リファレンスが存在するが、更新が古い上に意味を真逆に捉えた最悪な翻訳が野放しになっており、オリジナルへのリンクもない仕様なので、読むべきではない。
紙ベースでObjective-Cの入門書が欲しいのであれば、この本一択。
iOSに限定しないことで、Cocoa TouchがCocoaのサブセットであるがゆえの制約など、iOSだけ見ているとなぜそういう仕様になっているのか分からない部分が明瞭になる。
ある程度理解したつもりでいるiOSプログラマでも、おそらく新しい発見がある。
マイナビの連載でwebで無料で読むことができるが、加筆修正された書籍版も販売されている。
約7年前に始まった連載なので、情報としては古く、ポージングなど既に廃止されたテクニックについて語っていたりもするが、その内容は色褪せない。
Objective-Cランタイムがどのようにオブジェクト指向とC言語を結び付けているのか、クラスやメソッドの実体とは何なのかを明らかにしていく。
正直詳解と呼ぶほど詳しくないので、UIKitで困ったら素直にクラスリファレンスに頼った方が良い(ネットでググるのは間違った情報に当たる確率が高いのでおすすめしない…)。
しかし丁寧な解説はUIKitに触れる際に一読する価値はある。
惜しむらくはiOS4時代のもので、バージョンアップ時にそれなりにUIKitに変更が加えられるので、それを考慮に入れて読むこと。
タイトルからは中級者以上を想定しているように見えるが、実際には初学者向けで、retainを使ったメモリ管理から話が始まる。当然、MRC時代の本。
しかしデバッガを用いたクラッシュ原因の特定や、Instrumentを使ったメモリリークの防止など、より品質の高いアプリケーションを作るノウハウについて触れているのが異色。
iOS開発で多用するMVCを利用したデータ管理や、テーブルビューによるリスト表示などをパターンとして紹介する本。
「使い方は分かったけど、どう作ればわからない」という人に作成の一つの指針としておすすめだが、万人に対してこの通りに作れ、とは薦めにくい。
この本は、強力な仕組みながら解説の乏しいCore Dataをプッシュしてページ数を割いているのが貴重なのだけど、NSFetchedResultsController(訂正しました。指摘ありがとうございます!)をスルーしているため実用性を大きく欠いてしまっている。
大半の用途ではAVAudioPlayerを使用すれば困らないと思うのだけど、日本語でCoreフレームワークについて1冊本が出ていて、これだけ詳細な情報が手に入るというだけで読まないと損。
独創的で優れた楽器アプリが日本のAppStoreからこれだけ多く登場したのは、この本の存在があったからに他ならないように思う。
2012年はてな匿名ダイアリー名作ランキング50選様に取り上げて頂いた関係で、再び日の目を見ているようですので、この一冊を追加。
冒頭のメモリ管理の話が平易すぎて読む本を間違えたかと思ったが、ARCやBlocksの挙動を実装レベルで解説する以降の章はまさにエキスパートに相応しい内容。「使い方」の一歩先を知りたい人におすすめ。
http://okajima.air-nifty.com/b/2011/01/2011-ffac.html
ぷよぷよを解く問題をやってみた
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { StringBuilder[] blocks = { new StringBuilder("**GYRR"), new StringBuilder("RYYGYG"), new StringBuilder("GYGYRR"), new StringBuilder("RYGYRG"), new StringBuilder("YGYRYG"), new StringBuilder("GYRYRG"), new StringBuilder("YGYRYR"), new StringBuilder("YGYRYR"), new StringBuilder("YRRGRG"), new StringBuilder("RYGYGG"), new StringBuilder("GRYGYR"), new StringBuilder("GRYGYR"), new StringBuilder("GRYGYR") }; bool updated = true; while (updated) { breaked: DumpBlock(blocks); for (int i = 0; i < blocks.Length; i++) { for (int j = 0; j < blocks[i].Length; j++) { char c = blocks[i][j]; if (c == '*') continue; updated = false; if (KillBlocks(blocks, i, j)) { updated = true; goto breaked; } } } } DumpBlock(blocks); Console.Read(); } struct Point { public int x, y; public Point(int x, int y) { this.x = x; this.y = y; } } static bool KillBlocks(StringBuilder[] blocks, int x, int y) { bool[,] visted = new bool[blocks.Length,blocks[0].Length]; MarkBlock(visted, blocks, x, y); Queue<Point> queque = new Queue<Point>(); for (int i = x; i < blocks.Length; i++) for (int j = y; j < blocks[i].Length; j++) if(visted[i,j] == true) queque.Enqueue(new Point(j,i)); if (queque.Count < 4) return false; while (queque.Count > 0) { Point p = queque.Dequeue(); RemoveBlock(blocks, p.x, p.y); } return true; } static void MarkBlock(bool[,] visted, StringBuilder[] blocks, int x, int y) { if (x < 0 || y < 0 || x >= blocks.Length || y >= blocks[0].Length || visted[x, y] == true) return; char c = blocks[x][y]; visted[x, y] = true; if (x + 1 < blocks.Length && blocks[x + 1][y] == c) MarkBlock(visted, blocks, x + 1, y); if (y + 1 < blocks[0].Length && blocks[x][y + 1] == c) MarkBlock(visted, blocks, x, y + 1); if (x > 0 && blocks[x - 1][y] == c) MarkBlock(visted, blocks, x - 1, y); if (y > 0 && blocks[x][y - 1] == c) MarkBlock(visted, blocks, x, y - 1); } static void DumpBlock(StringBuilder[] blocks) { foreach (StringBuilder s in blocks) Console.WriteLine(s); Console.WriteLine(); } static void RemoveBlock(StringBuilder[] blocks,int x,int y) { int i; if (y == 0) { blocks[y][x] = '*'; return; } for (i = y; i > 0; i--) { blocks[i][x] = blocks[i - 1][x]; } blocks[i][x] = '*'; } } }
タグ「delphi」を含む注目エントリー - はてなブックマーク
Delphiアプリケーションのメモリリーク検出法 (山本隆の開発日誌)
http://www.componentsource.co.jp/features/delphi/
TMS Software | Productivity software building blocks
Components > Effects and Multimedia > Video. Torry's Delphi Pages
Components > Effects and Multimedia > Audio. Torry's Delphi Pages
Components > Effects and Multimedia > Voice. Torry's Delphi Pages
Components > Effects and Multimedia > Direct X. Torry's Delphi Pages
eXeScope(Windows95/98/Me / ユーティリティ)
Delphi-ML〓〓〓〓〓〓〓〓〓〓〓??About Delphi
Delphi Q & A 〓f〓〓〓〓 〓〓〓〓〓〓O〓〓(HTML〓o〓[〓W〓〓〓〓)
Delphi WAVEサウンド音を鳴らす/Tips & Tricks
5分ではじめるDelphi - 第1回 簡単なメディアプレーヤの作成(前編)
Controling sound volume from code
lsMicrophone: mxl.dwComponentType :=MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT
SwissDelphiCenter.ch : ...set the volume for the microphone/ mute it (enhanced)?
Components > Sound Effects > Mixer. Torry's Delphi Pages
PlaySound('C:\WINNT\Media\start.wav', 0, SND_FILENAME or SND_ASYNC);
Delphi6でプログラミング ビットマップの半透明コピー AlphaDraw
procedure TForm1.Button1Click(Sender: TObject);
bmp1.LoadFromFile('C:\Program Files\Common Files\Borland Shared\Images\Splash\256Color\FINANCE.BMP');
bmp2.LoadFromFile('C:\Program Files\Common Files\Borland Shared\Images\Splash\256Color\FACTORY.BMP');
Form1.Canvas.Draw(10,10,bmp1);
Form1.Image1.Canvas.Draw(10,10,bmp2);
bmp1.Free;
bmp2.Free;
無料版Delphi6でSTGをつくるためのプログラミング講座 Ver.2005 Jan.
SwissDelphiCenter.ch : ...get the MAC Address?
もっと楽にGUIとの連携がしたい:Python + Delphi = P4D(Python for Delphi) - ふにゃるん
Delphi WindowsのOSのバージョンを取得する/Tips & Tricks
SourceForge.net: Gecko SDK for Delphi
BDS(Delphi/BCB)用SQLiteライブラリ (山本隆の開発日誌)
SwissDelphiCenter.ch : programming tips
ナッキーの「Turbo Delphiはじめて奮戦記」- 第1回 Turbo Delphi のインストール
フリーのTurbo Delphiで始めるWindowsプログラミング:ITpro
フリーのTurbo Delphiで始めるWindowsプログラミング:ITpro
http://torrent.borland.com/turbo_hotfix_rollup.zip
http://torrent.borland.com/prereqs_jp.zip
http://torrent.borland.com/turbodelphi_jp.exe
(1) \dotNETRedist\dotnetfx.exe
(2) \dotNETRedist\langpack.exe
(3) \dotNETRedist\NDP1.1sp1-KB867460-X86.exe