Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
L
lottokone
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
M1888
lottokone
Commits
fd6dcee5
Commit
fd6dcee5
authored
Apr 10, 2019
by
M1888
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
10.4.
parent
a5dea225
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
225 additions
and
9 deletions
+225
-9
Lottokone/MainWindow.xaml
Lottokone/MainWindow.xaml
+19
-1
Lottokone/MainWindow.xaml.cs
Lottokone/MainWindow.xaml.cs
+23
-0
Lottokone/Model/Lotto.cs
Lottokone/Model/Lotto.cs
+102
-2
Lottokone/Model/Pelaaja.cs
Lottokone/Model/Pelaaja.cs
+19
-1
Lottokone/Model/Rivi.cs
Lottokone/Model/Rivi.cs
+62
-3
doc/spec.md
doc/spec.md
+0
-2
No files found.
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