Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
M1888
lottokone
Commits
da72682e
Commit
da72682e
authored
Apr 19, 2019
by
M1888
Browse files
päiväkoodailut
parent
79d4500a
Changes
23
Hide whitespace changes
Inline
Side-by-side
Lottokone/App.xaml
View file @
da72682e
...
...
@@ -27,8 +27,7 @@
</Style>
<Style TargetType="TextBox" x:Key="Lottonumero">
<Setter Property="Width" Value="50" />
<Setter Property="MinWidth" Value="20"/>
<Setter Property="Width" Value="10" />
<Setter Property="Margin" Value="3" />
</Style>
...
...
Lottokone/Asetukset.xaml
View file @
da72682e
...
...
@@ -73,7 +73,7 @@
<StackPanel>
<DockPanel Margin="5">
<Label>Vakiorivejä</Label>
<TextBox Style="{StaticResource Asetusboksi}" x:Name="txbVakiorivit" Text="{Binding Vakiorivit, Mode=TwoWay}" TextChanged="
txb
Changed" />
<TextBox Style="{StaticResource Asetusboksi}" x:Name="txbVakiorivit" Text="{Binding Vakiorivit, Mode=TwoWay}" TextChanged="
TxbVakiorivit_Text
Changed" />
</DockPanel>
<TextBlock Margin="25,-5,0,0">Montako vakioriviä haluat pelata?</TextBlock>
<Button Content="Aseta rivit" Width="100" x:Name="btnRivit" Click="BtnRivit_Click" />
...
...
Lottokone/Asetukset.xaml.cs
View file @
da72682e
...
...
@@ -59,5 +59,30 @@ namespace Lottokone
}
}
}
private
void
TxbVakiorivit_TextChanged
(
object
sender
,
TextChangedEventArgs
e
)
{
TextBox
tb
=
sender
as
TextBox
;
if
(
tb
!=
null
)
{
bool
ok
=
false
;
if
(
int
.
TryParse
(
tb
.
Text
,
out
int
result
))
{
if
(
result
>=
0
&&
result
<=
15
)
ok
=
true
;
}
if
(!
ok
)
{
lblInfo
.
Content
=
"Vakiorivejä voi olla 0-15 kpl"
;
btnRivit
.
IsEnabled
=
false
;
}
else
{
lblInfo
.
Content
=
""
;
btnRivit
.
IsEnabled
=
true
;
}
}
}
}
}
Lottokone/Lottokone.csproj
View file @
da72682e
...
...
@@ -78,7 +78,13 @@
<Compile
Include=
"Lottorivit.xaml.cs"
>
<DependentUpon>
Lottorivit.xaml
</DependentUpon>
</Compile>
<Compile
Include=
"Rikkaimmat.xaml.cs"
>
<DependentUpon>
Rikkaimmat.xaml
</DependentUpon>
</Compile>
<Compile
Include=
"Settings.cs"
/>
<Compile
Include=
"ViewModel\Nimigeneraattori.cs"
/>
<Compile
Include=
"ViewModel\Riviapuri.cs"
/>
<Compile
Include=
"ViewModel\Scoreboard.cs"
/>
<Compile
Include=
"Voitto.xaml.cs"
>
<DependentUpon>
Voitto.xaml
</DependentUpon>
</Compile>
...
...
@@ -105,6 +111,10 @@
<DependentUpon>
MainWindow.xaml
</DependentUpon>
<SubType>
Code
</SubType>
</Compile>
<Page
Include=
"Rikkaimmat.xaml"
>
<SubType>
Designer
</SubType>
<Generator>
MSBuild:Compile
</Generator>
</Page>
<Page
Include=
"Voitto.xaml"
>
<SubType>
Designer
</SubType>
<Generator>
MSBuild:Compile
</Generator>
...
...
@@ -138,6 +148,15 @@
<Generator>
SettingsSingleFileGenerator
</Generator>
<LastGenOutput>
Settings.Designer.cs
</LastGenOutput>
</None>
<None
Include=
"Resources\etunimet.csv"
>
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
</None>
<None
Include=
"Resources\lotto.sqlite"
>
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
</None>
<None
Include=
"Resources\sukunimet.csv"
>
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None
Include=
"App.config"
/>
...
...
@@ -154,6 +173,9 @@
<Resource
Include=
"Resources\lotto2.png"
/>
<Resource
Include=
"Resources\lotto3.png"
/>
</ItemGroup>
<ItemGroup>
<Content
Include=
"Resources\create-lotto.sql"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Import
Project=
"packages\System.Data.SQLite.Core.1.0.110.0\build\net46\System.Data.SQLite.Core.targets"
Condition=
"Exists('packages\System.Data.SQLite.Core.1.0.110.0\build\net46\System.Data.SQLite.Core.targets')"
/>
<Target
Name=
"EnsureNuGetPackageBuildImports"
BeforeTargets=
"PrepareForBuild"
>
...
...
Lottokone/Lottorivit.xaml
View file @
da72682e
...
...
@@ -7,11 +7,5 @@
mc:Ignorable="d"
Title="Lottorivit" Height="450" Width="400">
<Grid x:Name="grdRivit">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
</Grid>
</Window>
Lottokone/Lottorivit.xaml.cs
View file @
da72682e
using
System
;
using
Lottokone.Model
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
...
...
@@ -23,58 +24,129 @@ namespace Lottokone
private
Button
btnSave
;
private
Label
lblInfo
;
// Tähän listaan tehdään uusi lista jokaista lottoriviä varten.
// Siihen listaan sitten lisätään nuo kyseisen rivin TextBoxit, jotta ne saa
// käytyä myöhemmin järjestyksessä läpi, kun rivit tallentaa.
private
List
<
List
<
TextBox
>>
numerot
;
// Tähän haetaan kannasta tallennetut rivit, joilla täytetään kentät valmiiksi
private
List
<
Lottorivi
>
rivit
;
public
Lottorivit
()
{
InitializeComponent
();
NaytaKontrollit
();
}
p
ublic
void
NaytaKontrollit
()
p
rivate
void
NaytaKontrollit
()
{
this
.
Height
=
80
+
Properties
.
Settings
.
Default
.
Vakiorivit
*
40
;
numerot
=
new
List
<
List
<
TextBox
>>();
grdRivit
.
RowDefinitions
.
Add
(
new
RowDefinition
());
btnSave
=
new
Button
();
btnSave
.
Content
=
"Tallenna"
;
btnSave
.
Margin
=
new
Thickness
(
5
);
btnSave
.
Click
+=
btnSave_Click
;
Grid
.
SetRow
(
btnSave
,
Properties
.
Settings
.
Default
.
Vakiorivit
);
Grid
.
SetColumnSpan
(
btnSave
,
2
);
grdRivit
.
Children
.
Add
(
btnSave
);
grdRivit
.
RowDefinitions
.
Add
(
new
RowDefinition
());
lblInfo
=
new
Label
();
lblInfo
.
Style
=
Resources
[
"Isompi"
]
as
Style
;
lblInfo
.
Margin
=
new
Thickness
(
5
);
Grid
.
SetRow
(
lblInfo
,
Properties
.
Settings
.
Default
.
Vakiorivit
+
1
);
Grid
.
SetColumnSpan
(
lblInfo
,
8
);
grdRivit
.
Children
.
Add
(
lblInfo
);
try
{
rivit
=
ViewModel
.
Riviapuri
.
Lataa
(
Properties
.
Settings
.
Default
.
Vakiorivit
);
}
catch
(
Exception
ex
)
{
MessageBox
.
Show
(
$"Virhe:
{
ex
.
Message
}
"
);
}
for
(
int
i
=
0
;
i
<
8
;
i
++)
grdRivit
.
ColumnDefinitions
.
Add
(
new
ColumnDefinition
());
/*
StackPanel rivit = new StackPanel();
for
(
int
i
=
0
;
i
<
Properties
.
Settings
.
Default
.
Vakiorivit
;
i
++)
{
StackPanel rivi = new StackPanel();
rivi.Orientation = Orientation.Horizontal;
rivi.Name = $"spRivi{i}";
Grid.SetRow(rivi, i);
numerot
.
Add
(
new
List
<
TextBox
>());
grdRivit
.
RowDefinitions
.
Add
(
new
RowDefinition
());
Label
l
=
new
Label
();
l.Content = $"Rivi {i}: ";
rivi.Children.Add(l);
l
.
Content
=
$"Rivi
{
i
+
1
}
"
;
Grid
.
SetRow
(
l
,
i
);
Grid
.
SetColumn
(
l
,
0
);
grdRivit
.
Children
.
Add
(
l
);
for
(
int
j
=
0
;
j
<
7
;
j
++)
{
TextBox
tb
=
new
TextBox
();
tb
.
Style
=
Resources
[
"Lottonumero"
]
as
Style
;
tb
.
Width
=
25
;
tb
.
Height
=
25
;
tb
.
Margin
=
new
Thickness
(
3
,
0
,
3
,
0
);
tb
.
VerticalAlignment
=
VerticalAlignment
.
Top
;
tb
.
GotFocus
+=
txbFocus
;
tb
.
TextChanged
+=
txbChanged
;
Grid.SetColumn(tb, j);
rivi.Children.Add(tb);
tb
.
Text
=
rivit
[
i
].
Numerot
[
j
].
ToString
();
Grid
.
SetRow
(
tb
,
i
);
Grid
.
SetColumn
(
tb
,
j
+
1
);
grdRivit
.
Children
.
Add
(
tb
);
numerot
[
i
].
Add
(
tb
);
}
rivit.Children.Add(rivi);
}
grdRivit.Children.Add(rivit);
StackPanel spAlarivi = new StackPanel();
Grid.SetRow(spAlarivi, Properties.Settings.Default.Vakiorivit);
btnSave = new Button();
btnSave.Content = "Tallenna";
btnSave.Click += btnSave_Click;
spAlarivi.Children.Add(btnSave);
lblInfo = new Label();
lblInfo.Style = Resources["Isompi"] as Style;
spAlarivi.Children.Add(lblInfo);
}
grdRivit.Children.Add(spAlarivi);*/
private
void
txbFocus
(
object
sender
,
RoutedEventArgs
e
)
{
TextBox
tb
=
sender
as
TextBox
;
if
(
tb
!=
null
)
{
tb
.
SelectAll
();
}
}
public
void
btnSave_Click
(
object
sender
,
RoutedEventArgs
e
)
{
List
<
Rivi
>
rivit
=
new
List
<
Rivi
>();
foreach
(
List
<
TextBox
>
rivi
in
numerot
)
{
short
[]
tmp
=
new
short
[
7
];
// tarvitaan myös indeksi, joten foreach ei käy
for
(
int
i
=
0
;
i
<
7
;
i
++)
{
if
(
short
.
TryParse
(
rivi
[
i
].
Text
,
out
short
s
))
{
// tehdään vielä validaatio ennen tallennusta
if
(
s
<
1
||
s
>
40
)
{
lblInfo
.
Content
=
"Käytä vain numeroita 1-40"
;
return
;
}
tmp
[
i
]
=
s
;
}
else
{
lblInfo
.
Content
=
"Käytä vain numeroita 1-40"
;
return
;
}
}
rivit
.
Add
(
new
Rivi
(
tmp
));
}
try
{
ViewModel
.
Riviapuri
.
Tallenna
(
rivit
);
this
.
Close
();
}
catch
(
Exception
ex
)
{
lblInfo
.
Content
=
$"Virhe tallennettaessa rivejä:
{
ex
.
Message
}
"
;
}
}
public
void
txbChanged
(
object
sender
,
TextChangedEventArgs
e
)
...
...
Lottokone/MainWindow.xaml
View file @
da72682e
...
...
@@ -7,14 +7,15 @@
mc:Ignorable="d"
Title="Lottokone" Height="450" Width="950" Background="Black">
<StackPanel Orientation="Horizontal">
<StackPanel Margin="
0
,10,
0
,0">
<StackPanel Margin="
5
,10,
5
,0">
<Button x:Name="btnNext" Margin="0,5,0,0" Content="Seuraava viikko" Click="btnNext_Click"/>
<Button x:Name="btnStart" Margin="0,5,0,0" Content="Käynnistä" Click="btnStart_Click"/>
<Button x:Name="btnStop" Margin="0,5,0,0" Content="Pysäytä" Click="btnStop_Click"/>
<Button x:Name="btnSettings" Margin="0,50,0,0" Content="Asetukset" Click="btnSettings_Click" />
<Button x:Name="btnRikkaimmat" Margin="0,10,0,0" Content="Rikkaimmat" Click="BtnRikkaimmat_Click" />
</StackPanel>
<StackPanel Height="400">
<StackPanel x:Name="spLotto" Width="250" Background="White" Opacity="0.
6
" VerticalAlignment="Top">
<StackPanel x:Name="spLotto" Width="250" Background="White" Opacity="0.
7
" VerticalAlignment="Top">
<Label Style="{StaticResource Isompi}" Content="{Binding Vuosi}" ContentStringFormat="Vuosi: {0}"/>
<Label Style="{StaticResource Isompi}" Content="{Binding Viikko}" ContentStringFormat="Viikko: {0}"/>
<Label Style="{StaticResource Isompi}" Content="{Binding Rivimaara}" ContentStringFormat="Rivejä: {0:N0}"/>
...
...
@@ -29,10 +30,11 @@
<ListView Height="350" Width="300" x:Name="lstStatus" ItemsSource="{Binding Value, UpdateSourceTrigger=PropertyChanged}" Opacity="0.7"/>
</StackPanel>
<StackPanel>
<StackPanel x:Name="spPlayer" Width="300" Margin="5,0,0,0" Background="White" Opacity="0.
8
">
<StackPanel x:Name="spPlayer" Width="300" Margin="5,0,0,0" Background="White" Opacity="0.
7
">
<Label Style="{StaticResource Isompi}" Content="{Binding Nimi}" ContentStringFormat="Nimi: {0}" />
<Label Style="{StaticResource Isompi}" Content="{Binding Saldo}" ContentStringFormat="Tilin saldo: {0:C0}" />
<Label Style="{StaticResource Isompi}" Content="{Binding Riveja}" ContentStringFormat="Rivejä: {0:N0}" />
<Label Style="{StaticResource Isompi}" Content="{Binding Saldo}" ContentStringFormat="Tilin saldo: {0:C0}" />
<Label Style="{StaticResource Isompi}" Content="{Binding Voitot}" ContentStringFormat="Voitot yhteensä: {0:C0}" />
</StackPanel>
<StackPanel Width="300">
<Label Style="{StaticResource Isompi}" Foreground="White" Content="Omat voitot:" Margin="0,100,0,0"/>
...
...
Lottokone/MainWindow.xaml.cs
View file @
da72682e
...
...
@@ -2,6 +2,7 @@
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Collections.Specialized
;
using
System.Diagnostics
;
using
System.Globalization
;
using
System.Linq
;
using
System.Text
;
...
...
@@ -31,7 +32,7 @@ namespace Lottokone
// Meidän pelaaja
private
Pelaaja
pelaaja
;
// Meidän voit
o
t, ja lukko-objekti jotta voidaan käyttää sitä threadeista
// Meidän voitt
ohostoria
, ja lukko-objekti jotta voidaan käyttää sitä threadeista
private
ObservableCollection
<
string
>
voitot
;
private
object
voittolukko
;
...
...
@@ -39,6 +40,17 @@ namespace Lottokone
private
Thread
runner
;
private
bool
kaynnissa
=
false
;
// tähän tallennetaan oletuksena imgLotto-kuvassa oleva kuva.
// Se voidaan sitten helposti palauttaa, kun ollaan hetki näytetty jotain muuta kuvaa
private
ImageSource
oletuskuva
;
private
BitmapImage
img5oikein
;
private
BitmapImage
img6oikein
;
private
BitmapImage
img7oikein
;
private
short
kuvanro
;
// Tällä katsotaan, joko kuva pitäisi vaihtaa takaisin oletukseen.
private
Stopwatch
kuvakello
;
// Tässä kyseinen pelilooppi
// Tämä olisi ollut ehkä järkevä toteuttaa muualla kuin täällä MainWindow.xaml.cs:ssä,
// mutta tällä nyt mennään....
...
...
@@ -57,7 +69,6 @@ namespace Lottokone
case
3
:
if
(
r
.
Numerot
.
Contains
(
kone
.
Voittorivi
.
Lisanumero
))
{
s
=
$"Kierros
{
kone
.
Kierros
}
: 3+1 oikein (
{
kone
.
Voitot
[
5
]:
C0
}
)"
;
}
break
;
...
...
@@ -66,25 +77,67 @@ namespace Lottokone
break
;
case
5
:
s
=
$"Kierros
{
kone
.
Kierros
}
: 5 oikein (
{
kone
.
Voitot
[
3
]:
C0
}
)"
;
// 5 oikein ja suuremmat luokat, niin vaihdetaan ikkunan taustaa hetken ajaksi hienommaksi.
if
(
kuvanro
<=
1
)
{
this
.
Dispatcher
.
Invoke
(()
=>
{
this
.
Background
=
new
SolidColorBrush
(
Color
.
FromArgb
(
255
,
(
byte
)
255
,
(
byte
)
191
,
(
byte
)
192
));
imgLotto
.
Source
=
img5oikein
;
});
kuvanro
=
1
;
if
(
kuvakello
.
IsRunning
)
kuvakello
.
Reset
();
kuvakello
.
Start
();
}
break
;
case
6
:
this
.
Dispatcher
.
Invoke
(()
=>
if
(
kuvanro
<=
2
)
{
this
.
Background
=
Brushes
.
Pink
;
imgLotto
.
Source
=
new
BitmapImage
(
new
Uri
(
@"Resources/lotto1.png"
,
UriKind
.
Relative
));
});
this
.
Dispatcher
.
Invoke
(()
=>
{
this
.
Background
=
new
SolidColorBrush
(
Color
.
FromArgb
(
255
,
(
byte
)
35
,
(
byte
)
40
,
(
byte
)
4
));
imgLotto
.
Source
=
img6oikein
;
});
kuvanro
=
2
;
if
(
kuvakello
.
IsRunning
)
kuvakello
.
Reset
();
kuvakello
.
Start
();
}
s
=
$"Kierros
{
kone
.
Kierros
}
: "
;
//
taas
lisänumeron tarkistus
// lisänumeron tarkistus
if
(
r
.
Numerot
.
Contains
(
kone
.
Voittorivi
.
Lisanumero
))
s
+=
$"6+1 oikein!!!
{
kone
.
Voitot
[
1
]:
C0
}
- Melkein jo kannattaa?!"
;
else
s
+=
$"6 oikein! (
{
kone
.
Voitot
[
2
]:
C0
}
)"
;
break
;
case
7
:
// Päävoitto jos osuu, niin pelin voinee pysäyttää.
// päävoitto, pysäytetään peli
kaynnissa
=
false
;
this
.
Dispatcher
.
Invoke
(()
=>
{
this
.
Background
=
new
SolidColorBrush
(
Color
.
FromArgb
(
255
,
(
byte
)
251
,
(
byte
)
212
,
(
byte
)
1
));
imgLotto
.
Source
=
img7oikein
;
});
kuvanro
=
3
;
if
(
kuvakello
.
IsRunning
)
kuvakello
.
Reset
();
kuvakello
.
Start
();
s
=
$"Kierros
{
kone
.
Kierros
}
: PÄÄVOITTO!!!! (
{
kone
.
Voitot
[
0
]:
C0
}
) JUMANTSUIKKA! Kannattaa ehkä lotota oikeastikin?! "
+
"Ellet käyttänyt kaikkea onneasi tähän...."
;
kaynnissa
=
false
;
// asetetaan scoreboardille pisteet.
// Meidän saldossa on jo päävoitto, mutta me halutaan tietää kuinka paljon oltiin miinuksella ennen sitä.
// Vähennetään siis päävoitto pisteistä jotka tallennetaan scoreboardille.
try
{
ViewModel
.
Scoreboard
.
AsetaPisteet
(
pelaaja
.
Nimi
,
pelaaja
.
Saldo
-
kone
.
Voitot
[
0
]);
}
catch
(
Exception
ex
)
{
s
=
$"Pisteiden talletus tietokantaan ei onnistunut: $
{
ex
.
Message
}
"
;
}
break
;
default
:
break
;
...
...
@@ -97,6 +150,21 @@ namespace Lottokone
}
}
}
// jos kuvakello on käynnissä, niin meillä on eri tausta ikkunassa kun oletus
if
(
kuvakello
.
IsRunning
)
{
// jos viimeisestä isosta voitosta on yli 5 sek, niin vaihdetaan kuva takaisin vanhaan.
if
(
kuvakello
.
ElapsedMilliseconds
>
5
_000
)
{
kuvakello
.
Reset
();
this
.
Dispatcher
.
Invoke
(()
=>
{
this
.
Background
=
Brushes
.
Black
;
imgLotto
.
Source
=
oletuskuva
;
});
}
}
}
while
(
kaynnissa
);
}
...
...
@@ -117,15 +185,6 @@ namespace Lottokone
kone
=
new
Lotto
();
spLotto
.
DataContext
=
kone
;
// luodaan meidän pelaaja, ja lisätään se lottoon.
pelaaja
=
new
Pelaaja
(
Properties
.
Settings
.
Default
.
Nimi
);
pelaaja
.
Riveja
=
Properties
.
Settings
.
Default
.
Arparivit
+
Properties
.
Settings
.
Default
.
Vakiorivit
;
pelaaja
.
RivitVoimassa
=
Properties
.
Settings
.
Default
.
ArparivitVoimassa
;
kone
.
Pelaajat
.
Add
(
pelaaja
);
// sidotaan meidät pelaajan tietoikkunaan
spPlayer
.
DataContext
=
pelaaja
;
// status-ikkunaan skrollaava historia eventeistä
// EnableCollectionSynchronization() mahdollistaa listan käyttämisen muista
// threadeista, ja UI-thread saa siitä silti CollectionUpdated eventin.
...
...
@@ -138,18 +197,51 @@ namespace Lottokone
BindingOperations
.
EnableCollectionSynchronization
(
voitot
,
voittolukko
);
lstVoitot
.
ItemsSource
=
voitot
;
// luodaan meidän pelaaja
pelaaja
=
new
Pelaaja
(
Properties
.
Settings
.
Default
.
Nimi
);
pelaaja
.
Riveja
=
Properties
.
Settings
.
Default
.
Arparivit
+
Properties
.
Settings
.
Default
.
Vakiorivit
;
pelaaja
.
RivitVoimassa
=
Properties
.
Settings
.
Default
.
ArparivitVoimassa
;
// ladataan vakiorivit tietokannasta
if
(
Properties
.
Settings
.
Default
.
Vakiorivit
>
0
)
{
try
{
pelaaja
.
Rivit
=
ViewModel
.
Riviapuri
.
Lataa
(
Properties
.
Settings
.
Default
.
Vakiorivit
);
}
catch
(
Exception
ex
)
{
kone
.
Status
=
$"Virhe ladattaessa vakiorivejä:
{
ex
.
Message
}
"
;
}
}
// lisätään pelaaja lottoon.
kone
.
Pelaajat
.
Add
(
pelaaja
);
// sidotaan meidät pelaajan tietoikkunaan
spPlayer
.
DataContext
=
pelaaja
;
// loppuun vielä muut tarvittavien muuttujien alustukset.
btnStop
.
IsEnabled
=
false
;
oletuskuva
=
imgLotto
.
Source
;
kuvanro
=
0
;
kuvakello
=
new
Stopwatch
();
img5oikein
=
new
BitmapImage
(
new
Uri
(
@"Resources/lotto1.png"
,
UriKind
.
Relative
));
img6oikein
=
new
BitmapImage
(
new
Uri
(
@"Resources/lotto2.png"
,
UriKind
.
Relative
));
img7oikein
=
new
BitmapImage
(
new
Uri
(
@"Resources/lotto3.png"
,
UriKind
.
Relative
));
}
private
void
btnNext_Click
(
object
sender
,
RoutedEventArgs
e
)
{
btnStart
.
IsEnabled
=
false
;
btnNext
.
IsEnabled
=
false
;
btnRikkaimmat
.
IsEnabled
=
false
;
// ajetaan looppi kerran. kun kaynnissa = false, niin se palautuu heti.
GameLoop
();
btnNext
.
IsEnabled
=
true
;
btnRikkaimmat
.
IsEnabled
=
true
;
btnStart
.
IsEnabled
=
true
;
}
...
...
@@ -159,6 +251,7 @@ namespace Lottokone
btnStart
.
IsEnabled
=
false
;
btnNext
.
IsEnabled
=
false
;
btnSettings
.
IsEnabled
=
false
;
btnRikkaimmat
.
IsEnabled
=
false
;
kaynnissa
=
true
;
runner
=
new
Thread
(
GameLoop
);
...
...
@@ -176,17 +269,18 @@ namespace Lottokone
btnStart
.
IsEnabled
=
true
;
btnStop
.
IsEnabled
=
false
;
btnSettings
.
IsEnabled
=
true
;
btnRikkaimmat
.
IsEnabled
=
true
;
}
private
void
btnSettings_Click
(
object
sender
,
RoutedEventArgs
e
)
{
var
a
=
new
Asetukset
();
a
.
ShowDialog
();
// kun asetuksista palataan, voidaan ottaa uudet asetukset käyttöön.
// kun asetuksista palataan, voidaan ottaa uudet asetukset käyttöön.
// ensin tarkistetaan, onko pelaajamäärä muuttunut
int
curr
=
kone
.
Pelaajat
.
Count
();
// + 1 koska pelaajissa on myös meidän pelaajaolio
int
uusi
=
Properties
.
Settings
.
Default
.
Pelaajia
+
1
;
...
...
@@ -201,7 +295,9 @@ namespace Lottokone
kone
.
Status
=
$"Poistettu
{
curr
-
uusi
}
pelaajaa."
;
}
Pelaaja
tmp
=
kone
.
Pelaajat
.
Last
();
// otetaan joku satunnainen pelaaja, ja verrataan sen tietoja uusiin.
// Näin saadaan selville, pitääkö pelaajien tietoja muuttaa.
Pelaaja
tmp
=
kone
.
Pelaajat
.
ElementAt
(
kone
.
Pelaajat
.
Count
()
/
2
);
if
(
tmp
.
RivitVoimassa
!=
Properties
.
Settings
.
Default
.
Voimassa
)
{
kone
.
Status
=
$"Rivit voimassa
{
tmp
.
RivitVoimassa
}
->
{
Properties
.
Settings
.
Default
.
Voimassa
}
viikkoa"
;
...
...
@@ -210,10 +306,10 @@ namespace Lottokone
p
.
RivitVoimassa
=
Properties
.
Settings
.
Default
.
Voimassa
;
}
}
if
(
tmp
.
Riveja
!=
Properties
.
Settings
.
Default
.
Riveja
)
if
(
tmp
.
Riveja
!=
Properties
.
Settings
.
Default
.
Riveja
)
{
kone
.
Status
=
$"Simuloitujen pelaajien riv
ejä
{
tmp
.
Riveja
}
->
{
Properties
.
Settings
.
Default
.
Riveja
}
"
;
foreach
(
Pelaaja
p
in
kone
.
Pelaajat
)
kone
.
Status
=
$"Simuloitujen pelaajien riv
it
{
tmp
.
Riveja
}
->
{
Properties
.
Settings
.
Default
.
Riveja
}
"
;
foreach
(
Pelaaja
p
in
kone
.
Pelaajat
)
{
p
.
Riveja
=
Properties
.
Settings
.
Default
.
Riveja
;
}
...
...
@@ -222,24 +318,35 @@ namespace Lottokone
// saatettiin poistaa pelaajia, niin varmistetaan, että meidän pelaaja on
// yhä lotossa mukana...
if
(!
kone
.
Pelaajat
.
Contains
(
pelaaja
))
{
kone
.
Status
=
"Lisätty oma pelaaja takaisin listoille"
;
kone
.
Pelaajat
.
Add
(
pelaaja
);
}
if
(
pelaaja
.
Nimi
!=
Properties
.
Settings
.
Default
.
Nimi
)
pelaaja
.
Nimi
=
Properties
.
Settings
.
Default
.
Nimi
;
if
(
pelaaja
.
Riveja
!=
Properties
.
Settings
.
Default
.
Arparivit
+
Properties
.
Settings
.
Default
.
Vakiorivit
)
{
kone
.
Status
=
$"Omat rivit
{
pelaaja
.
Riveja
}
->
{
Properties
.
Settings
.
Default
.
Arparivit
+
Properties
.
Settings
.
Default
.
Vakiorivit
}
"
;
pelaaja
.
Riveja
=
Properties
.
Settings
.
Default
.
Arparivit
+
Properties
.
Settings
.
Default
.
Vakiorivit
;
}
if
(
pelaaja
.
RivitVoimassa
!=
Properties
.
Settings
.
Default
.
ArparivitVoimassa
)
pelaaja
.
RivitVoimassa
=
Properties
.
Settings
.
Default
.
ArparivitVoimassa
;
// ladataan vakiorivit uudelleen
if
(
Properties
.
Settings
.
Default
.
Vakiorivit
>
0
)
{
try
{
// voidaan tyhjentää rivit, mukaan lukien arparivit, kun ne luodaan uusiksi kuitenkin
pelaaja
.
Rivit
=
ViewModel
.
Riviapuri
.
Lataa
(
Properties
.
Settings
.
Default
.
Vakiorivit
);
}
catch
(
Exception
ex
)
{
kone
.
Status
=
$"Virhe ladattaessa vakiorivejä:
{
ex
.
Message
}
"
;
}
}
}
private
void
BtnRikkaimmat_Click
(
object
sender
,
RoutedEventArgs
e
)
{
new
Rikkaimmat
(
kone
.
Pelaajat
).
ShowDialog
();
}
}
}
Lottokone/Model/Lotto.cs
View file @
da72682e