diff --git a/Lottokone/MainWindow.xaml b/Lottokone/MainWindow.xaml
index fb8a877d7f6fc7ea796f0bf493e410a8963ec8ab..6b8a864244d15949d21cd2966d4591e794784822 100644
--- a/Lottokone/MainWindow.xaml
+++ b/Lottokone/MainWindow.xaml
@@ -7,6 +7,24 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Lottokone/MainWindow.xaml.cs b/Lottokone/MainWindow.xaml.cs
index d6581bf073e716e085941c392a235e28a525f4a4..cfee6c635a966b0633c994f17e42ac87cb65ed58 100644
--- a/Lottokone/MainWindow.xaml.cs
+++ b/Lottokone/MainWindow.xaml.cs
@@ -1,5 +1,6 @@
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
///
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]);
+ }
+ }
+
}
}
diff --git a/Lottokone/Model/Lotto.cs b/Lottokone/Model/Lotto.cs
index 91da427c8ce47d758ddfa317b1276cc28f69b482..9ce0d8b1af8316474692f3ba396add3544db69b8 100644
--- a/Lottokone/Model/Lotto.cs
+++ b/Lottokone/Model/Lotto.cs
@@ -1,13 +1,18 @@
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 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 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();
+ StatusHistory = new ObservableCollection();
+ 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));
}
}
}
diff --git a/Lottokone/Model/Pelaaja.cs b/Lottokone/Model/Pelaaja.cs
index 760174c8ab15667f651f1d87035756b092ebe968..734ec59f542037479ae90f93aeb0c0cd4c1cc4c5 100644
--- a/Lottokone/Model/Pelaaja.cs
+++ b/Lottokone/Model/Pelaaja.cs
@@ -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 Rivit { get; set; }
+ public short Riveja { get; set; }
+
public Pelaaja()
{
Saldo = 0;
+ Rivit = new List();
+ Riveja = 0;
}
public Pelaaja(string nimi) : this()
{
Nimi = nimi;
}
+ public Pelaaja(short riveja) : this()
+ {
+ Riveja = riveja;
+ }
+
+ public void Tick()
+ {
+ foreach(Rivi r in Rivit)
+ {
+
+ }
+ }
+
+
}
}
diff --git a/Lottokone/Model/Rivi.cs b/Lottokone/Model/Rivi.cs
index d347667775b9eecd9b640a4748cd02e6164e72f9..bc76866ec415bb80d4b0c82fab4486d0b6407d2f 100644
--- a/Lottokone/Model/Rivi.cs
+++ b/Lottokone/Model/Rivi.cs
@@ -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 false;
+ return true;
}
public override int GetHashCode()
{
return 521069651 + EqualityComparer.Default.GetHashCode(Numerot);
}
+
+ public override string ToString()
+ {
+ string s = "[";
+
+ foreach (short n in Numerot)
+ s += $" {n} ";
+
+ s += "]";
+ return s;
+ }
}
}
diff --git a/doc/spec.md b/doc/spec.md
index 29b7749a9265bca21b02a15363b56f85cf9aa9ee..14f5eca99407113dfb35910afffb6f2c5f61ee48 100644
--- a/doc/spec.md
+++ b/doc/spec.md
@@ -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.