private static void AssertFSharpAt(GtSceneGuitar pGuitarItem, BeatTick pStartPosition, string pMessage) { { var notes = pGuitarItem.Notes.Where(p => (p.String == 6) && (p.Fret == 2) && (p.StartPosition == pStartPosition)); Assert.AreEqual(1, notes.Count(), pMessage); Assert.AreEqual(pStartPosition, notes.ElementAt(0).StartPosition, pMessage); Assert.AreEqual(new BeatTick(pStartPosition.Beat, 470), notes.ElementAt(0).EndPosition, pMessage); } { var notes = pGuitarItem.Notes.Where(p => (p.String == 5) && (p.Fret == 4) && (p.StartPosition == pStartPosition)); Assert.AreEqual(1, notes.Count(), pMessage); Assert.AreEqual(pStartPosition, notes.ElementAt(0).StartPosition, pMessage); Assert.AreEqual(new BeatTick(pStartPosition.Beat, 470), notes.ElementAt(0).EndPosition, pMessage); } { var notes = pGuitarItem.Notes.Where(p => (p.String == 4) && (p.Fret == 4) && (p.StartPosition == pStartPosition)); Assert.AreEqual(1, notes.Count(), pMessage); Assert.AreEqual(pStartPosition, notes.ElementAt(0).StartPosition, pMessage); Assert.AreEqual(new BeatTick(pStartPosition.Beat, 470), notes.ElementAt(0).EndPosition, pMessage); } }
[TestCase(13, 0, 10000)] //8 beats in first 8sec and 4 beats in the next 2sec public void ForceCurrentPositionInMiliseconds(long pBeat, long pTick, long pPosition) { var guitar = new GtSceneGuitar(new Double_GtTickDataTable_32Notes(), 30); guitar.ForceCurrentPositionInMiliseconds(pPosition); Assert.AreEqual(new BeatTick(pBeat, pTick), guitar.CurrentPosition); }
public void PropertyNotes_TwoChords() { var guitar = new GtSceneGuitar(new Double_GtTickDataTable_TwoChords()); AssertFSharpAt(guitar, (new BeatTick(1, 0)), "F# at 1:0"); AssertFSharpAt(guitar, (new BeatTick(2, 0)), "F# at 2:0"); //Triangulation }
public void VisibleNotes_Position1_120() { var guitar = new GtSceneGuitar(new Double_GtTickDataTable_32Notes(), 4); guitar.ForceCurrentPosition((new BeatTick(1, 120))); Assert.AreEqual((new BeatTick(1, 120)), guitar.CurrentPosition); var visibleNotes = guitar.GetVisibleNotes(); Assert.AreEqual(27, visibleNotes.Count); //8 B's for (int i = 0; i < 24; i++) { var note = visibleNotes[i]; switch (note.String) { case 5: Assert.AreEqual(2, note.Fret); break; case 4: Assert.AreEqual(4, note.Fret); break; case 3: Assert.AreEqual(4, note.Fret); break; default: Assert.Fail(); break; } } //1 F# for (int i = 24; i < 27; i++) { var note = visibleNotes[i]; switch (note.String) { case 6: Assert.AreEqual(2, note.Fret); break; case 5: Assert.AreEqual(4, note.Fret); break; case 4: Assert.AreEqual(4, note.Fret); break; default: Assert.Fail(); break; } } }
public void VisibleNotes_Position1_0() { var guitar = new GtSceneGuitar(new Double_GtTickDataTable_32Notes(), 4); guitar.ForceCurrentPosition((new BeatTick(1, 0))); Assert.AreEqual((new BeatTick(1, 0)), guitar.CurrentPosition); var visibleNotes = guitar.GetVisibleNotes(); Assert.AreEqual(24, visibleNotes.Count); //Eight Bs (string 5, fret 2) foreach (var note in visibleNotes) { switch (note.String) { case 5: Assert.AreEqual(2, note.Fret); break; case 4: Assert.AreEqual(4, note.Fret); break; case 3: Assert.AreEqual(4, note.Fret); break; default: Assert.Fail(); break; } } }
private void RenderStrings(GtSceneGuitar pSceneGuitar, SpriteBatch pSpriteBatch) { var x = this.X; pSpriteBatch.Draw(this.Game.StringTexture, new Rectangle(x, this.Y, 4, this.Height + this.MatchAreaHeight), Color.White); x += this.Distance; pSpriteBatch.Draw(this.Game.StringTexture, new Rectangle(x, this.Y, 3, this.Height + this.MatchAreaHeight), Color.White); x += this.Distance; pSpriteBatch.Draw(this.Game.StringTexture, new Rectangle(x, this.Y, 3, this.Height + this.MatchAreaHeight), Color.White); x += this.Distance; pSpriteBatch.Draw(this.Game.StringTexture, new Rectangle(x, this.Y, 1, this.Height + this.MatchAreaHeight), Color.White); x += this.Distance; pSpriteBatch.Draw(this.Game.StringTexture, new Rectangle(x, this.Y, 1, this.Height + this.MatchAreaHeight), Color.White); x += this.Distance; pSpriteBatch.Draw(this.Game.StringTexture, new Rectangle(x, this.Y, 1, this.Height + this.MatchAreaHeight), Color.White); x += this.Distance; }
public void Constructor() { var tickDataTable = new Double_GtTickDataTable_OneChord(); var guitar = new GtSceneGuitar(tickDataTable); Assert.AreSame(tickDataTable, guitar.TickDataTable); }
public void UpdatePosition_6_0() { //1 note at 5:0 var guitar = new GtSceneGuitar(new Double_GtTickDataTable_1Note(), 4); guitar.ForceCurrentPosition(new BeatTick(6, 0)); Assert.AreEqual(-480, guitar.Notes[0].DistanceFromCurrentPosition); }
private void RenderVisibleNotes(GtSceneGuitar pSceneGuitar, SpriteBatch pSpriteBatch) { IList <GtSceneGuitarNote> visibleNotes = pSceneGuitar.GetVisibleNotes(); foreach (var note in visibleNotes) { RenderNote(pSceneGuitar, note, pSpriteBatch); } }
public void CurrentExpectedPlayingNotes_StartingAtFirstBeat() { //1 note at 1:0 var guitar = new GtSceneGuitar(new Double_GtTickDataTable_1NoteFirstBeat(), 30); var position = new BeatTick(1, 0); guitar.ForceCurrentPosition(position); Assert.AreEqual(1, guitar.CurrentStartingNotes.Count); Assert.AreEqual(1, guitar.CurrentExpectedPlayingNotes.Count); }
public void CurrentExpectedPlayingNotes_Tolerance_InBounds2() { var guitar = new GtSceneGuitar(new Double_GtTickDataTable_32Notes(), 30); var position = new BeatTick(2, 0); guitar.ForceCurrentPosition(position); Assert.AreEqual(3, guitar.CurrentStartingNotes.Count); guitar.ForceCurrentPosition(position.AddTicks(200)); Assert.AreEqual(0, guitar.CurrentStartingNotes.Count); }
private void DrawPanelWithAllNotesByFret(GtSceneGuitar pSceneGuitar, SpriteBatch pSpriteBatch) { for (var fret = 0; fret <= 21; fret++) { #region draw the ball/star/square Texture2D noteTexture; if (fret < 7) { noteTexture = this.Game.BallTexture; } else if (fret < 14) { noteTexture = this.Game.StarTexture; } else { noteTexture = this.Game.SquareTexture; } var x = this.X + (7 * this.Distance); var y = 3 + (fret * this.BallWidth); pSpriteBatch.Draw(noteTexture, new Rectangle(x, y, this.BallWidth, this.BallWidth), CalculateColorByFret(fret)); #endregion #region Draw the fret number var noteContent = fret.ToString(); int shift; if (noteContent.Length == 1) { shift = 8; //1 digit } else { shift = 2; //2 digits } var x2 = x + 3; //2 var y2 = y + 5; //4 pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift - 2, y2), Color.Black); pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift, y2 - 2), Color.Black); pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift + 2, y2), Color.Black); pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift, y2 + 2), Color.Black); pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift, y2), Color.White); #endregion } }
public void CurrentStartingNotes_OneNote() { //1 note at 5:0 var guitar = new GtSceneGuitar(new Double_GtTickDataTable_1Note(), 4); guitar.ForceCurrentPosition(new BeatTick(1, 0)); Assert.AreEqual(0, guitar.CurrentStartingNotes.Count); guitar.ForceCurrentPosition(new BeatTick(5, 0)); Assert.AreEqual(1, guitar.CurrentStartingNotes.Count); }
public void CurrentStartingNotes_Tolerance_OutOfBounds() { //1 note at 5:0 var guitar = new GtSceneGuitar(new Double_GtTickDataTable_1Note(), 30); var position = new BeatTick(5, 0); guitar.ForceCurrentPosition(position.AddTicks(GtSceneGuitar.PLAYER_TOLERANCE_IN_TICKS + 1)); Assert.AreEqual(0, guitar.CurrentStartingNotes.Count); guitar.ForceCurrentPosition(position.SubTicks(GtSceneGuitar.PLAYER_TOLERANCE_IN_TICKS + 1)); Assert.AreEqual(0, guitar.CurrentStartingNotes.Count); }
public void Render(GtSceneGuitar pSceneGuitar, SpriteBatch pSpriteBatch) { RenderNeck(pSceneGuitar, pSpriteBatch); RenderFrets(pSceneGuitar, pSpriteBatch); RenderStrings(pSceneGuitar, pSpriteBatch); RenderVisibleNotes(pSceneGuitar, pSpriteBatch); RenderMatchBalls(pSceneGuitar, pSpriteBatch); DrawPanelWithAllNotesByFret(pSceneGuitar, pSpriteBatch); }
public void CurrentExpectedPlayingNotes_Tolerance_InBounds() { //1 note at 5:0 var guitar = new GtSceneGuitar(new Double_GtTickDataTable_1Note(), 30); var position = new BeatTick(5, 0); guitar.ForceCurrentPosition(position.SubTicks(GtSceneGuitar.PLAYER_TOLERANCE_IN_TICKS)); Assert.AreEqual(1, guitar.CurrentStartingNotes.Count); //the note at (5:0) has 8 beats of duration. guitar.ForceCurrentPosition(position.AddTicks((8 * 480) + GtSceneGuitar.PLAYER_TOLERANCE_IN_TICKS)); Assert.AreEqual(1, guitar.CurrentExpectedPlayingNotes.Count); }
public void SetupSong_InvalidNumberOfPlayers() { var factory = new GtFactory(); factory.AddMapping <IAudioListener, DoubleAudioListenerDoNothing>(); var controller = new GtGameRoundController( factory, new GtGameController(new GtFileLoaderDouble6())); var guitar1 = new GtSceneGuitar(new GtTickDataTable(4)); var guitar2 = new GtSceneGuitar(new GtTickDataTable(4)); controller.SetupSong(1, new Double_SongPlayerWithTimer(new BeatTick(5, 0)), "Artist", "Album", "Song", 0.0f, guitar1, guitar2); }
public void VisibleNotes_Position5_120() { var guitar = new GtSceneGuitar(new Double_GtTickDataTable_1Note(), 4); guitar.ForceCurrentPosition(new BeatTick(5, 120)); Assert.AreEqual(new BeatTick(5, 120), guitar.CurrentPosition); var visibleNotes = guitar.GetVisibleNotes(); Assert.AreEqual(1, visibleNotes.Count); Assert.AreEqual(6, visibleNotes[0].String); Assert.AreEqual(0, visibleNotes[0].Fret); }
public void SetupSong_OnePlayer() { var factory = new GtFactory(); factory.AddMapping <IAudioListener, DoubleAudioListenerDoNothing>(); var controller = new GtGameRoundController( factory, new GtGameController(new GtFileLoaderDouble6())); var guitar1 = new GtSceneGuitar(new GtTickDataTable(4)); controller.SetupSong(1, new Double_SongPlayerWithTimer(new BeatTick(5, 0)), "Artist", "Album", "Song", 0.0f, guitar1); Assert.AreEqual(1, controller.SceneGuitars.Count()); Assert.AreSame(guitar1, controller.SceneGuitars[0]); }
private void RenderFrets(GtSceneGuitar pSceneGuitar, SpriteBatch pSpriteBatch) { this.FretHeight = this.Height / pSceneGuitar.NumberOfVisibleBeats; this.TickHeight = this.FretHeight / 480.0f; int firstFretPosition = (int)(this.Height - ((480 - pSceneGuitar.CurrentPosition.Tick) * this.TickHeight)); for (int i = 0; i < pSceneGuitar.NumberOfVisibleBeats; i++) { var position = firstFretPosition - (i * this.FretHeight); if (position >= this.Y) { pSpriteBatch.Draw(this.Game.FretTexture, new Rectangle(this.X - this.Distance, position, 7 * this.Distance, 2), Color.Gray); } } }
public void PlayMusic() { var factory = new GtFactory(); factory.AddMapping <IAudioListener, DoubleAudioListenerDoNothing>(); var controller = new GtGameRoundController( factory, new GtGameController(new GtFileLoaderDouble6())); var guitar1 = new GtSceneGuitar(new GtTickDataTable(4)); controller.SetupSong(1, new Double_SongPlayerWithTimer(new BeatTick(5, 0)), "Artist", "Album", "Song", 0.0f, guitar1); controller.PlaySong(); Assert.AreEqual(EnumGameRoundState.Playing, controller.GameRoundState); }
private void RenderMatchBalls(GtSceneGuitar pSceneGuitar, SpriteBatch pSpriteBatch) { for (int iString = 1; iString <= 6; iString++) { var x = this.X - (this.Distance / 2); //start position - 6th string //positioning at the correct string x += (6 - iString) * this.Distance; x += 2; var color = Color.White; switch (iString) { case 6: x += 1; //this string is large break; case 5: x += 1; //this string is large break; case 4: x += 1; //this string is large break; case 3: break; case 2: break; case 1: break; } pSpriteBatch.Draw(this.Game.MatchBallTexture, new Rectangle(x, this.MatchBall_Y, this.BallWidth, this.BallWidth), Color.Silver); } }
public void PropertyNotes_OneChord() { var guitar = new GtSceneGuitar(new Double_GtTickDataTable_OneChord()); AssertFSharpAt(guitar, (new BeatTick(1, 0)), "F# at 1:0"); }
public void ConstructorParametersValidation1() { var guitar = new GtSceneGuitar(null); }
public void ConstructorParametersValidation2() { var guitar = new GtSceneGuitar(new GtTickDataTable(0)); }
private void RenderNeck(GtSceneGuitar pSceneGuitar, SpriteBatch pSpriteBatch) { pSpriteBatch.Draw(this.Game.GuitarNeckTexture, new Rectangle(this.X - this.Distance, this.Y, 7 * this.Distance, this.Height + this.MatchAreaHeight), Color.Gray); }
private void RenderNote(GtSceneGuitar pSceneGuitar, GtSceneGuitarNote pSceneGuitarNote, SpriteBatch pSpriteBatch) { var x = this.X - (this.Distance / 2); //start position - 6th string //positioning at the correct string x += (6 - pSceneGuitarNote.String) * this.Distance; x += 2; var color = CalculateNoteColor(pSceneGuitarNote); switch (pSceneGuitarNote.String) { case 6: x += 1; //this string is large break; case 5: x += 1; //this string is large break; case 4: x += 1; //this string is large break; case 3: break; case 2: break; case 1: break; } //Draw the boll int y = this.Height - (int)(this.TickHeight * pSceneGuitarNote.DistanceFromCurrentPosition) - (this.BallWidth / 2); if (y < 0) { return; } var noteRectangle = new Rectangle(x, y, this.BallWidth, this.BallWidth); this.RenderNoteDuration(pSceneGuitarNote, noteRectangle, color, pSpriteBatch); if (pSceneGuitarNote.Fret < 7) { pSpriteBatch.Draw(this.Game.BallTexture, noteRectangle, color); } else if (pSceneGuitarNote.Fret < 14) { pSpriteBatch.Draw(this.Game.StarTexture, noteRectangle, color); } else { pSpriteBatch.Draw(this.Game.SquareTexture, noteRectangle, color); } #region Draw the note content (note letter or fret number) string noteContent; int shift; noteContent = pSceneGuitarNote.Fret.ToString(); //noteContent = pSceneGuitarNote.NoteValue.AsSharpedString(); //Draw the fret number if (noteContent.Length == 1) { shift = 8; //1 digit } else { shift = 2; //2 digits } var x2 = x + 3; var y2 = y + 5; pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift - 2, y2), Color.Black); pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift, y2 - 2), Color.Black); pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift + 2, y2), Color.Black); pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift, y2 + 2), Color.Black); pSpriteBatch.DrawString(this.Game.FontFretNumbers, noteContent, new Vector2(x2 + shift, y2), Color.White); #endregion if (pSceneGuitarNote.Playing) { var fireHeight = 3 * this.BallWidth; var fireRectangle = new Rectangle(x, MatchBall_Y - fireHeight + (2 * this.BallWidth / 3), this.BallWidth, fireHeight); pSpriteBatch.Draw(this.Game.FireTexture, fireRectangle, Color.White); } #region Draw the chord name var tickData = pSceneGuitar.TickDataTable[pSceneGuitarNote.StartPosition.Beat, pSceneGuitarNote.StartPosition.Tick]; if (tickData.IsStartTick) { var chordName = tickData.RemarkOrChordName; pSpriteBatch.DrawString( this.Game.FontFretNumbers, " " + chordName, new Vector2(this.X - (2 * this.Distance), y), //left Color.Silver); if (tickData.DrawChord) { RenderChordPicture(pSpriteBatch, tickData, y); } } #endregion }