Changeset 1208 for 2010/27


Ignore:
Timestamp:
2010-07-08 22:47:38 (13 years ago)
Author:
anlakane
Message:

Hienommat napit, nyt tosin vain neljä nappia. Pistelaskua ei ole vielä.

Location:
2010/27/anlakane/Nopeuspeli
Files:
10 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2010/27/anlakane/Nopeuspeli/Nopeuspeli.csproj

    r1207 r1208  
    5959    <Reference Include="Jypeli2, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86"> 
    6060      <SpecificVersion>False</SpecificVersion> 
    61       <HintPath>..\..\lib\Jypeli2.dll</HintPath> 
     61      <HintPath>..\..\..\..\..\npo\trunk\lib\Jypeli2.dll</HintPath> 
    6262    </Reference> 
    6363    <Reference Include="Microsoft.Xna.Framework, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d" /> 
  • 2010/27/anlakane/Nopeuspeli/Peli.cs

    r1207 r1208  
    88{ 
    99    List<GameObject> painikkeet; 
     10    List<GameObject> painamattomat; 
    1011    const double painikkeenLeveys = 100; 
    1112    const double painikkeenKorkeus = painikkeenLeveys; 
    1213    Timer painikkeidenSytytin; 
     14    Timer nopeutusAjastin; 
     15    Timer aikaaPainaaUuttaNappia; 
     16 
     17    int painikkeidenMaara; 
     18    int montakoPainikettaPainettu; 
    1319 
    1420    protected override void Begin() 
    1521    { 
    1622        painikkeet = new List<GameObject>(); 
     23        painamattomat = new List<GameObject>(); 
     24        painikkeidenMaara = 4; 
    1725 
     26        Level.Background.Image = LoadImage("tausta"); 
     27        Level.Background.Size = new Vector(Screen.Width, Screen.Height); 
     28        MessageDisplay.TextColor = Color.White; 
    1829        LisaaNappaimet(); 
    1930        LisaaPainikkeet(); 
     
    2435    void LisaaPainikkeet() 
    2536    { 
    26         for (int i = 0; i < 8; i++) 
     37        for (int i = 0; i < painikkeidenMaara; i++) 
    2738        { 
    2839            Add(LuoPainike()); 
    2940        } 
    30  
    3141    } 
    3242 
     
    3848        byte g = painike.Color.GreenComponent; 
    3949        byte b = painike.Color.BlueComponent; 
    40         r = (byte)((double)r / 2); 
    41         g = (byte)((double)g / 2); 
    42         b = (byte)((double)b / 2); 
     50        r = (byte)((double)r / 1.5); 
     51        g = (byte)((double)g / 1.5); 
     52        b = (byte)((double)b / 1.5); 
    4353        painike.Color = new Color(r, g, b); 
    4454 
    4555        painikkeet.Add(painike); 
    46         painike.X = -(4 * (painikkeenLeveys + 20)) + ((painikkeet.Count) * (painikkeenLeveys + 20)) - 60; 
     56        painike.X = -((painikkeidenMaara / 2) * (painikkeenLeveys + 20)) + ((painikkeet.Count) * (painikkeenLeveys + 20)) - 20; 
     57        painike.Tag = painikkeet.Count.ToString(); 
     58        painike.Image = LoadImage((painikkeet.Count - 1).ToString() + "_"); 
    4759        return painike; 
    4860    } 
     
    5062    void LisaaNappaimet() 
    5163    { 
     64        Keyboard.Listen(Key.A, ButtonState.Pressed, NappainPainettu, null, 0); 
     65        Keyboard.Listen(Key.S, ButtonState.Pressed, NappainPainettu, null, 1); 
     66        Keyboard.Listen(Key.D, ButtonState.Pressed, NappainPainettu, null, 2); 
     67        Keyboard.Listen(Key.F, ButtonState.Pressed, NappainPainettu, null, 3); 
     68        //Keyboard.Listen(Key.J, ButtonState.Pressed, NappainPainettu, null, 4); 
     69        //Keyboard.Listen(Key.K, ButtonState.Pressed, NappainPainettu, null, 5); 
     70        //Keyboard.Listen(Key.L, ButtonState.Pressed, NappainPainettu, null, 6); 
     71        //Keyboard.Listen(Key., ButtonState.Pressed, NappainPainettu, null, 7); 
    5272 
     73    } 
     74 
     75    void NappainPainettu(int painikeIndeksi) 
     76    { 
     77        if (painamattomat.Count < 1 || painamattomat[0].Tag.ToString() != (painikeIndeksi + 1).ToString()) 
     78        { 
     79            PeliPaattyy(new Timer()); 
     80        } 
     81        else 
     82        { 
     83            painamattomat.RemoveAt(0); 
     84            aikaaPainaaUuttaNappia.Reset(); 
     85        } 
     86    } 
     87 
     88    void PeliPaattyy(Timer t) 
     89    { 
     90        ClearTimers(); 
     91        for (int i = 0; i < painikkeet.Count; i++) 
     92            Sytyta(painikkeet[i], i); 
    5393    } 
    5494 
     
    5797        painikkeidenSytytin = new Timer(); 
    5898        painikkeidenSytytin.Interval = 1; 
    59         painikkeidenSytytin.Trigger += SytytaPainike; 
     99        painikkeidenSytytin.Trigger += SytytaJokinPainike; 
    60100        Add(painikkeidenSytytin); 
    61101        painikkeidenSytytin.Start(); 
     102 
     103        nopeutusAjastin = new Timer(); 
     104        nopeutusAjastin.Interval = 5; 
     105        nopeutusAjastin.Trigger += NopeutaPelia; 
     106        Add(nopeutusAjastin); 
     107        nopeutusAjastin.Start(); 
     108 
     109        aikaaPainaaUuttaNappia = new Timer(); 
     110        aikaaPainaaUuttaNappia.Interval = 3; 
     111        aikaaPainaaUuttaNappia.Trigger += PeliPaattyy; 
     112        Add(aikaaPainaaUuttaNappia); 
     113        aikaaPainaaUuttaNappia.Start(); 
    62114    } 
    63115 
    64     void SytytaPainike(Timer t) 
     116    void NopeutaPelia(Timer t) 
    65117    { 
    66         int sytytettavanIndeksi = RandomGen.NextInt(0, painikkeet.Count-1); 
    67         Color alkuperainenVari = painikkeet[sytytettavanIndeksi].Color; 
    68         List<double> varit = new List<double>();         
    69         double r = alkuperainenVari.RedComponent; 
    70         double g = alkuperainenVari.GreenComponent; 
    71         double b = alkuperainenVari.BlueComponent; 
    72         r *= 4; varit.Add(r); 
    73         g *= 4; varit.Add(g); 
    74         b *= 4; varit.Add(b); 
    75         for (int i = 0; i < varit.Count; i++) 
    76         { 
    77             if (varit[i] >= 255) 
    78             { 
    79                 varit[i] = 255; 
    80             } 
    81         } 
    82  
    83         r = (byte)varit[0]; g = (byte)varit[1]; b = (byte)varit[2]; 
    84  
    85         MessageDisplay.Add( 
    86             alkuperainenVari.RedComponent.ToString() + " " +  
    87             alkuperainenVari.GreenComponent.ToString() + " " +  
    88             alkuperainenVari.BlueComponent.ToString() + " -> " +  
    89             r.ToString() + " " +  
    90             g.ToString() + " " +  
    91             b.ToString()); 
    92         painikkeet[sytytettavanIndeksi].Color = new Color((byte)r, (byte)g, (byte)b); 
    93  
    94         Timer.SingleShot(t.Interval / 1.2, delegate() { Sammuta(alkuperainenVari, sytytettavanIndeksi); }); 
     118        painikkeidenSytytin.Interval /= 1.2; 
    95119    } 
    96120 
    97     void Sammuta(Color vari, int i) 
     121    void SytytaJokinPainike(Timer t) 
    98122    { 
    99         painikkeet[i].Color = vari; 
     123        int sytytettavanIndeksi = RandomGen.NextInt(0, painikkeet.Count - 1); 
     124        Color alkuperainenVari = painikkeet[sytytettavanIndeksi].Color; 
     125        Sytyta(painikkeet[sytytettavanIndeksi], sytytettavanIndeksi); 
     126        painamattomat.Add(painikkeet[sytytettavanIndeksi]); 
     127        Timer.SingleShot(t.Interval / 1.4, delegate() { Sammuta(sytytettavanIndeksi); }); 
    100128    } 
    101129 
     130    void Sytyta(GameObject sytytettava, int indeksi) 
     131    { 
     132        Color alkuperainenVari = sytytettava.Color; 
     133        double r = alkuperainenVari.RedComponent + 164; 
     134        double g = alkuperainenVari.GreenComponent + 164; 
     135        double b = alkuperainenVari.BlueComponent + 164; 
     136        if (r >= 255) r = 255; 
     137        if (g >= 255) g = 255; 
     138        if (b >= 255) b = 255; 
     139        sytytettava.Image = LoadImage(indeksi.ToString()); 
     140    } 
     141 
     142    void Sammuta(int i) 
     143    { 
     144        painikkeet[i].Image = LoadImage(i.ToString() + "_"); 
     145    } 
     146 
     147 
    102148} 
Note: See TracChangeset for help on using the changeset viewer.