SpielStrategien mit Interface und Enum

This commit is contained in:
Daniel Herrmann
2014-06-05 11:22:06 +02:00
parent 0021f75b4d
commit e53f2657aa
5 changed files with 72 additions and 15 deletions

View File

@@ -57,10 +57,13 @@
<Reference Include="System.Core" /> <Reference Include="System.Core" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="src\GameStrategy.cs" />
<Compile Include="src\IGame.cs" />
<Compile Include="src\Receiver.cs" /> <Compile Include="src\Receiver.cs" />
<Compile Include="src\Sender.cs" /> <Compile Include="src\Sender.cs" />
<Compile Include="src\Dragon.cs" /> <Compile Include="src\Dragon.cs" />
<Compile Include="src\Map.cs" /> <Compile Include="src\Map.cs" />
<Compile Include="src\Skirmish.cs" />
<Compile Include="src\Tile.cs" /> <Compile Include="src\Tile.cs" />
<Compile Include="src\Entity.cs" /> <Compile Include="src\Entity.cs" />
<Compile Include="src\Player.cs" /> <Compile Include="src\Player.cs" />

View File

@@ -4,7 +4,7 @@ namespace WorldOfPeacecraft
{ {
public enum Decision public enum Decision
{ {
DRAGON, STAGHUNT, SKIRMISH FIGHT, REST, STAG, BUNNY, SWORD, ALCHEMY, MAGIC
} }
} }

View File

@@ -3,40 +3,40 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace inf3.src namespace WorldOfPeacecraft
{ {
class GameStrategy class GameStrategy
{ {
// 0 = defect, 1 = cooperate
int opponentLastMove;
bool opDefected = false;
int counter = 0; int counter = 0;
public GameStrategy(int opLM) public GameStrategy()
{ {
opponentLastMove = opLM;
} }
public int nextMove() public bool getFirstMove()
{ {
if (opponentLastMove != 0) return true;
}
public bool nextMove(bool opCooperated)
{ {
return opponentLastMove; if (opCooperated && counter==0)
{
return true;
} }
else else
{ {
opDefected = true;
counter++; counter++;
if (counter < 10) if (counter < 10)
{ {
return 0; return false;
} }
else else
{ {
counter = 0; counter = 0;
opDefected = false; return false;
return 0;
} }
} }

13
src/IGame.cs Normal file
View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WorldOfPeacecraft
{
public interface IGame
{
Decision getFirstMove();
Decision getNextMove(Decision opLM);
}
}

41
src/Skirmish.cs Normal file
View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WorldOfPeacecraft
{
class Skirmish
{
Random random = new Random();
public Skirmish()
{
}
public Decision getFirstMove()
{
return getNextMove();
}
public Decision getNextMove()
{
int randomNumber = random.Next(0, 2);
Decision bla;
switch (randomNumber)
{
case 0:
bla = Decision.SWORD;
break;
case 1:
bla = Decision.MAGIC;
break;
case 2:
default:
bla = Decision.ALCHEMY;
break;
}
return bla;
}
}
}