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
fd6dcee5
Commit
fd6dcee5
authored
Apr 10, 2019
by
M1888
Browse files
10.4.
parent
a5dea225
Changes
6
Hide whitespace changes
Inline
Side-by-side
Lottokone/MainWindow.xaml
View file @
fd6dcee5
...
...
@@ -7,6 +7,24 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel Orientation="Horizontal">
<Button x:Name="btnNext" Content="Seuraava viikko..." Click="btnNext_Click"/>
<StackPanel x:Name="spLotto" Width="250">
<Label Content="Vuosi:"/>
<Label Content="{Binding Vuosi}" />
<Label Content="Viikko:"/>
<Label Content="{Binding Viikko}" />
<Label Content="Pelaajia:"/>
<Label Content="{Binding Pelaajat.Length}"/>
<Label Content="Potti:"/>
<Label Content="{Binding Potti}"/>
<Label Content="Voittorivi:"/>
<Label Content="{Binding Voittorivi}"/>
</StackPanel>
<StackPanel>
<Label Content="Status:"/>
<ListView Height="150" Width="300" x:Name="lstStatus" ItemsSource="{Binding Value, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>
Lottokone/MainWindow.xaml.cs
View file @
fd6dcee5
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Specialized
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
...
...
@@ -12,6 +13,7 @@ using System.Windows.Media;
using
System.Windows.Media.Imaging
;
using
System.Windows.Navigation
;
using
System.Windows.Shapes
;
using
Lottokone.Model
;
namespace
Lottokone
{
...
...
@@ -20,9 +22,30 @@ namespace Lottokone
/// </summary>
public
partial
class
MainWindow
:
Window
{
private
Lotto
kone
;
public
MainWindow
()
{
InitializeComponent
();
kone
=
new
Lotto
();
spLotto
.
DataContext
=
kone
;
lstStatus
.
ItemsSource
=
kone
.
StatusHistory
;
((
INotifyCollectionChanged
)
lstStatus
.
Items
).
CollectionChanged
+=
lstStatus_CollectionChanged
;
}
private
void
btnNext_Click
(
object
sender
,
RoutedEventArgs
e
)
{
kone
.
Tick
();
}
private
void
lstStatus_CollectionChanged
(
object
sender
,
NotifyCollectionChangedEventArgs
e
)
{
if
(
e
.
Action
==
NotifyCollectionChangedAction
.
Add
)
{
// scroll the new item into view
lstStatus
.
ScrollIntoView
(
e
.
NewItems
[
0
]);
}
}
}
}
Lottokone/Model/Lotto.cs
View file @
fd6dcee5
using
System
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Runtime.CompilerServices
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Lottokone.Model
{
class
Lotto
public
class
Lotto
:
INotifyPropertyChanged
{
private
bool
kaynnissa
=
false
;
private
short
viikko
;
public
short
Viikko
{
...
...
@@ -15,6 +20,16 @@ namespace Lottokone.Model
{
return
viikko
;
}
set
{
viikko
=
value
;
if
(
viikko
>
52
)
{
viikko
=
1
;
Vuosi
++;
}
RaisePropertyChanged
();
}
}
private
short
vuosi
;
...
...
@@ -24,6 +39,11 @@ namespace Lottokone.Model
{
return
vuosi
;
}
set
{
vuosi
=
value
;
RaisePropertyChanged
();
}
}
public
List
<
Pelaaja
>
Pelaajat
{
get
;
set
;
}
...
...
@@ -35,8 +55,15 @@ namespace Lottokone.Model
{
return
potti
;
}
set
{
potti
=
value
;
RaisePropertyChanged
();
}
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
private
Voittorivi
voittorivi
;
public
Voittorivi
Voittorivi
{
...
...
@@ -44,6 +71,55 @@ namespace Lottokone.Model
{
return
voittorivi
;
}
set
{
voittorivi
=
value
;
RaisePropertyChanged
();
}
}
public
ObservableCollection
<
string
>
StatusHistory
;
public
string
Status
{
get
{
return
StatusHistory
.
Last
();
}
set
{
StatusHistory
.
Add
(
value
);
RaisePropertyChanged
();
}
}
// Konstruktori lottokoneen pääluokalle
public
Lotto
()
{
viikko
=
0
;
vuosi
=
1
;
Pelaajat
=
new
List
<
Pelaaja
>();
StatusHistory
=
new
ObservableCollection
<
string
>();
Status
=
"Alustetaan pelaajia..."
;
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
Pelaaja
p
=
new
Pelaaja
();
for
(
int
j
=
0
;
j
<
5
;
j
++)
{
Lottorivi
l
=
new
Lottorivi
();
l
.
ArvoRivi
();
p
.
Rivit
.
Add
(
l
);
Potti
++;
}
Pelaajat
.
Add
(
p
);
}
}
public
void
LisaaPelaajia
(
int
maara
)
{
for
(
int
i
=
0
;
i
<
maara
;
i
++)
{
Pelaajat
.
Add
(
new
Pelaaja
());
}
}
public
void
Start
()
...
...
@@ -58,7 +134,31 @@ namespace Lottokone.Model
public
void
Tick
()
{
// TODO
Status
=
"Seuraava viikko..."
;
Viikko
++;
Voittorivi
=
new
Voittorivi
();
Voittorivi
.
ArvoRivi
();
TarkistaVoitot
();
}
private
void
TarkistaVoitot
()
{
foreach
(
Pelaaja
p
in
Pelaajat
)
{
foreach
(
Rivi
r
in
p
.
Rivit
)
{
if
(
Voittorivi
.
Oikein
(
r
)
>=
5
)
{
Status
=
$">=5 oikein!
{
Voittorivi
.
ToString
()}
ja
{
r
.
ToString
()}
"
;
}
}
}
}
protected
void
RaisePropertyChanged
([
CallerMemberName
]
string
propertyName
=
null
)
{
if
(
PropertyChanged
!=
null
)
PropertyChanged
(
this
,
new
PropertyChangedEventArgs
(
propertyName
));
}
}
}
Lottokone/Model/Pelaaja.cs
View file @
fd6dcee5
...
...
@@ -8,18 +8,36 @@ namespace Lottokone.Model
{
public
class
Pelaaja
{
public
string
Nimi
{
get
;
set
}
public
string
Nimi
{
get
;
set
;
}
public
long
Saldo
{
get
;
set
;
}
public
List
<
Lottorivi
>
Rivit
{
get
;
set
;
}
public
short
Riveja
{
get
;
set
;
}
public
Pelaaja
()
{
Saldo
=
0
;
Rivit
=
new
List
<
Lottorivi
>();
Riveja
=
0
;
}
public
Pelaaja
(
string
nimi
)
:
this
()
{
Nimi
=
nimi
;
}
public
Pelaaja
(
short
riveja
)
:
this
()
{
Riveja
=
riveja
;
}
public
void
Tick
()
{
foreach
(
Rivi
r
in
Rivit
)
{
}
}
}
}
Lottokone/Model/Rivi.cs
View file @
fd6dcee5
...
...
@@ -8,27 +8,86 @@ namespace Lottokone.Model
{
public
class
Rivi
{
private
Random
rnd
;
public
short
[]
Numerot
{
get
;
set
;
}
public
Rivi
()
{
rnd
=
new
Random
();
Numerot
=
new
short
[
7
];
}
public
Rivi
(
short
[]
numerot
)
{
if
(
numerot
.
Length
!=
7
)
throw
new
ArgumentException
(
"Rivin pituus pitää olla 7 numeroa"
);
Numerot
=
numerot
;
}
public
Rivi
(
Rivi
r
)
{
Numerot
=
r
.
Numerot
;
}
public
void
ArvoRivi
()
{
/*for(int i = 0; i < 7; i++)
{
Numerot[i] = (short)rnd.Next(1, 41);
}*/
Numerot
=
Array
.
ConvertAll
(
// otetaan numerot 1-40, järjestellään satunnaisesti, valitaan 7 ekaa, ja tehdään niistä taulukko
Enumerable
.
Range
(
1
,
40
).
OrderBy
(
x
=>
rnd
.
Next
()).
Take
(
7
).
ToArray
(),
// Enumerable.Range tuottaa inttejä, jotka pitää sitten muuntaa shorteiksi
Convert
.
ToInt16
);
// järjestellään rivi arpomisen jälkeen heti
// suuruusjärjestykseen, niin vertailu on myöhemmin helpompaa
Array
.
Sort
(
Numerot
);
}
public
short
Oikein
(
object
obj
)
{
Rivi
r
=
obj
as
Rivi
;
short
osumia
=
0
;
if
(
r
==
null
)
return
0
;
for
(
int
i
=
0
;
i
<
Numerot
.
Length
;
i
++)
if
(
Numerot
[
i
]
==
r
.
Numerot
[
i
])
osumia
++;
return
osumia
;
}
public
override
bool
Equals
(
object
obj
)
{
Rivi
r
=
obj
as
Rivi
;
if
(
r
==
null
)
return
false
;
if
(
r
.
Numerot
.
Equals
(
this
.
Numerot
))
return
true
;
for
(
int
i
=
0
;
i
<
Numerot
.
Length
;
i
++)
if
(
Numerot
[
i
]
!=
r
.
Numerot
[
i
])
return
false
;
return
fals
e
;
return
tru
e
;
}
public
override
int
GetHashCode
()
{
return
521069651
+
EqualityComparer
<
short
[
]>
.
Default
.
GetHashCode
(
Numerot
);
}
public
override
string
ToString
()
{
string
s
=
"["
;
foreach
(
short
n
in
Numerot
)
s
+=
$"
{
n
}
"
;
s
+=
"]"
;
return
s
;
}
}
}
doc/spec.md
View file @
fd6dcee5
...
...
@@ -49,8 +49,6 @@ Peli tullaan toteuttamaan C# ja XAML -kielillä WPF:ää käyttäen. Kohdealusta
Tietojen säilyttämiseen ohjelma tulee käyttämään SQLiteä, ja C#:n
[
System.Data.SQLite
](
https://www.nuget.org/packages/System.Data.SQLite
)
-pakettia.
Harkintalistalla on myös toteuttaa käyttöliittymä
[
AdonisUI:n avulla
](
https://github.com/benruehl/adonis-ui
)
, mikäli aikaa tähän tutustumiseen jää.
## Käyttäjäroolit
Peli on paikallinen yksinpeli, ja käyttäjärooleja on siten vain yksi: Pelaaja.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment