Deep Shallow copy moe nog gebeuren

This commit is contained in:
Beppe
2019-08-12 13:28:38 +02:00
parent e32405674a
commit fb078ec1d8
9 changed files with 137 additions and 101 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

View File

@@ -9,7 +9,7 @@ namespace Globals.classes
{
[JsonConstructor]
public Game(int Id, Ploeg home, Ploeg away, DateTime date)
public Game(int Id, PloegInMatch home, PloegInMatch away, DateTime date)
{
homeSetBool = false;
awaySetBool = false;
@@ -21,7 +21,7 @@ namespace Globals.classes
this.away.scoreChanged += awaySet;
this.date = date;
}
public Game(Ploeg home, Ploeg away, DateTime d)
public Game(PloegInMatch home, PloegInMatch away, DateTime d)
{
homeSetBool = false;
awaySetBool = false;
@@ -38,15 +38,15 @@ namespace Globals.classes
homeSetBool = false;
awaySetBool = false;
this.home = home;
this.away = away;
this.home = (PloegInMatch) home; //cast de oorspronkelijke klasse naar deze subklasse
this.away = (PloegInMatch) away;
this.home.scoreChanged += homeSet;
this.away.scoreChanged += awaySet;
this.home.setScore(scoreHome);
this.away.setScore(scoreAway);
this.date = d;
}
public Game(int id, Ploeg home, Ploeg away)
public Game(int id, PloegInMatch home, PloegInMatch away)
{
homeSetBool = false;
awaySetBool = false;
@@ -71,9 +71,9 @@ namespace Globals.classes
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("home")]
public Ploeg home { get; set; }
public PloegInMatch home { get; set; }
[JsonProperty("away")]
public Ploeg away { get; set; }
public PloegInMatch away { get; set; }
[JsonProperty("Date")]
public DateTime date { get; set; } //y m d

View File

@@ -6,77 +6,28 @@ namespace Globals.classes
{
public class Ploeg : IPloeg
{
[JsonConstructor]
public Ploeg(int Id, string naam, int score)
public Ploeg(int id, string naam)
{
this.Id = Id;
Id = id;
this.naam = naam;
this.score = score;
}
public Ploeg(string naam)
public Ploeg(Ploeg p)
{
this.naam = naam;
this.score = int.MinValue;
this.Id = p.Id;
this.naam = p.naam;
}
public Ploeg(string naam, int score) : this(naam)
{
this.score = score;
}
public Ploeg(string naam, int score, int Id)
{
this.score = score;
this.naam = naam;
this.Id = Id;
}
public int Id { get; set; }
public string naam { get; set; }
public int score { get; private set; }
public bool scoreSet { get; }
public event EventHandler scoreChanged;
public override bool Equals(object obj)
{
try
{
Ploeg te = (Ploeg)obj;
} catch (Exception e)
{
return false;
}
Ploeg t = (Ploeg)obj;
return this.Id == t.Id;
}
public override int GetHashCode()
{
return base.GetHashCode();
return base.Equals(obj);
}
public override string ToString()
{
string score = "";
if (this.score != int.MinValue)
{
score = ":" + this.score;
}
return this.Id + ": " + this.naam + score;
}
public void setScore(int i)
{
EventHandler h = scoreChanged;
if (null != h) h(this, EventArgs.Empty);
this.score = i;
}
public int getScore()
{
return this.score;
return this.naam;
}
}
}

View File

@@ -5,37 +5,47 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Globals.Classes
namespace Globals.classes
{
public class PloegInMatch : Ploeg
{
public int score;
public PloegInMatch(int score)
public PloegInMatch(int id, string naam) : base(id, naam)
{
}
public PloegInMatch(int id, string naam, int score) : base(id, naam)
{
setScore(score);
}
public PloegInMatch(Ploeg p) : base(p)
{
this.Id = p.Id;
this.naam = p.naam;
}
public PloegInMatch(Ploeg p, int score) : base(p)
{
this.Id = p.Id;
this.naam = p.naam;
setScore(score);
}
public int score { get; private set; }
public bool scoreSet { get; private set; }
public event EventHandler scoreChanged;
public void setScore(int score)
{
EventHandler h = scoreChanged;
if (null != h) h(this, EventArgs.Empty);
this.score = score;
this.scoreSet = true;
}
public override zegMijnNaam(string naam)
{
return "blabla " + naam;
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override string ToString()
{
return base.ToString();
}
}
}

View File

@@ -34,7 +34,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Classes\ploegInMatch.cs" />
<Compile Include="Classes\PloegInMatch.cs" />
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Classes\Bet.cs" />

View File

@@ -7,8 +7,8 @@ namespace Globals.Interfaces
public interface IGame
{
int Id { get; set; }
Ploeg home { get; set; }
Ploeg away { get; set; }
PloegInMatch home { get; set; }
PloegInMatch away { get; set; }
DateTime date { get; set; }
state getWinner();

View File

@@ -1,10 +0,0 @@
using System;
namespace Globals
{
public class MyClass
{
public MyClass()
{
}
}
}

View File

@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 16.0.29123.88
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "old", "old", "{BF8F2852-F325-4C72-AFF6-E0C40808625B}"
ProjectSection(SolutionItems) = preProject
Ploeg.cs = Ploeg.cs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Online Gokkantoor_GUI", "Online Gokkantoor\Online Gokkantoor_GUI.csproj", "{62E2ECA5-72AF-4401-9FE3-D7BD5044D7E9}"
EndProject

View File

@@ -0,0 +1,82 @@
using System;
using Globals.Interfaces;
using Newtonsoft.Json;
namespace Globals.classes
{
public class Ploeg : IPloeg
{
[JsonConstructor]
public Ploeg(int Id, string naam, int score)
{
this.Id = Id;
this.naam = naam;
this.score = score;
}
public Ploeg(string naam)
{
this.naam = naam;
this.score = int.MinValue;
}
public Ploeg(string naam, int score) : this(naam)
{
this.score = score;
}
public Ploeg(string naam, int score, int Id)
{
this.score = score;
this.naam = naam;
this.Id = Id;
}
public int Id { get; set; }
public string naam { get; set; }
public int score { get; private set; }
public bool scoreSet { get; }
public event EventHandler scoreChanged;
public override bool Equals(object obj)
{
try
{
Ploeg te = (Ploeg)obj;
} catch (Exception e)
{
return false;
}
Ploeg t = (Ploeg)obj;
return this.Id == t.Id;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override string ToString()
{
string score = "";
if (this.score != int.MinValue)
{
score = ":" + this.score;
}
return this.Id + ": " + this.naam + score;
}
public void setScore(int i)
{
EventHandler h = scoreChanged;
if (null != h) h(this, EventArgs.Empty);
this.score = i;
}
public int getScore()
{
return this.score;
}
}
}