Permalink
Browse files

Merge branch 'master' of https://github.com/snups/hopnet

Conflicts:
	src/Game/Game.csproj
  • Loading branch information...
2 parents 6aec107 + b25d4d6 commit 5de4167eb7365ce73b9d02db3fe3b2a51e03b551 @soltys committed May 15, 2012
Showing with 103 additions and 12 deletions.
  1. +5 −0 src/Game/Game.csproj
  2. +8 −4 src/Game/HopnetGame.cs
  3. +5 −5 src/Game/PlatformRow.cs
  4. +85 −3 src/Game/Platforms.cs
View
@@ -59,6 +59,9 @@
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>true</XnaCompressContent>
</PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
@@ -76,6 +79,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="HighScores.cs" />
+ <Compile Include="PlatformRow.cs" />
+ <Compile Include="Platforms.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
<Compile Include="HopnetGame.cs" />
View
@@ -24,6 +24,7 @@ public class HopnetGame : Microsoft.Xna.Framework.Game
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
+
public HopnetGame()
{
graphics = new GraphicsDeviceManager(this);
@@ -52,6 +53,10 @@ protected override void LoadContent()
logger.Trace("Load Content starts");
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
+
+
+
+
logger.Trace("Load Content ends");
// TODO: use this.Content to load your game content here
}
@@ -72,12 +77,11 @@ protected override void UnloadContent()
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
+ if (Keyboard.GetState().IsKeyDown(Keys.P)) { this.Exit(); }
- // TODO: Add your update logic here
+
+ // TODO: Add your update logic here
base.Update(gameTime);
}
View
@@ -18,7 +18,7 @@ class PlatformRow
{
public PlatformRow(bool[] platformSettings)
{
- if (platformSettings.Length != ROW_LENGTH)
+ if (platformSettings.Length != RowLength)
{
throw new ArgumentException();
}
@@ -28,24 +28,24 @@ public PlatformRow(bool[] platformSettings)
public PlatformRow()
{
- for (int i = 0; i < ROW_LENGTH; i++)
+ for (int i = 0; i < RowLength; i++)
{
this.platformSettings[i] = true;
}
}
- private const int ROW_LENGTH = 5;
- private readonly bool[] platformSettings = new bool[ROW_LENGTH];
+ public const int RowLength = 5;
+ private readonly bool[] platformSettings = new bool[RowLength];
public bool this[int i]
{
get { return platformSettings[i]; }
}
public bool IsEmpty()
{
- for (int i = 0; i < ROW_LENGTH; i++)
+ for (int i = 0; i < RowLength; i++)
{
if (platformSettings[i]) { return false; }
}
View
@@ -15,12 +15,94 @@ namespace Game
{
class Platforms
{
- private Queue<PlatformRow> QueueOfPlatformRowObjects = new Queue<PlatformRow>();
+ private LinkedList<PlatformRow> PlatformRows = new LinkedList<PlatformRow>();
+ private const int NumberOfLanes=5;
+ private int ChanceToCreatePlatform = 4;
+ private const int MaxValueOfChanceToCreatePlatform = 10;
- public void GenerateNextRow()
+ private int MinPlatformsToBeCreated = 2;
+ private int MaxPlatformsToBeCreated = 4;
+ private PlatformRow RowToBeAdded;
+ private int NumberOfRowsSinceLastEmptyRow = 5;
+ private int NumberOfGeneratedRowsSinceLastEmptyRow = 0;
+ private int MinNumberOfNonEmptyRows = 3;
+ private int MaxNumberOfNonEmptyRows = 6;
+
+
+ private void GenerateNextRow()
+ {
+ PlatformRows.AddFirst(RowToBeAdded);
+ }
+
+ private void RemoveLastRow()
+ {
+ PlatformRows.RemoveLast();
+ }
+
+ public Platforms()
+ {
+ for (int i = 0; i < NumberOfLanes; i++)
+ {
+ GenerateNextRow();
+ }
+ }
+
+ private void CalculatePlatformsForNewRow()
+ {
+ bool[] ValuesForNewRow = new bool[PlatformRow.RowLength];
+ Random randomNumberObject = new Random();
+ int randomNumber;
+ int platformsCreated = 0;
+ int platformsToBeCreated;
+ PlatformRow lastAddedRow = PlatformRows.Last();
+
+ if(NumberOfGeneratedRowsSinceLastEmptyRow>=NumberOfRowsSinceLastEmptyRow)
+ {
+ NumberOfGeneratedRowsSinceLastEmptyRow = 0;
+ randomNumber = randomNumberObject.Next(MinNumberOfNonEmptyRows, MaxNumberOfNonEmptyRows + 1);
+ NumberOfRowsSinceLastEmptyRow = randomNumber;
+ }
+ else
+ {
+ if (lastAddedRow.IsEmpty())
+ {
+ for (int i = 0; i < PlatformRow.RowLength; i++)
+ {
+ ValuesForNewRow[i] = true;
+ }
+ }
+ else
+ {
+ platformsToBeCreated = randomNumberObject.Next(MinPlatformsToBeCreated, MaxPlatformsToBeCreated + 1);
+
+ while (platformsCreated < platformsToBeCreated)
+ {
+ for (int i = 0; i < PlatformRow.RowLength; i++)
+ {
+ if (!ValuesForNewRow[i])
+ {
+ randomNumber = randomNumberObject.Next(MaxValueOfChanceToCreatePlatform);
+ if (randomNumber > ChanceToCreatePlatform)
+ {
+ ValuesForNewRow[i] = true;
+ platformsCreated++;
+ }
+ }
+ }
+ }
+ }
+ }
+ NumberOfGeneratedRowsSinceLastEmptyRow++;
+ RowToBeAdded = new PlatformRow(ValuesForNewRow);
+ }
+
+
+ public void UpdatePlatforms()
{
- QueueOfPlatformRowObjects.Enqueue(new PlatformRow());
+ RemoveLastRow();
+ CalculatePlatformsForNewRow();
+ GenerateNextRow();
}
}

0 comments on commit 5de4167

Please sign in to comment.