クラスの定義をいろんな言語で書いてみた

まとめリンク: 同じことをいろんな言語で書いてみたシリーズ



C++

#include <iostream>
#include <stdio.h> //printf用
class Neko
{
  private:
    std::string name;
  public:
    Neko(std::string new_name)
    {
      name = new_name;
    };
    void hello()
    {
      std::cout << "吾輩は " << name << " である" << std::endl; // c++的にはこちらの方が一般的?
      printf("吾輩は %s である", name.c_str()); // prinfで出力する場合は c_strでchar*に変換する
    };
};
int main(int argc, char* argv[])
{
  Neko mike = Neko("ミケ");
  mike.hello();
};


Ruby

#!/usr/local/bin/ruby -Ku
class Neko
  def initialize(new_name)
    @name = new_name
  end
  def hello()
    puts("吾輩は #{@name} である")
  end
end
mike = Neko.new('ミケ')
mike.hello()


Crystal

class Neko
  @name: String
  def initialize(new_name)
    @name = new_name
  end
  def hello()
    puts("吾輩は #{@name} である")
  end
end
mike = Neko.new("ミケ")
mike.hello()


Rust

struct Neko {
  name: String,
}
impl Neko {
  fn hello(&self) {
    println!("吾輩は {} である", self.name);
  }
}
fn main() {
  let mike = Neko{name: "ミケ".to_string()};
  mike.hello();
}


Python3

#!/usr/bin/python3
class Neko:
  def __init__(self, new_name):
    self.name = new_name
  def hello(self):
    print(f"吾輩は {self.name} である")
mike = Neko("ミケ")
mike.hello()


Node.js

#!/usr/local/bin/node
class Neko{
  constructor(new_name){
    this.name = new_name;
  };
  hello(){
    console.log(`吾輩は ${this.name} である`);
  };
};
const mike = new Neko('ミケ');
mike.hello();


C#

namespace NekoApp
{
  class Neko
  {
    private string name;
    public Neko(string new_name)
    {
      name = new_name;
    }
    public void hello()
    {
      System.Console.WriteLine($"吾輩は {name} である");
    }
  }
  class NekoMain
  {
    static void Main()
    {
      Neko mike = new Neko("ミケ");
      mike.hello();
    }
  }
}

(NintendoSwitch)(マインクラフトBE版)ブレイズトラップを作った時の考え方

過去にアップしたブレイズトラップを作った時の考え方をテスト的にこちらのブログにも貼り付けてみます



Switchマインクラフト統合版でブレイズトラップを作った時の考え方

ブレイズをトラップの湧き範囲外に出してしまうと湧きペースに影響を与えないというのがミソのようです
かなり縦に長い構造になってしまうので処理層の高さまで下りていくとブレイズスポナーの活動自体が止まってしまうので
待機場所はスポナーが活動する所まで登った場所になります。

C#でメディアファイルをウインドウにドロップしたらそのメディアファイルの情報を表示する

このアプリを実行するとウインドウが表示されるので
そこにファイラーなどからメディアファイルをドロップしてください
そうすると、FFmpegのffprobe.exeを利用してその情報をウインドウに表示します

https://www.ffmpeg.org からffmpeg-xxxxxxxx-xxxxxxx-win64-static.zip をダウンロードして
その中にある ffprobe.exe をこのアプリと同じディレクトリに入れておいてください
(64bit版の場合、このアプリを管理者権限で実行してしまうと、管理者権限で実行中の物からしかドロップできませんので注意)


csc.exe -target:winexe mediafile_probe.cs

みたいな感じでコンパイルすればコマンドプロンプトは開きません

あと、フォントに「Yu Gothic UI」を指定してるので無い環境の場合は違うフォントを指定してください

using A_Console          = System.Console;
using A_Forms            = System.Windows.Forms;
using A_Application      = System.Windows.Forms.Application;
using A_DataFormats      = System.Windows.Forms.DataFormats;
using A_DragDropEffects  = System.Windows.Forms.DragDropEffects;
using A_DragEventArgs    = System.Windows.Forms.DragEventArgs;
using A_DragEventHandler = System.Windows.Forms.DragEventHandler;
using A_FormBorderStyle  = System.Windows.Forms.FormBorderStyle;
using A_MessageBox       = System.Windows.Forms.MessageBox;
using A_ScrollBars       = System.Windows.Forms.ScrollBars;
using A_TextBox          = System.Windows.Forms.TextBox;
using A_Process          = System.Diagnostics.Process;
using A_ProcessStartInfo = System.Diagnostics.ProcessStartInfo;
using A_Encoding         = System.Text.Encoding;
using A_Font             = System.Drawing.Font;
using A_FontStyle        = System.Drawing.FontStyle;
using A_GraphicsUnit     = System.Drawing.GraphicsUnit;
using A_Point            = System.Drawing.Point;
using A_Size             = System.Drawing.Size;

