Kodu nasıl çalıştırabilirim?

Affansen

Hectopat
Katılım
17 Nisan 2020
Mesajlar
4.766
Makaleler
1
Çözümler
29
Belki saçma bir konudur. :D

@The Anorak bir müzik kodu paylaşmıştı. Hem Arduino hem "C" galiba. Visual Studio'dan mı çalıştırılıyor?

@SideWinder @cengover_ekin @Mithat Berhan @The Anorak
C:
#define B0  31
#define C1  33
#define CS1 35
#define D1  37
#define DS1 39
#define E1  41
#define F1  44
#define FS1 46
#define G1  49
#define GS1 52
#define A1  55
#define AS1 58
#define B1  62
#define C2  65
#define CS2 69
#define D2  73
#define DS2 78
#define E2  82
#define F2  87
#define FS2 93
#define G2  98
#define GS2 104
#define A2  110
#define AS2 117
#define B2  123
#define C3  131
#define CS3 139
#define D3  147
#define DS3 156
#define E3  165
#define F3  175
#define FS3 185
#define G3  196
#define GS3 208
#define A3  220
#define AS3 233
#define B3  247
#define C4  262
#define CS4 277
#define D4  294
#define DS4 311
#define E4  330
#define F4  349
#define FS4 370
#define G4  392
#define GS4 415
#define A4  440
#define AS4 466
#define B4  494
#define C5  523
#define CS5 554
#define D5  587
#define DS5 622
#define E5  659
#define F5  698
#define FS5 740
#define G5  784
#define GS5 831
#define A5  880
#define AS5 932
#define B5  988
#define C6  1047
#define CS6 1109
#define D6  1175
#define DS6 1245
#define E6  1319
#define F6  1397
#define FS6 1480
#define G6  1568
#define GS6 1661
#define A6  1760
#define AS6 1865
#define B6  1976
#define C7  2093
#define CS7 2217
#define D7  2349
#define DS7 2489
#define E7  2637
#define F7  2794
#define FS7 2960
#define G7  3136
#define GS7 3322
#define A7  3520
#define AS7 3729
#define B7  3951
#define C8  4186
#define CS8 4435
#define D8  4699
#define DS8 4978
 
Kopyala yapıştır yapıp F5 tuşu ile çalıştırabilirsin Visual Studio'da. Tabii kütüphaneye ek bir kod girmek gerekmiyorsa, yoksa hata verir.
Hangi seçeneği seçeyim?
1601041802632.png
 
Bu kod, DOS'ta "dos.h" başlık dosyası ile düzgün çalışır. Windows NT mimarisine sahip işletim sistemlerinde bipleme olayı yok, sadece printf("\a"); yazdığınızda çıkardığı sesi çıkartıyor. Denemiştim zamanında.

DOSBox'ta deneyebilirsiniz Turbo C yükleyerek.


Edit: Zamanında Windows XP ile denemiştim fakat Windows 7 ile birlikte bipleme fonksiyonu ses kartı üzerinden yapılıyormuş. Kodun başına "Windows.h" başlık dosyasını eklemeyi unutmayın.
 
Son düzenleme:
C# ile çalmak istiyorsanız. #define olarak belirtilen notaları const olarak bir yere ekleyin.
(Proje olarak.
1601045523431.png
)
.NET Console App.

Çalmak istediğiniz note ve süre(duration) verisini Console.Beep() içerisine atıp. PC speaker'ı üzerinden ses alabilirsiniz.

Atılan kısım notaların, frekanks karşılığı. Tek başına bir melodi belirtmiyor.
 
