0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

cscの作法、調べてみた。
DxLibDotNet.dll、使ってみた。
練習問題やってみた。

練習問題

モグラ叩きを作れ。

写真

image.png

サンプルコード

using System;
using DxLibDLL;

class Test {
	[STAThread]
	static void Main() {
		int X;
		int Y;
		int[] cx = new int[9];
		int[] cy = new int[9];
		int[] cz = new int[9];
		int j;
		int k;
		int t1;
		int t2;
		int t3;
		int s;
		int g = 0;
		Random r = new Random();
		System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
		double ts;
		for (k = 0; k < 3; k++)
		{
			for (j = 0; j < 3; j++)
			{
				cx[k * 3 + j] = 30 + 160 * j;
				cy[k * 3 + j] = 30 + 160 * k;
				cz[k * 3 + j] = 1;
			}
		}
		uint red = DX.GetColor(255, 0, 0);
		DX.ChangeWindowMode(DX.TRUE);
		DX.SetGraphMode(640, 480, 32);
		if (DX.DxLib_Init() == -1)
			return;
		t1 = DX.LoadGraph("mogu_tan1.png");
		t2 = DX.LoadGraph("mogu_tan2.png");
		t3 = DX.LoadGraph("mogu_tan3.png");
		s = DX.LoadSoundMem("coin07.mp3");
		sw.Start();
		while (DX.ProcessMessage() == 0 && DX.CheckHitKey(DX.KEY_INPUT_ESCAPE) == 0)
		{
			DX.ClearDrawScreen();
			DX.DrawBox(0, 0, 640, 480, DX.GetColor(255, 255, 255), DX.TRUE);
			for (k = 0; k < 3; k++)
			{
				for (j = 0; j < 3; j++)
				{
					if (cz[k * 3 + j] < 3)
					{
						cz[k * 3 + j] = r.Next(2) + 1;
					}
				}
			}
			if ((DX.GetMouseInput() & DX.MOUSE_INPUT_LEFT) != 0)
			{
				DX.PlaySoundMem(s, DX.DX_PLAYTYPE_BACK);
				DX.GetMousePoint(out X, out Y);
				//Console.WriteLine(X);
				for (k = 0; k < 3; k++)
				{
					for (j = 0; j < 3; j++)
					{
						if (X > cx[k * 3 + j] && X < cx[k * 3 + j] + 120 && Y > cy[k * 3 + j] && Y < cy[k * 3 + j] + 120)
						{
							cz[k * 3 + j] = 3;
							g++;
						}
					}
				}
			}
			for (k = 0; k < 3; k++)
			{
				for (j = 0; j < 3; j++)
				{
					if (cz[k * 3 + j] == 1)
					{
						DX.DrawGraph(cx[k * 3 + j], cy[k * 3 + j], t1, DX.TRUE);
					}
					if (cz[k * 3 + j] == 2)
					{
						DX.DrawGraph(cx[k * 3 + j], cy[k * 3 + j], t2, DX.TRUE);
					}
					if (cz[k * 3 + j] == 3)
					{
						DX.DrawGraph(cx[k * 3 + j], cy[k * 3 + j], t3, DX.TRUE);
					}
				}
			}
			DX.ScreenFlip();
			DX.WaitTimer(800);
			ts = sw.ElapsedMilliseconds;
			if (ts > 30000)
			{
				break;
			}
			//Console.WriteLine(ts);
		}
		DX.SetFontSize(64);
		if (g == 9)
		{
			DX.DrawString(250, 240, "GAME CLEAR", DX.GetColor(0, 0, 255));
		}
		else
		{
			DX.DrawString(250, 240, "GAME OVER", DX.GetColor(255, 0, 0));
		}
		DX.ScreenFlip();
		DX.WaitTimer(5000);
		DX.DxLib_End();
	}
}





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?