u`
eLXgҁFp.321uO̊bv
Q[JKFe̕AG@̏o

13 O

p.321 O̊b

EႦ΁AZŃ[ZɂȂƎsG[ƂĈُI
E̎sG[OƂAO̎ނ󋵂ɂẮAُIė~Ȃꍇ
Ȅꍇɗpd|O
EOpƁAǑmƑΏ₷Lqł
EAɈُIׂOiFs̏ĵŁAOɂ͔zƒmKv

p.322 exception01.cs

//p.322 exception01.cs
using System;
class MyClass {
    public static void Main() {
        Console.Write("鐔--");
        string strA = Console.ReadLine();
        double a = double.Parse(strA); //`Ỏ\L
        Console.Write("鐔---");
        string strB = Console.ReadLine();
        double b = double.Parse(strB); //`Ỏ\L
        Console.WriteLine("{0}  {1} = {2}", a, b, a / b);
    }
}

p.322 exception01.cs̗Ȍɂ

Ep.322 exception01.csŁuavȂǂ̐lȊO͂̕ƎsG[ɂȂ
E̎̃bZ[Wɂĕ͂悤

nhĂȂO: System.FormatException: ͕̌`܂B
OȂƂ@O\NX(`O) ONX̎bZ[W
ꏊ System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
@@ۂɎsG[(O)ꏊiC#񋟂NXj
ꏊ System.Double.Parse(String s)
@@ۂɎsG[(O)\bhĂł郁\bh
ꏊ MyClass.Main() ꏊ D:\ha232_C#_omiya\Chap11\Chap11\exception01.cs:s 7
@@O\bhĂł郁\bhĂłvOƔsԍ

AWKFp.322 exception01.cs

EQϐdouble^ł͂Ȃint^ɂƁAL̂R̗O𔭐邱Ƃł
@@ `OFɕϊłȂ͂ꂽꍇ
@A [ZOFZŃ[ŏZꍇiZł͔Ȃj
@B I[o[t[OFϊʂint^͈̔͂𒴂ꍇiF22j
Eȏオ邱Ƃ

쐬

//AWKFp.322 exception01.cs
using System;
class MyClass {
    public static void Main() {
        Console.Write("鐔--");
        string strA = Console.ReadLine();
        int a = int.Parse(strA); //`OAI[o[t[Ỏ\L
        Console.Write("鐔---");
        string strB = Console.ReadLine();
        int b = int.Parse(strB); //`OAI[o[t[Ỏ\L
        Console.WriteLine("{0}  {1} = {2}", a, b, a / b); //[ZỎ\L
    }
}

si`Oj

鐔--a

nhĂȂO: System.FormatException: ͕̌`܂B
   ꏊ System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   ꏊ System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   ꏊ System.Int32.Parse(String s)
   ꏊ MyClass.Main() ꏊ D:\ha232_C#_omiya\Chap11\Chap11\exception01.cs:s 7

siI[o[t[Oj

鐔--2200000000
A
nhĂȂO: System.OverflowException: Int32 ^̒l傫邩A܂͏܂B
   ꏊ System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   ꏊ System.Int32.Parse(String s)
   ꏊ MyClass.Main() ꏊ D:\ha232_C#_omiya\Chap11\Chap11\exception01.cs:s 7

si[ZOj

鐔--5
鐔---0

nhĂȂO: System.DivideByZeroException: 0 ŏZ悤Ƃ܂B
   ꏊ MyClass.Main() ꏊ D:\ha232_C#_omiya\Chap11\Chap11\exception01.cs:s 11

p.323itryubNcatchubNj

EO̊{͏Ώۂ͈̔͂߂邱ƂłA܂͈͂tryubNɂ
EF try { OΏ }
EtryubN̒ŗOAɈُI邱Ƃ͂ȂȂAVXeO`̃`FbNƑΏsĂ
EȂAtryubN̓rŗOAO̗LɊւ炸AꏊtryubN̏I܂ł̋Lqe͎sȂ
EtryubNɂ1ȏcatchubNKvŁAȎΏLqB
EΏłvO͐탂[hɖ߂AcatchubN̎̍ssĊJB
EłPȏF try { OΏ } catch { O }

p.324 exception02.cs

//p.324 exception02.cs
using System;
class MyClass {
    public static void Main() {
        double a = 0.0, b = 0.0;
        Console.Write("鐔--");
        string strA = Console.ReadLine();
        try { //OΏۇ@
            a = double.Parse(strA); //`Ỏ\
        } catch { //@̗O
            Console.WriteLine("sK؂ȓ͂ł"); //\A𑱍s
        }
        Console.Write("鐔---");
        string strB = Console.ReadLine();
        try { //OΏۇA
            b = double.Parse(strB); //`Ỏ\
        } catch { //A̗O
            Console.WriteLine("sK؂ȓ͂ł");//\A𑱍s
        }
        Console.WriteLine("{0}  {1} = {2}", a, b, a / b);
    }
}

p.325 ONX

EOɗp̂C#`ĂO\NXŁAExceptionNX{NXƂhNXɂȂĂ
E܂Ae̗ÕO[vONX̌p֌Wɂĕ\Ă̂ŁA̔hNXʂ̊{NXňƂł
EcatchubNɈƂėONXLqłA̗Oɂ̂ݑΏ邱Ƃ\
E̎wɂuǂȗOłcatchĂ܂vƂɂ镾Qh~ł
EłPȏF try { OΏ } catch(ONX) { O }
EȂAO̒ŁAOɊւONX̃IuWFNgoRœ邱Ƃ\
ÉAOɔONX̃IuWFNgƂăVXeēāiāj邩ŁAcatchubNɈƂėONXƈw肷邱Ƃŗpł
EPȏF try { OΏ } catch(ONX ) { O }

p.325 ȗONX

EłɐONX
@System.FormatException: `O(ϊϊȂǂs)
@System.OverflowException: I[o[t[O(f[^̌^̍őlEŏl𒴂)
@System.DivideByZeroException: [ZO(Z0ŏZ)
Epo̗ONX
@System.IndexOutOfRangeException: zY͈͊OO(Yvfȏ܂0)
EȌڍׂc[\͌hLgŉ{\
@F https://learn.microsoft.com/ja-jp/dotnet/api/system.formatexception

p.326 ONX̎ȃo

EcatchubNɈƂėONXƈw肷邱ƂœOIuWFNg́AONXɋʂȃoi\bhƃvpeBjpē
Eڍׂ͌hLgŉ{\
@https://learn.microsoft.com/ja-jp/dotnet/api/system.exception?view=net-8.0
EȂAeLXgɋLڂToString()\bh́AONXɌ̂ł͂ȂAׂẴNXɂāȀԂ\bhƂċLq(I[o[Ch)ƂĂB

p.326 System.ObjectNX

EObject^Int32ȂǂƓl.NETt[[N^łA.NETt[[N^ɂׂ͂đΉNX܂͍\̂񋟂Ă
Eint^ȂǂƓlɁAobject^pƁA.NETt[[NObject^ƂĈ
Eobject/Object^ɑΉNXSystem.ObjectNXŁASẴNẌÖق̊{NX([gNX)ƂĒ`ĂApw肵ȂĂAIɗp
ESystem.ObjectNX̎Ă郁öToString()\bhȂ̂ŁAׂẴNXɂToString()\bh̃I[o[Ch\B
ÊƂ𗘗pāAIuWFNg(Qƕϐ)Console.WriteȂǂɎw肷ƁAIɁuQƕϐ.ToString()vs悤ɂȂĂB
F p.327 exception03.csŁuConsole.Write(io)vƁuConsole.Write(io.ToString())vsĂ邪ʂɂȂ

eLXgҎ\Fp.327uexception03.csv

Q[JKFe̕AG@̏o

otH[FK29 ẽAj[V

EeE]摜ƌ݂ɕ\邱ƂŁA]Ă悤Ɍ悤
E摜͉L𗘗p\
@https://rundog.org/si/bullet2.gif bullet2.gif 20x20

菇F

@ e摜2Ƃbullet2.gifǍ
A OnPaint\bhɂāAe``悷OɁA`摜̓ւs
@ Zqpƕ֗F
@ pb.i = (pb.i == bulleti) ? bullet2i : bulleti; //摜ݕύX

쐬

//K29 ẽAj[V
using System; //ėpIɗp
using System.Windows.Forms; //tH[AvP[VɕK{
using System.Drawing; //SizeAImagep
struct Item { //ACe\\
    public Image i; //摜
    public int x;  //SXW
    public int y;  //SYW
    public int hv; //Ȇx(͕̐AE͐̐)
    public int vv; //㉺̑x(͕̐A͐̐)
    public int v;  //\(0F\A1ȏF\)
}
class Program : Form { //FormNX̔hNX
    [System.Runtime.InteropServices.DllImport("user32.dll")] //DLLC|[g
    private static extern short GetKeyState(int nVirtKey); //O`w
    int gamemode = 0; //[h(0:^Cg,1:vC,9:I)
    int score = 0; //XRA
    Image backi = Image.FromFile("backb.bmp"); //wi摜Ǎ
    Image playeri = Image.FromFile("player.gif"); //@ʏ摜Ǎ
    Image playerl = Image.FromFile("playerl.gif"); //@摜Ǎ
    Image playerr = Image.FromFile("playerr.gif"); //@E摜Ǎ
    Image bulleti = Image.FromFile("bullet.gif"); //e摜Ǎ
    Image bullet2i = Image.FromFile("bullet2.gif"); //yǉze摜2Ǎ
    Pen pen1 = new Pen(Color.Red, 2); //ԐF2̃y
    Brush brush1 = new SolidBrush(Color.FromArgb(63, 255, 0, 0)); //ԂuV
    Font font1 = new Font("CI", 20, FontStyle.Bold); //tHg𐶐
    Font fontt = new Font("CI", 80, FontStyle.Bold); //tHg𐶐
    Font fontm = new Font("CI", 25, FontStyle.Bold); //tHg𐶐
    Brush brushs = new SolidBrush(Color.Yellow); //F̃uV
    Timer timer = new Timer(); //^C}[̐
    int backy = 0; //1ڂ̔wi`JnYW
    Item player; //@̍\̃IuWFNg
    Item pb; //e̍\̃IuWFNg
    //Wp摜`揈
    private void DrawItem(PaintEventArgs e, Item it) {
        int xx = it.x - it.i.Width / 2; //XW𓾂
        int yy = it.y - it.i.Height / 2; //YW𓾂
        e.Graphics.DrawImage(it.i, xx, yy);
    }
    //`揈̃I[oCh
    protected override void OnPaint(PaintEventArgs e) { 
        base.OnPaint(e); //{NX̕`揈Ă
        e.Graphics.DrawImage(backi, 0, backy); //wi摜`
        e.Graphics.DrawImage(backi, 0, backy - backi.Height); //wi摜`
        if (gamemode == 0) { //X^[gʁH
            e.Graphics.DrawString("GAME1", fontt, brushs, 100, 150); //^Cg\
            e.Graphics.DrawString("Hit Enter Key", fontm, brushs, 200, 300); //bZ[W\
        } else if (gamemode == 1) { //vCʁH
            string s = String.Format("SCORE:{0:000,000}", score); //XRA
            e.Graphics.DrawString(s, font1, brushs, 400, 10); //XRA\
            switch (player.hv) { //@̌ɂĕ
                case 0:  player.i = playeri; break; //ʏ摜ɂ
                case -1: player.i = playerl; break; //摜ɂ
                case 1:  player.i = playerr; break; //E摜ɂ
            }
            DrawItem(e, player); //@`
            if (pb.v == 1) { //eH
                pb.i = (pb.i == bulleti) ? bullet2i : bulleti; //yǉz摜ݕύX
                DrawItem(e, pb); //e`
            }
        }

    }
    //L[͎
    void OnKeyDown(object o, KeyEventArgs e) { 
        if (e.KeyCode.ToString() == "Escape") { //EscL[Ă
            Close(); //tH[I
        }
        //^CgʂEnterL[Ă
        if (gamemode == 0 && e.KeyCode.ToString() == "Return") { 
            gamemode = 1; //vCɑJ
            timer.Start(); //^C}[Jn
        }
        Invalidate(); //ʍĕ`˗
    }
    //^C}[Cxg
    void Play(object o, EventArgs e) { 
        backy = (backy + 1) % backi.Height; //1ڂ̔wi`JnYW
        player.hv = 0; //@̌𖳂ɂĂ
        if (player.x > playeri.Width / 2 && GetKeyState((int)Keys.Left) < 0) { //͈͓ŁL[ĂH
            player.x -= 10; //@
            player.hv = -1; //
        }
        if (player.x < backi.Width - playeri.Width / 2 && GetKeyState((int)Keys.Right) < 0) { //͈͓ŁL[ĂH
            player.x += 10; //@E
            player.hv = 1; //E
        }
        if (GetKeyState((int)Keys.Space) < 0) { //Xy[XL[ĂH
            if (pb.v == 0) { //e\H
                pb.v = 1; //\ɂ
                pb.i = bulleti; //摜
                pb.x = player.x; //XW͎@Ɠ
                pb.y = player.y - player.i.Height / 2 - pb.i.Height / 2; //YW͎@̒
                pb.vv = -5; //ړx
            }
        }
        if (pb.v != 0) { //e݁H
            pb.y += pb.vv; //ֈړ
            if (pb.y + pb.i.Height / 2 < 0) { //ʏ[ɏo
                pb.v = 0; //e
            }
        }
        Invalidate(); //ʍĕ`˗
    }
    //RXgN^
    Program() { 
        DoubleBuffered = true; //_uobt@OL
        KeyDown += new KeyEventHandler(OnKeyDown); //L[̓Cxgo^
        timer.Tick += new EventHandler(Play); //^C}[Cxgo^
        timer.Interval = 10; //^C}[C^[o(~b)
        player.i = playeri;  //@̉摜
        player.x = 320; //@̒SXW
        player.y = 410; //@̒SYW
        player.hv = 0;  //@̍Ȇx
    }
    public static void Main() {
        Program f = new Program(); //̃IuWFNg𐶐
        f.Size = new Size(660, 520); //tH[̃TCYݒ
        f.Text = "Game"; //tH[ݒ
        f.ControlBox = false; //Rg[{bNX\
        f.FormBorderStyle = FormBorderStyle.Fixed3D; //TCYύX}~
        Application.Run(f); //tH[o
    }
}

K30 e̕

Ee10ɂ悤
EXy[XL[Əɔ˂Aʏ10鎞́AĂ
EʒuȂǂ͒eƂɎAʏ㕔Aēxˉ\Ƃ

菇F

@ e̍ő吔萔maxpbŕێl10Ƃ
A e̍\̃IuWFNgAvfmaxpb̔zpbaɂ
B OnPaint\bhɂāAe``悷鏈A
@ueΕ`悷vSeɂČJԂ悤ɕύX
@摜̌ݕϊPlay\bhɈڂ
C Play\bhɂāAXy[XL[ĂƂ̏A
@u\̎e甭˂vSeɂČJԂ悤ɕύX
@ȂA1甲邱
D ܂ueΉ摜؂ւAֈړA[ɂȂ\ɂv
@SeɂČJԂ悤ɕύX

쐬

//K30 e̕
using System; //ėpIɗp
using System.Windows.Forms; //tH[AvP[VɕK{
using System.Drawing; //SizeAImagep
struct Item { //ACe\\
    public Image i; //摜
    public int x;  //SXW
    public int y;  //SYW
    public int hv; //Ȇx(͕̐AE͐̐)
    public int vv; //㉺̑x(͕̐A͐̐)
    public int v;  //\(0F\A1ȏF\)
}
class Program : Form { //FormNX̔hNX
    [System.Runtime.InteropServices.DllImport("user32.dll")] //DLLC|[g
    private static extern short GetKeyState(int nVirtKey); //O`w
    int gamemode = 0; //[h(0:^Cg,1:vC,9:I)
    int score = 0; //XRA
    Image backi = Image.FromFile("backb.bmp"); //wi摜Ǎ
    Image playeri = Image.FromFile("player.gif"); //@ʏ摜Ǎ
    Image playerl = Image.FromFile("playerl.gif"); //@摜Ǎ
    Image playerr = Image.FromFile("playerr.gif"); //@E摜Ǎ
    Image bulleti = Image.FromFile("bullet.gif"); //e摜Ǎ
    Image bullet2i = Image.FromFile("bullet2.gif"); //e摜2Ǎ
    Pen pen1 = new Pen(Color.Red, 2); //ԐF2̃y
    Brush brush1 = new SolidBrush(Color.FromArgb(63, 255, 0, 0)); //ԂuV
    Font font1 = new Font("CI", 20, FontStyle.Bold); //tHg𐶐
    Font fontt = new Font("CI", 80, FontStyle.Bold); //tHg𐶐
    Font fontm = new Font("CI", 25, FontStyle.Bold); //tHg𐶐
    Brush brushs = new SolidBrush(Color.Yellow); //F̃uV
    Timer timer = new Timer(); //^C}[̐
    int backy = 0; //1ڂ̔wi`JnYW
    Item player; //@̍\̃IuWFNg
    const int maxpb = 10; //yǉze̍ő吔
    Item[] pba = new Item[maxpb]; //yύXze̍\̃IuWFNgz
    //Wp摜`揈
    private void DrawItem(PaintEventArgs e, Item it) {
        int xx = it.x - it.i.Width / 2; //XW𓾂
        int yy = it.y - it.i.Height / 2; //YW𓾂
        e.Graphics.DrawImage(it.i, xx, yy);
    }
    //`揈̃I[oCh
    protected override void OnPaint(PaintEventArgs e) { 
        base.OnPaint(e); //{NX̕`揈Ă
        e.Graphics.DrawImage(backi, 0, backy); //wi摜`
        e.Graphics.DrawImage(backi, 0, backy - backi.Height); //wi摜`
        if (gamemode == 0) { //X^[gʁH
            e.Graphics.DrawString("GAME1", fontt, brushs, 100, 150); //^Cg\
            e.Graphics.DrawString("Hit Enter Key", fontm, brushs, 200, 300); //bZ[W\
        } else if (gamemode == 1) { //vCʁH
            string s = String.Format("SCORE:{0:000,000}", score); //XRA
            e.Graphics.DrawString(s, font1, brushs, 400, 10); //XRA\
            switch (player.hv) { //@̌ɂĕ
                case 0:  player.i = playeri; break; //ʏ摜ɂ
                case -1: player.i = playerl; break; //摜ɂ
                case 1:  player.i = playerr; break; //E摜ɂ
            }
            DrawItem(e, player); //@`
            foreach (var pb in pba) { //yǉzSeɂČJԂ
                if (pb.v == 1) { //eH
                    DrawItem(e, pb); //e`
                }
            }
        }

    }
    //L[͎
    void OnKeyDown(object o, KeyEventArgs e) { 
        if (e.KeyCode.ToString() == "Escape") { //EscL[Ă
            Close(); //tH[I
        }
        //^CgʂEnterL[Ă
        if (gamemode == 0 && e.KeyCode.ToString() == "Return") { 
            gamemode = 1; //vCɑJ
            timer.Start(); //^C}[Jn
        }
        Invalidate(); //ʍĕ`˗
    }
    //^C}[Cxg
    void Play(object o, EventArgs e) { 
        backy = (backy + 1) % backi.Height; //1ڂ̔wi`JnYW
        player.hv = 0; //@̌𖳂ɂĂ
        if (player.x > playeri.Width / 2 && GetKeyState((int)Keys.Left) < 0) { //͈͓ŁL[ĂH
            player.x -= 10; //@
            player.hv = -1; //
        }
        if (player.x < backi.Width - playeri.Width / 2 && GetKeyState((int)Keys.Right) < 0) { //͈͓ŁL[ĂH
            player.x += 10; //@E
            player.hv = 1; //E
        }
        if (GetKeyState((int)Keys.Space) < 0) { //Xy[XL[ĂH
            for (int i = 0; i < maxpb; i++) { //yǉzSeɂČJԂ
                if (pba[i].v == 0) { //yύXze\H
                    pba[i].v = 1; //yύXz\ɂ
                    pba[i].i = bulleti; //yύXz摜
                    pba[i].x = player.x; //yύXzXW͎@Ɠ
                    pba[i].y = player.y - player.i.Height / 2 - pba[i].i.Height / 2; //yύXzYW͎@̒
                    pba[i].vv = -5; //yύXzړx
                    break; //yǉz1˂łOK
                }
            }
        }
        for (int i = 0; i < maxpb; i++) { //yǉzSeɂČJԂ
            if (pba[i].v != 0) { //yύXze݁H
                pba[i].i = (pba[i].i == bulleti) ? bullet2i : bulleti; //yړύXz摜ݕύX
                pba[i].y += pba[i].vv; //yύXzֈړ
                if (pba[i].y + pba[i].i.Height / 2 < 0) { //yύXzʏ[ɏo
                    pba[i].v = 0; //yύXze
                }
            }
        }
        Invalidate(); //ʍĕ`˗
    }
    //RXgN^
    Program() { 
        DoubleBuffered = true; //_uobt@OL
        KeyDown += new KeyEventHandler(OnKeyDown); //L[̓Cxgo^
        timer.Tick += new EventHandler(Play); //^C}[Cxgo^
        timer.Interval = 10; //^C}[C^[o(~b)
        player.i = playeri;  //@̉摜
        player.x = 320; //@̒SXW
        player.y = 410; //@̒SYW
        player.hv = 0;  //@̍Ȇx
    }
    public static void Main() {
        Program f = new Program(); //̃IuWFNg𐶐
        f.Size = new Size(660, 520); //tH[̃TCYݒ
        f.Text = "Game"; //tH[ݒ
        f.ControlBox = false; //Rg[{bNX\
        f.FormBorderStyle = FormBorderStyle.Fixed3D; //TCYύX}~
        Application.Run(f); //tH[o
    }
}

e[}29 p

EɃANVnQ[ɂāAvC[̋ɍ킹ĕ̂̕𓮂ꍇu{^ĂԁAAďvƂƁAPŕKvȏ̐̂̕ɉeĂ܂ƂB
ÉAvO̓쑬xP啝ɑƂB
EɁAA˂\ɂĂꍇÂƂւ̔zKv
Ehɂ́AP̂̓ォ莞Ԃ̓s\ԁpԂĂΗǂ
E쒼Ƀ^C~OvϐZbgăJEg_EsA[ɂȂA̓\ƂƗǂ
E{^ɂA˂\ɂꍇ́A{^̏󋵂ĎĎ肪ꂽA^C~O͂ϐ[ɂΗǂ

K31 e˂̉

EXy[XL[ςȂ̏ꍇ́A̒e̔˂܂œKȗpԂuƂɂ悤
EXy[XL[ĂȂApԂȂŎ̒e̔˂\ɂ悤

菇F

@ pԂ萔coldŕێl10Ƃ
A eˑ҂ϐwaitpbŕ\l0Ƃ
B Xy[XL[ꂽƂAwaitpb0Ȃ玩e𔭎˂
C e𔭎˂AwaitpbcoldėpԂƂ悤
D play\bhɂāAwaitpb0ȏȂ0܂ŃJEg_E悤
E play\bhɂāAXy[XL[ĂȂ΁Awaitpb0ɂ悤

쐬

//K31 e˂̉
using System; //ėpIɗp
using System.Windows.Forms; //tH[AvP[VɕK{
using System.Drawing; //SizeAImagep
struct Item { //ACe\\
    public Image i; //摜
    public int x;  //SXW
    public int y;  //SYW
    public int hv; //Ȇx(͕̐AE͐̐)
    public int vv; //㉺̑x(͕̐A͐̐)
    public int v;  //\(0F\A1ȏF\)
}
class Program : Form { //FormNX̔hNX
    [System.Runtime.InteropServices.DllImport("user32.dll")] //DLLC|[g
    private static extern short GetKeyState(int nVirtKey); //O`w
    int gamemode = 0; //[h(0:^Cg,1:vC,9:I)
    int score = 0; //XRA
    Image backi = Image.FromFile("backb.bmp"); //wi摜Ǎ
    Image playeri = Image.FromFile("player.gif"); //@ʏ摜Ǎ
    Image playerl = Image.FromFile("playerl.gif"); //@摜Ǎ
    Image playerr = Image.FromFile("playerr.gif"); //@E摜Ǎ
    Image bulleti = Image.FromFile("bullet.gif"); //e摜Ǎ
    Image bullet2i = Image.FromFile("bullet2.gif"); //e摜2Ǎ
    Pen pen1 = new Pen(Color.Red, 2); //ԐF2̃y
    Brush brush1 = new SolidBrush(Color.FromArgb(63, 255, 0, 0)); //ԂuV
    Font font1 = new Font("CI", 20, FontStyle.Bold); //tHg𐶐
    Font fontt = new Font("CI", 80, FontStyle.Bold); //tHg𐶐
    Font fontm = new Font("CI", 25, FontStyle.Bold); //tHg𐶐
    Brush brushs = new SolidBrush(Color.Yellow); //F̃uV
    Timer timer = new Timer(); //^C}[̐
    int backy = 0; //1ڂ̔wi`JnYW
    Item player; //@̍\̃IuWFNg
    const int maxpb = 10; //e̍ő吔
    Item[] pba = new Item[maxpb]; //e̍\̃IuWFNgz
    const int cold = 10; //yǉze˂̗p
    int waitpb = 0; //yǉze˂̑҂
    //Wp摜`揈
    private void DrawItem(PaintEventArgs e, Item it) {
        int xx = it.x - it.i.Width / 2; //XW𓾂
        int yy = it.y - it.i.Height / 2; //YW𓾂
        e.Graphics.DrawImage(it.i, xx, yy);
    }
    //`揈̃I[oCh
    protected override void OnPaint(PaintEventArgs e) { 
        base.OnPaint(e); //{NX̕`揈Ă
        e.Graphics.DrawImage(backi, 0, backy); //wi摜`
        e.Graphics.DrawImage(backi, 0, backy - backi.Height); //wi摜`
        if (gamemode == 0) { //X^[gʁH
            e.Graphics.DrawString("GAME1", fontt, brushs, 100, 150); //^Cg\
            e.Graphics.DrawString("Hit Enter Key", fontm, brushs, 200, 300); //bZ[W\
        } else if (gamemode == 1) { //vCʁH
            string s = String.Format("SCORE:{0:000,000}", score); //XRA
            e.Graphics.DrawString(s, font1, brushs, 400, 10); //XRA\
            switch (player.hv) { //@̌ɂĕ
                case 0:  player.i = playeri; break; //ʏ摜ɂ
                case -1: player.i = playerl; break; //摜ɂ
                case 1:  player.i = playerr; break; //E摜ɂ
            }
            DrawItem(e, player); //@`
            foreach (var pb in pba) { //SeɂČJԂ
                if (pb.v == 1) { //eH
                    DrawItem(e, pb); //e`
                }
            }
        }

    }
    //L[͎
    void OnKeyDown(object o, KeyEventArgs e) { 
        if (e.KeyCode.ToString() == "Escape") { //EscL[Ă
            Close(); //tH[I
        }
        //^CgʂEnterL[Ă
        if (gamemode == 0 && e.KeyCode.ToString() == "Return") { 
            gamemode = 1; //vCɑJ
            timer.Start(); //^C}[Jn
        }
        Invalidate(); //ʍĕ`˗
    }
    //^C}[Cxg
    void Play(object o, EventArgs e) { 
        backy = (backy + 1) % backi.Height; //1ڂ̔wi`JnYW
        player.hv = 0; //@̌𖳂ɂĂ
        if (player.x > playeri.Width / 2 && GetKeyState((int)Keys.Left) < 0) { //͈͓ŁL[ĂH
            player.x -= 10; //@
            player.hv = -1; //
        }
        if (player.x < backi.Width - playeri.Width / 2 && GetKeyState((int)Keys.Right) < 0) { //͈͓ŁL[ĂH
            player.x += 10; //@E
            player.hv = 1; //E
        }
        if (GetKeyState((int)Keys.Space) < 0) { //Xy[XL[ĂH
            if (waitpb <= 0) { //yǉzeˑ҂Ԃ[H
                for (int i = 0; i < maxpb; i++) { //SeɂČJԂ
                    if (pba[i].v == 0) { //e\H
                        pba[i].v = 1; //\ɂ
                        pba[i].i = bulleti; //摜
                        pba[i].x = player.x; //XW͎@Ɠ
                        pba[i].y = player.y - player.i.Height / 2 - pba[i].i.Height / 2; //YW͎@̒
                        pba[i].vv = -5; //ړx
                        waitpb = cold; //yǉzeˑ҂ԂZbg
                        break; //1˂łOK
                    }
                }
            }
        } else { //yȉǉzXy[XL[ĂȂH
            waitpb = 0; //eˑ҂Ԃ[ɂĔˉ\ɂ
        }
        for (int i = 0; i < maxpb; i++) { //SeɂČJԂ
            if (pba[i].v != 0) { //e݁H
                pba[i].i = (pba[i].i == bulleti) ? bullet2i : bulleti; //摜ݕύX
                pba[i].y += pba[i].vv; //ֈړ
                if (pba[i].y + pba[i].i.Height / 2 < 0) { //ʏ[ɏo
                    pba[i].v = 0; //e
                }
            }
        }
        if (waitpb > 0) { //yȉǉzeˑ҂ԂZbgĂ
            waitpb--; //JEg_E
        }
        Invalidate(); //ʍĕ`˗
    }
    //RXgN^
    Program() { 
        DoubleBuffered = true; //_uobt@OL
        KeyDown += new KeyEventHandler(OnKeyDown); //L[̓Cxgo^
        timer.Tick += new EventHandler(Play); //^C}[Cxgo^
        timer.Interval = 10; //^C}[C^[o(~b)
        player.i = playeri;  //@̉摜
        player.x = 320; //@̒SXW
        player.y = 410; //@̒SYW
        player.hv = 0;  //@̍Ȇx
    }
    public static void Main() {
        Program f = new Program(); //̃IuWFNg𐶐
        f.Size = new Size(660, 520); //tH[̃TCYݒ
        f.Text = "Game"; //tH[ݒ
        f.ControlBox = false; //Rg[{bNX\
        f.FormBorderStyle = FormBorderStyle.Fixed3D; //TCYύX}~
        Application.Run(f); //tH[o
    }
}

oFK31 e˂̉ǁiłOKj

Q[JK\FG@̏oAG@̈ړAՓ˔