Çok önceden yazdığım "Harder Better Faster Stronger" parçasının kodlarını az önce elden geçirdim.

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HarderBetterFasterStronger
{
    class HarderBetterFasterStrongerSong : Song
    {

        public HarderBetterFasterStrongerSong()
        {
            this.notes = new List<Note>();
            this.Build();
        }
        public override void Build()
        {
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.D5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(0, 500));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.A4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(0, 500));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.DS5, 250));
            notes.Add(new Note(Note.DS5, 250));
            notes.Add(new Note(Note.DS4, 250));
            notes.Add(new Note(Note.DS4, 250));
            notes.Add(new Note(Note.DS3, 250));
            notes.Add(new Note(Note.DS3, 250));
            notes.Add(new Note(Note.D3, 250));
            notes.Add(new Note(Note.D3, 250));
            notes.Add(new Note(0, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.D5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(0, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.A4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(0, 250));
            notes.Add(new Note(Note.E3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.E3, 250));
            notes.Add(new Note(Note.C4, 250));
            notes.Add(new Note(Note.AS3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.E3, 250));
            notes.Add(new Note(Note.DS3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.AS3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.AS3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.AS3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(0, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.D5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(0, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.A4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(0, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.DS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.D5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.A4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.E4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.DS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.A5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.DS6, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.A5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.DS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.A5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.E4, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.DS5, 250));
            notes.Add(new Note(Note.DS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.A5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.A5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.E4, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.DS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.DS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.D5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.A4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.E4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.DS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.A5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.E5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.DS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(0, 1000));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(0, 1000));
            notes.Add(new Note(Note.D5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(0, 1000));
            notes.Add(new Note(Note.AS3, 250));
            notes.Add(new Note(Note.AS3, 250));
            notes.Add(new Note(Note.C4, 250));
            notes.Add(new Note(Note.C4, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.G3, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.D5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.F5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.F4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.D5, 250));
            notes.Add(new Note(Note.C5, 250));
            notes.Add(new Note(Note.AS4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.D6, 250));
            notes.Add(new Note(Note.C6, 250));
            notes.Add(new Note(Note.AS5, 250));
            notes.Add(new Note(Note.G5, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
            notes.Add(new Note(Note.G4, 250));
        }

        public override void Play()
        {
            foreach(Note note in this.notes)
            {
                note.PlayNote();
            }
        }
    }
}
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HarderBetterFasterStronger
{
    class Note
    {
        public const int C3 = 130;
        public const int D3 = 147;
        public const int DS3 = 155;
        public const int E3 = 164;
        public const int F3 = 174;
        public const int G3 = 196;
        public const int A3 = 220;
        public const int AS3 = 233;
        public const int B3 = 247;
        public const int C4 = 261;
        public const int D4 = 293;
        public const int DS4 = 311;
        public const int E4 = 329;
        public const int F4 = 349;
        public const int G4 = 392;
        public const int A4 = 440;
        public const int AS4 = 466;
        public const int B4 = 494;
        public const int C5 = 523;
        public const int D5 = 587;
        public const int DS5 = 622;
        public const int E5 = 659;
        public const int F5 = 698;
        public const int G5 = 784;
        public const int A5 = 880;
        public const int AS5 = 932;
        public const int B5 = 988;
        public const int C6 = 1046;
        public const int D6 = 1174;
        public const int DS6 = 1244;
        public const int E6 = 1568;
        public const int F6 = 1397;
        public const int G6 = 1568;
        public const int A6 = 1760;
        public const int AS6 = 1864;
        public const int B6 = 1975;
        public const int C7 = 2093;
        public const int D7 = 2349;
        public const int DS7 = 2489;
        public const int E7 = 2637;
        public const int F7 = 2793;
        public const int G7 = 3136;
        public const int A7 = 3520;
        public const int AS7 = 3729;
        public const int B7 = 3951;

        public void PlayNote()
        {
            if (duration != 0)
            {
                if (note == 0)
                {
                    // Silence.
                    System.Threading.Thread.Sleep(this.duration);
                }
                else
                {
                    // Play it.
                    Console.Beep(this.note, this.duration);
                }
            }
        }

        private int note;
        private int duration;

        public Note(int note, int duration)
        {
            if (note >= 0)
            {
                this.note = note;
            }
            else
            {
                this.note = 0;
            }
            if (duration > 0)
            {
                this.duration = duration;
            }
            else
            {
                this.duration = 0;
            }
        }
    }
}
C#:
using System.Collections.Generic;

namespace HarderBetterFasterStronger
{
    abstract class Song
    {
        public List<Note> notes;
        public abstract void Build();
        public abstract void Play();
    }
}
C#:
using System;

namespace HarderBetterFasterStronger
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Press any key to Play");
            Console.ReadKey(true);
            HarderBetterFasterStrongerSong hbfss = new HarderBetterFasterStrongerSong();
            hbfss.Play();
        } 
    }
}


Dosya isimleri Class ifadesinden sonraki isim ile aynı olmalı. (Class Note ise Dosya ismi de "Note.cs" olmalı.)
Parçalı ve Object Oriented bir yapıda olduğu için birazcık karışık görünebilir.
 
Son düzenleme:

Yeni konular

Geri
Yukarı