namespace AppMediaFileProbe
{
	public class Form1 : A_Forms.Form
	{
		private A_TextBox txt1;
		public Form1()
		{
			//Form1
			this.Name = "Form1";
			this.Text = "メディア情報解析 by ffprobe";
			this.ClientSize = new A_Size(1600, 800);
			this.FormBorderStyle = A_FormBorderStyle.FixedSingle;
			this.AllowDrop = true;
			this.DragDrop += new A_DragEventHandler(this.Form1_DragDrop);
			this.DragEnter += new A_DragEventHandler(this.Form1_DragEnter);
			//txt1
			this.txt1 = new A_TextBox();
			this.txt1.Name = "txt1";
			this.txt1.Font = new A_Font("Yu Gothic UI", 12F, A_FontStyle.Bold, A_GraphicsUnit.Point, ((byte)(128)));
			this.txt1.Location = new A_Point(5, 5);
			this.txt1.Multiline = true;
			this.txt1.ReadOnly = true;
			this.txt1.ScrollBars = A_ScrollBars.Both;
			this.txt1.Size = new A_Size(1590, 790);
			this.txt1.TabIndex = 1;
			this.Controls.Add(txt1);
		}
		private void Form1_DragDrop(object sender, A_DragEventArgs e)
		{
			string[] files = (string[])e.Data.GetData(A_DataFormats.FileDrop, false);
			txt1.Text = Call_ffprobe(files[0]);
		}
		private void Form1_DragEnter(object sender, A_DragEventArgs e)
		{
			if (e.Data.GetDataPresent(A_DataFormats.FileDrop))
			{
				e.Effect = A_DragDropEffects.Copy;
			}
		}
		private string Call_ffprobe(string file_name)
		{
			A_ProcessStartInfo psi = new A_ProcessStartInfo();
			psi.FileName = @".\ffprobe.exe";
			psi.Arguments = "\"" + file_name + "\"";
			psi.CreateNoWindow = true;
			psi.UseShellExecute = false;
			psi.RedirectStandardError = true;
			psi.StandardErrorEncoding = A_Encoding.UTF8;
			A_Process p = A_Process.Start(psi);
			return p.StandardError.ReadToEnd();
		}
		[System.STAThread]
		static void Main()
		{
			A_Application.EnableVisualStyles();
			A_Application.Run(new Form1());
		}
	}
}

C#でファイルのドラッグ&ドロップを受け付け出来るようにする

C#でFormを表示して ファイルのドロップを受け付けて
投げ込まれたもの(複数個なら最初の)が何だったのかをMessageBoxで表示します
以下のソースをcsc.exeに通すだけで出来ます(VisualStudioの環境は必須ではありません)

using A_Forms            = System.Windows.Forms;
using A_Application      = System.Windows.Forms.Application;
using A_DataFormats      = System.Windows.Forms.DataFormats;
using A_DragDropEffects  = System.Windows.Forms.DragDropEffects;
using A_DragEventArgs    = System.Windows.Forms.DragEventArgs;
using A_DragEventHandler = System.Windows.Forms.DragEventHandler;
using A_FormBorderStyle  = System.Windows.Forms.FormBorderStyle;
using A_MessageBox       = System.Windows.Forms.MessageBox;
using A_Size             = System.Drawing.Size;
using A_EventArgs        = System.EventArgs;
using A_EventHandler     = System.EventHandler;

namespace AppFileDrop
{
	public class Form1 : A_Forms.Form
	{
		public Form1()
		{
			this.Name = "Form1";
			this.ClientSize = new A_Size(800, 600);
			this.FormBorderStyle = A_FormBorderStyle.FixedSingle;
			this.Load += new A_EventHandler(this.Form1_Load);
			this.AllowDrop = true;
			this.DragDrop += new A_DragEventHandler(this.Form1_DragDrop);
			this.DragEnter += new A_DragEventHandler(this.Form1_DragEnter);
		}
		private void Form1_Load(object sender, A_EventArgs e)
		{
			// Form1.Load event
		}
		private void Form1_DragDrop(object sender, A_DragEventArgs e)
		{
			string[] files = (string[])e.Data.GetData(A_DataFormats.FileDrop, false);
			A_MessageBox.Show(files[0]);
		}
		private void Form1_DragEnter(object sender, A_DragEventArgs e)
		{
			if (e.Data.GetDataPresent(A_DataFormats.FileDrop))
			{
				e.Effect = A_DragDropEffects.Copy;
			}
		}
		[System.STAThread]
		static void Main()
		{
			A_Application.EnableVisualStyles();
			A_Application.Run(new Form1());
		}
	}
}

C#でフォント選択ダイアログを表示させる

細かなことは省いてただ単純に フォントを選択させてそれが何だったのかを表示させるだけです
VisualStudioを使う事も無く、単にcsc.exeにぶち込めばexeファイルが生成されます

using A_Console = System.Console;
using A_FontDialog = System.Windows.Forms.FontDialog;
namespace AppFontSelect
{
	class FontSelect
	{
		static void Main()
		{
			A_FontDialog fd = new A_FontDialog();
			fd.ShowDialog();
			A_Console.WriteLine(fd.Font.Name);
			A_Console.WriteLine(fd.Font.Size);
			A_Console.WriteLine(fd.Font.Style);
		}
	}
}