public void when_calculating_value_of_10th_frame_if_scratch() { AbstractFrame frame = new LastFrame(3, 4, 7, 2); var value = frame.Value(); Assert.AreEqual(value, 7); }
public void when_calculating_value_of_10th_frame_if_strike() { AbstractFrame frame = new LastFrame(10, 3, 7, 2); var value = frame.Value(); Assert.AreEqual(value, 20); }
private List <IFrame> GetFakeFrames() { var frames = new List <IFrame>(); var frameOne = new Frame { FirstScore = 3, SecondScore = 3 }; var frameTwo = new Frame { FirstScore = 10, SecondScore = 0 }; var lastFrame = new LastFrame { FirstScore = 3, SecondScore = 6, ThirdScore = 0 }; frames.Add(frameOne); frames.Add(frameTwo); frames.Add(lastFrame); return(frames); }
public void AddFrame(LastFrame frame) // Додавання останнього фрейму { if (frames.Count == 9) { lastFrame = frame; isLast = true; if (frames[8].IsSpare()) { frames[8].ResetScore(lastFrame.GetScoreFirst()); } else if (frames[6].IsStrike() && frames[7].IsStrike() && frames[8].IsStrike()) { frames[6].SetScore(30); frames[7].ResetScore(lastFrame.GetScoreFirst()); frames[8].ResetScore(lastFrame.GetScore()); } else if (frames[7].IsStrike() && frames[8].IsStrike()) { frames[7].ResetScore(lastFrame.GetScoreFirst()); frames[8].ResetScore(lastFrame.GetScore()); } else if (frames[8].IsStrike()) { frames[8].ResetScore(lastFrame.GetScore()); } } }
public override IAwaitable TestExecute(IServices services) { var firstFrame = LastFrame.Int32(services); var lastFrame = FirstFrame.Int32(services); ServiceId.Rendering[services].AnimateBackground(firstFrame, lastFrame); return(DummyAwaitable.Instance); }
public void should_valid_when_create_invalid_10th_frame_pinhit_less_than_Max_point() { Bowl b2 = new Bowl(10); Bowl b3 = new Bowl(10); AbstractFrame frame = new LastFrame(strike, b2, b3, 2); Assert.IsTrue(frame.IsValid); }
public void when_adding_bowls_to_10th_frame() { LastFrame frame = new LastFrame(10, 3, 7, 2); Assert.AreEqual(frame.FirstBowl.PinsDrop, 10); Assert.AreEqual(frame.SecondBowl.PinsDrop, 3); Assert.AreEqual(frame.ExtraBowl.PinsDrop, 7); Assert.IsTrue(frame.Index == 2); }
public LastFrameTests() { _frameUnderTest = new LastFrame(new [] { new Roll(5), new Roll(5), new Roll(1) }); _frameUnderTest2 = new LastFrame(new [] { new Roll(10), new Roll(10), new Roll(10) }); _frameUnderTest3 = new LastFrame(new [] { new Roll(10), new Roll(3), new Roll(2) }); _frameUnderTest4 = new LastFrame(new [] { new Roll(1), new Roll(1) }); _framesUnderTest = new LastFrame[] { _frameUnderTest, _frameUnderTest2, _frameUnderTest3, _frameUnderTest4 }; }
public void LastFrameShouldSimplyAddUpAllItsBalls() { //given var lastFrame = new LastFrame(1, 9, 2); //when int score = lastFrame.Score; //then Assert.AreEqual(12, score); }
public void LastFrameShouldSimplyCountItsScoreAsThreeBallsSum() { //given var lastFrame = new LastFrame(1, 2, 3); //when var score = lastFrame.Score; //then Assert.AreEqual(6, score); }
public void LastFrameShouldJustAddThreeTries() { //given var lastFrame = new LastFrame {FirstTry = 2, SecondTry = 4, ThirdTry = 6}; //when var score = lastFrame.Score; //then Assert.AreEqual(12, score); }
public void LastFrameShouldSimplyAddAllThreeBallsUp() { //given var lastFrame = new LastFrame(1, 2, 3); //when var score = lastFrame.Score; //then Assert.AreEqual(6, score); }
private void SetLastFrame(SimpleBitmap bmp) { lock (ImageProcessLock) { if (LastFrame != null && LastFrame.Locked) { LastFrame.Dispose(true); } LastFrame = bmp; } }
public void LastFrameShouldJustAddThreeTries() { //given var lastFrame = new LastFrame { FirstTry = 2, SecondTry = 4, ThirdTry = 6 }; //when var score = lastFrame.Score; //then Assert.AreEqual(12, score); }
public void LastRoundCalculateScoreShouldThrowInvalidScoreException() { // Arrange var currentFrame = new LastFrame(); currentFrame.FirstScore = 9; currentFrame.SecondScore = 2; currentFrame.ThirdScore = 10; // Act var score = currentFrame.CalculateScore(); }
public void LastRoundShouldCalculateFrameShouldThrowInvalidScoreException() { // Arrange var currentFrame = new LastFrame { FirstScore = 5, SecondScore = 7, ThirdScore = 3 }; // Act var frameScore = currentFrame.CalculateOpenFrame(); }
public void Score_DoubleStrikeType_ShouldGet2NextBalls() { var frame = new Frame(); var frame2 = new LastFrame(); frame.TryToAddPins(10); frame2.TryToAddPins(10); frame2.TryToAddPins(1); frame2.TryToAddPins(5); frame.NextFrame = frame2; frame2.PreviousFrame = frame; frame.Score.Should().Be(21); }
public void NinethFrameShouldIncludeNext2BallsAsBonusWhenThereAre2ConsectiveStrikes() { //given Frame frame = new Frame(10, 0); LastFrame frame2 = new LastFrame(10, 2, 3); frame.Next = frame2; //when int score = frame.Score; //then Assert.AreEqual(22, score); }
public void FrameShouldCountItsScoreWithNext2BallsAsBonusWhenNextFrameIsLast() { //given var frame = new Frame(10, 0); var nextFrame = new LastFrame(10, 3, 4); frame.Next = nextFrame; //when var score = frame.Score; //then Assert.AreEqual(23, score); }
public void FrameShouldIncludeNextTwoBallsAsBonusWhenNextToStrikeIsLastFrame() { //given var frame = new Frame(10, 0); var frame2 = new LastFrame(10, 3, 4); frame.Next = frame2; //when var score = frame.Score; //then Assert.AreEqual(23, score); }
public void LastRoundShouldSumAsOpenFrame() { // Arrange var currentFrame = new LastFrame { FirstScore = 5, SecondScore = 5, ThirdScore = 3 }; // Act var score = currentFrame.CalculateOpenFrame(); // Assert Assert.AreEqual((5 + 5 + 3), score); Assert.AreEqual(FrameMark.Spare, currentFrame.FrameMark); }
public LastFrameTest() { _frame = new LastFrame(); }
/// <summary> /// The button was released between this and last frame (and is still released in the current frame) /// </summary> /// <param name="button">On button</param> /// <returns>True if the button was just released, otherwise false</returns> public bool IsJustReleased(Buttons button) { return(LastFrame.IsButtonDown(button) && CurrentFrame.IsButtonUp(button)); }
public void SetArgVar(int index, IValue var) { LastFrame.SetARGVar(index, var); LastFrame.SetARGVar(index, var.Data); }
public static void Read(string fileName, ConversionSettings conversionSettings, ref DisplayList dsp, out Dictionary <string, TextureInfo> allMaterials, out string[] messages) { List <string> messageList = new List <string>(); string currentObject = ""; Subset LastFrame = null; List <Subset> Frames = new List <Subset>(); List <Vertex> Vertices = new List <Vertex>(); List <int> Indices = new List <int>(); List <FaceVertex> faceVertices = new List <FaceVertex>(); List <Vertex> dspVertexBuffer = new List <Vertex>(); List <int[]> dspIndexBuffers = new List <int[]>(); List <int> dspTextureKeys = new List <int>(); int[] dspIndices; int minVertexIndex = 0; List <Vector3> positions = new List <Vector3>(); List <Vector2> texCoords = new List <Vector2>(); List <Vector3> normals = new List <Vector3>(); allMaterials = new Dictionary <string, TextureInfo>(); allMaterials["<Undefined>"] = new TextureInfo(null); string[] fileNameSplit = fileName.Split(new char[] { '/', '\\' }); string fileRelativePath = fileName.Remove(fileName.Length - (fileNameSplit[fileNameSplit.Length - 1].Length), fileNameSplit[fileNameSplit.Length - 1].Length); if (!System.IO.File.Exists(fileName)) { messages = new string[] { "File " + fileName + " was not found." }; return; } StreamReader rd = new StreamReader(fileName); StreamReader materialReader = null; while (!rd.EndOfStream) { string line = rd.ReadLine(); string[] split = line.Split(' '); if (split[0] == "mtllib") { materialReader = new StreamReader(fileRelativePath + line.Remove(0, split[0].Length + 1)); string currentMtl = null; while (!materialReader.EndOfStream) { string matLine = materialReader.ReadLine(); string[] matSplit = matLine.Split(' '); if (matSplit[0] == "newmtl") { currentMtl = matLine.Remove(0, matSplit[0].Length); } if (matSplit[0] == "map_Kd") { TextureInfo newTex; string fullPath = matLine.Remove(0, matSplit[0].Length).Trim(); if (fullPath[1] != ':') { fullPath = fileRelativePath + fullPath; } allMaterials.Add(currentMtl, newTex = new TextureInfo(fullPath)); } } } else if (split[0] == "o") //Object { if (LastFrame == null) { LastFrame = new Subset(); } currentObject = split[1]; } else if (split[0] == "v") // Vertex { positions.Add(cvt.ParseVector3(split, 1)); } else if (split[0] == "vn")// Vertex Normal { normals.Add(cvt.ParseVector3(split, 1)); } else if (split[0] == "vt") // Vertex TexCoord { texCoords.Add(cvt.parseVector2(split, 1)); } else if (split[0] == "usemtl") { LastFrame.VertexBuffer = Vertices.ToArray(); LastFrame.IndexBuffer = Indices.ToArray(); dspIndices = new int[LastFrame.IndexBuffer.Length]; for (int i = 0; i < LastFrame.IndexBuffer.Length; i += 3) { dspIndices[i] = LastFrame.IndexBuffer[i + 2] + minVertexIndex; dspIndices[i + 1] = LastFrame.IndexBuffer[i + 1] + minVertexIndex; dspIndices[i + 2] = LastFrame.IndexBuffer[i] + minVertexIndex; } if (Indices.Count > 0) { dspIndexBuffers.Add(dspIndices); LastFrame.CreatePatches(); Frames.Add(LastFrame); } Indices.Clear(); LastFrame = new Subset(); string mtlName = line.Remove(0, split[0].Length); if (!allMaterials.TryGetValue(mtlName, out LastFrame.Texture)) { messageList.Add("Object " + currentObject + " has unassigned faces."); LastFrame.Texture = allMaterials["<Undefined>"]; } } else if (split[0] == "f") // Face { int i0 = 0, ix = 0; for (int i = 1; i < split.Length; i++) { string[] vertexIndices = split[i].Split('/'); FaceVertex faceVertex = new FaceVertex(); int.TryParse(vertexIndices[0], out faceVertex.Vertex); if (vertexIndices.Length > 1) { int.TryParse(vertexIndices[1], out faceVertex.Texture); } if (vertexIndices.Length > 2) { int.TryParse(vertexIndices[2], out faceVertex.Normal); } int index = 0; foreach (FaceVertex v in faceVertices) { if (v.Vertex == faceVertex.Vertex && v.Texture == faceVertex.Texture && v.Normal == faceVertex.Normal) { break; } index++; } if (i > 3) { Indices.Add(i0); Indices.Add(ix); } Indices.Add(index); if (i == 1) { i0 = index; } ix = index; if (index == faceVertices.Count) { faceVertices.Add(faceVertex); Vertex newVertex; Vector2 texCoord = Vector2.Empty; if (faceVertex.Texture > 0) { texCoord = texCoords[faceVertex.Texture - 1]; } Vector3 normal = Vector3.Empty; if (faceVertex.Normal > 0) { normal = normals[faceVertex.Normal - 1]; } Vertices.Add(newVertex = new Vertex(positions[faceVertex.Vertex - 1], texCoord, normal)); dspVertexBuffer.Add(newVertex); } } } } rd.BaseStream.Close(); materialReader.Close(); LastFrame.IndexBuffer = Indices.ToArray(); LastFrame.VertexBuffer = Vertices.ToArray(); dspIndices = new int[LastFrame.IndexBuffer.Length]; for (int i = 0; i < LastFrame.IndexBuffer.Length; i += 3) { dspIndices[i] = LastFrame.IndexBuffer[i + 2] + minVertexIndex; dspIndices[i + 1] = LastFrame.IndexBuffer[i + 1] + minVertexIndex; dspIndices[i + 2] = LastFrame.IndexBuffer[i] + minVertexIndex; } dspIndexBuffers.Add(dspIndices); LastFrame.CreatePatches(); Frames.Add(LastFrame); dsp.subsets = Frames.ToArray(); messages = messageList.ToArray(); }
public void ThridBallShouldNotBeBiggerThan10() { var lastFrame = new LastFrame(1, 2, 13); var score = lastFrame.Score; }
public override unsafe void CodeImage(Bitmap bitmap, Stream outStream) { lock (ImageProcessLock) { if (!outStream.CanWrite) { throw new Exception("Must have access to Write in the Stream"); } if (LastFrame == null) { byte[] temp = base.jpgCompression.Compress(bitmap); outStream.Write(BitConverter.GetBytes(temp.Length), 0, 4); outStream.Write(temp, 0, temp.Length); SetLastFrame(ref bitmap); return; } long oldPos = outStream.Position; outStream.Write(new byte[4], 0, 4); int TotalDataLength = 0; List <byte[]> updates = new List <byte[]>(); SimpleBitmap sbBmp = new SimpleBitmap(bitmap); MemoryStream ms = new MemoryStream(); byte[] buffer = null; if (!LastFrame.Locked) { LastFrame.Lock(); } sbBmp.Lock(); if (sbBmp.Info.PixelSize != LastFrame.Info.PixelSize) { throw new Exception("PixelFormat is not equal to previous Bitmap"); } if (LastFrame.Info.Width != sbBmp.Info.Width || LastFrame.Info.Height != sbBmp.Info.Height) { sbBmp.Unlock(); throw new Exception("Bitmap width/height are not equal to previous bitmap"); } List <Rectangle> Blocks = new List <Rectangle>(); int index = 0; int y = 0; int x = 0; Size s = new Size(bitmap.Width, CheckBlock.Height); Size lastSize = new Size(bitmap.Width % CheckBlock.Width, bitmap.Height % CheckBlock.Height); int lasty = bitmap.Height - lastSize.Height; int lastx = bitmap.Width - lastSize.Width; Rectangle cBlock = new Rectangle(); s = new Size(bitmap.Width, s.Height); while (y != bitmap.Height) { if (y == lasty) { s = new Size(bitmap.Width, lastSize.Height); } cBlock = new Rectangle(0, y, bitmap.Width, s.Height); if (onCodeDebugScan != null) { onCodeDebugScan(cBlock); } if (!SimpleBitmap.Compare(cBlock, LastFrame.Scan0_int, sbBmp.Scan0_int, sbBmp.Info)) //if (!SimpleBitmap.Compare(y, s.Height, LastFrame.Scan0_int, sbBmp.Scan0_int, sbBmp.Info)) { index = Blocks.Count - 1; if (Blocks.Count != 0 && (Blocks[index].Y + Blocks[index].Height) == cBlock.Y) { cBlock = new Rectangle(Blocks[index].X, Blocks[index].Y, Blocks[index].Width, Blocks[index].Height + cBlock.Height); Blocks[index] = cBlock; } else { Blocks.Add(cBlock); } } y += s.Height; } List <CacheInfo> finalUpdates = new List <CacheInfo>(); const int CheckHeight = 50; for (int i = 0; i < Blocks.Count; i++) { s = new Size(CheckBlock.Width, Blocks[i].Height); y = Blocks[i].Y; lasty = (Blocks[i].Y + Blocks[i].Height); while (y != lasty) { int ScanHeight = y + CheckHeight > lasty ? lasty - y : CheckHeight; x = 0; while (x != bitmap.Width) { if (x == lastx) { s = new Size(lastSize.Width, Blocks[i].Height); } cBlock = new Rectangle(x, y, s.Width, ScanHeight); if (onCodeDebugScan != null) { onCodeDebugScan(cBlock); } if (!SimpleBitmap.Compare(cBlock, sbBmp.Scan0_int, LastFrame.Scan0_int, sbBmp.Info)) { /*byte[] tempData = new byte[0]; * LastFrame.CopyBlock(cBlock, ref tempData); * finalUpdates.Add(new CacheInfo(0, false, tempData, cBlock));*/ //hash it and see if exists in cache hasher = new CRC32(); //re-initialize for seed byte[] tempData = new byte[0]; LastFrame.CopyBlock(cBlock, ref tempData); int hash = BitConverter.ToInt32(hasher.ComputeHash(tempData), 0); if (codeCached.Count >= MaxBuffers) { codeCached.RemoveAt(0); } if (codeCached.ContainsKey(hash)) { CachedSize += (ulong)tempData.Length; finalUpdates.Add(new CacheInfo(hash, true, new byte[0], cBlock)); } else { //nothing found in cache let's use the normal way codeCached.Add(hash, tempData); finalUpdates.Add(new CacheInfo(hash, false, tempData, cBlock)); } } x += s.Width; } y += ScanHeight; } } for (int i = 0; i < finalUpdates.Count; i++) { buffer = new byte[0]; Rectangle rect = finalUpdates[i].Rect; if (!finalUpdates[i].isCached) { fixed(byte *ptr = finalUpdates[i].Data) { using (Bitmap TmpBmp = new Bitmap(rect.Width, rect.Height, rect.Width * LastFrame.Info.PixelSize, LastFrame.bitmapData.PixelFormat, new IntPtr(ptr))) { buffer = base.jpgCompression.Compress(TmpBmp); } } } outStream.WriteByte(finalUpdates[i].isCached ? (byte)1 : (byte)0); outStream.Write(BitConverter.GetBytes(finalUpdates[i].Rect.X), 0, 4); outStream.Write(BitConverter.GetBytes(finalUpdates[i].Rect.Y), 0, 4); outStream.Write(BitConverter.GetBytes(finalUpdates[i].Rect.Width), 0, 4); outStream.Write(BitConverter.GetBytes(finalUpdates[i].Rect.Height), 0, 4); outStream.Write(BitConverter.GetBytes(finalUpdates[i].Hash), 0, 4); outStream.Write(BitConverter.GetBytes(buffer.Length), 0, 4); outStream.Write(buffer, 0, buffer.Length); TotalDataLength += buffer.Length + (4 * 6) + 1; } outStream.Position = oldPos; outStream.Write(BitConverter.GetBytes(TotalDataLength), 0, 4); Blocks.Clear(); SetLastFrame(sbBmp); ms.Close(); ms.Dispose(); } }
public void should_consider_bonus_frame_when_scoring_last_frame() { var lastFrame = new LastFrame("X", "XX"); Assert.That(lastFrame.GetScore(), Is.EqualTo(30)); }
private bool WasLastFrameASpare() { return(_currentFrame > 0 && LastFrame.IsSpare()); }
public void AddLastFrame(int playerID, LastFrame frame) // Додавання останнього фрейму { players[playerID].AddFrame(frame); }
public void Interact() // Взаємодія із користувачем { bool played = false; bool end = true; while (end) { Console.WriteLine("Choose what you want to do:\n1) Play the game" + "\n2) Add a player" + "\n3) Remove a player" + "\n4) Show the game table" + "\n5) Save the results into the file" + "\n6) End"); Console.Write("Your choice: "); string choice = Console.ReadLine(); Console.WriteLine("\n"); if (choice == "1")// Гра { if (!played) { game.ShowTable(); for (int i = 0; i < 9; i++) { for (int j = 0; j < game.GetPlayerList().Count; j++) { Console.WriteLine("\nEnter info about the numbers of pins, that left after the FIRST throw of {0}, in this format:\n1 2 3 4 5 6 7 8 9 10", game.GetName(j));; int[] indexes1 = Read(); FirstThrow ft = new FirstThrow(indexes1); Console.WriteLine("\nEnter info about the numbers of pins, that left after the SECOND throw of {0}, in this format:\n1 2 3 4 5 6", game.GetName(j)); int[] indexes2 = Read(); SecondThrow st = new SecondThrow(indexes2, ft); Frame fr = new Frame(ft, st); game.AddFrame(j, fr); game.ShowTable(); } } for (int j = 0; j < game.GetPlayerList().Count; j++) { Console.WriteLine("\nEnter info about the numbers of pins, that left after the FIRST throw of {0}, in this format:\n1 2 3 4 5 6 7 8 9 10", game.GetName(j)); int[] indexes1 = Read(); FirstThrow ft = new FirstThrow(indexes1); Console.WriteLine("\nEnter info about the numbers of pins, that left after the SECOND throw of {0}, in this format:\n1 2 3 4 5 6", game.GetName(j)); int[] indexes2 = Read(); SecondThrow st = new SecondThrow(indexes2, ft); LastFrame fr = new LastFrame(ft, st); game.AddLastFrame(j, fr); if (game.IsStrikeLastFrame(j)) { Console.WriteLine("\nEnter info about the numbers of pins, that left after the SECOND throw of {0}, in this format:\n1 2 3 4 5 6 7 8 9 10", game.GetName(j)); indexes2 = Read(); FirstThrow stL = new FirstThrow(indexes2); game.ResetSecondThrowLastFrame(j, stL); if (game.IsStrikeLastFrameSecond(j)) { Console.WriteLine("\nEnter info about the numbers of pins, that left after the THIRD throw of {0}, in this format:\n1 2 3 4 5 6", game.GetName(j)); int[] indexes3 = Read(); FirstThrow thT = new FirstThrow(indexes3); game.SetThirdThrowLastFrame(j, thT); } else { Console.WriteLine("\nEnter info about the numbers of pins, that left after the THIRD throw of {0}, in this format:\n1 2 3 4 5 6", game.GetName(j)); int[] indexes3 = Read(); SecondThrow thT = new SecondThrow(indexes3, stL); game.SetThirdThrowLastFrame(j, thT); } } else if (game.IsSpareLastFrame(j)) { Console.WriteLine("\nEnter info about the numbers of pins, that left after the THIRD throw, in this format of {0}, in this format:\n1 2 3 4 5 6", game.GetName(j)); int[] indexes3 = Read(); FirstThrow thT = new FirstThrow(indexes3); game.SetThirdThrowLastFrame(j, thT); } game.ShowTable(); } played = true; } else { Console.WriteLine("You've already played this game! To start the new one:\n 1) Save the results\n 2) End the game\n 3) Read a file\n"); game.ShowTable(); } } else if (choice == "2") // Додавання нового гравця { Console.WriteLine("Enter info about the player in this format:\nZozulya"); try { string player = Console.ReadLine(); game.AddPlayer(new Player(player)); } catch (PlayerException ex) { CatchExcepts(ex); } finally { Console.WriteLine("\n"); game.ShowPlayerList(); } } else if (choice == "3") // Видалення гравця { try { game.ShowPlayerList(); Console.WriteLine("\nEnter the player's id in this format:\n3"); game.RemovePlayer(Convert.ToInt32(Console.ReadLine())); } catch (FormatException ex) { CatchExcepts(ex); } finally { Console.WriteLine("\n"); game.ShowPlayerList(); } } else if (choice == "4") // Вивід таблиці результатів партії { game.ShowTable(); } else if (choice == "5") // Запис результатів партії у файл players.xml { List <Player> players = game.GetPlayerList(); foreach (Player pl in players) { pl.previousScore = pl.GetTotalScore(); } XmlSerializer playersFormatter = new XmlSerializer(typeof(List <Player>), new XmlRootAttribute("Players")); using (FileStream fs = new FileStream("players.xml", FileMode.OpenOrCreate)) { playersFormatter.Serialize(fs, players); } } else if (choice == "6") // Вихід { Console.WriteLine("Do you want to exit without saving?"); Console.Write("Press y/n: "); string yes = Console.ReadLine(); Console.WriteLine("\n"); if (yes == "y" || yes == "Y") { end = false; } } Console.WriteLine("\n\n"); } }
public void AddLastFrame(int firstTry, int secondTry, int thirdTry = 0) { var frame = new LastFrame {FirstTry = firstTry, SecondTry = secondTry, ThirdTry = thirdTry}; AddFrame(frame); }