/// <summary> /// Creates a new coloured object /// </summary> /// <param name="colour">The colour of the object</param> /// <param name="x">The coloured object's x position</param> /// <param name="y">The coloured object's y position</param> /// <param name="w">The coloured object's width</param> /// <param name="h">The coloured object's height</param> public ColouredObject(int x, int y, int w, int h, ColouredObject.Colours colour) : base(x,y,w,h) { this.Colour = colour; // Populate the colour dictionary if it is empty if (_colourLookup.Count == 0) { _colourLookup.Add(Colours.Grey, Color.Gray); _colourLookup.Add(Colours.Blue, Color.DeepSkyBlue); _colourLookup.Add(Colours.Green, Color.Green); _colourLookup.Add(Colours.Red, Color.Red); _colourLookup.Add(Colours.Yellow, Color.Yellow); _colourLookup.Add(Colours.White, Color.White); } }
/// <summary> /// Removes the appropriate amount of cubes for a trophy that has been won /// </summary> /// <param name="colour">The colour of the trophy</param> /// <returns>The list of trophies that have been won</returns> private Trophy WinTrophy(ColouredObject.Colours colour) { Trophy won = new Trophy(colour); Trophies.Add(won); // Remove the appropriate amount of cubes int numRemoved = 0; for (int i = 0; i < Cubes.Count; i++) { if (Cubes[i].Colour == colour && numRemoved < (int)colour) // colour can be cast as int because reference starts at three. { Cubes.RemoveAt(i); numRemoved++; } } return won; }
/// <summary> /// Counts the number of coloured cubes in the player's possesion /// </summary> /// <param name="colour">The colour of the cube to count</param> /// <returns></returns> public int CubeCount(ColouredObject.Colours colour) { int count = 0; foreach (Cube c in this.Cubes) if (c.Colour == colour) count++; return count; }
/// <summary> /// Checks if this side of the tile has a spare slot for this colour. /// e.g. If the number of Red Cards is equal to the number of Red Cubes, this returns false /// because the player needs to fill the other colours. /// </summary> /// <param name="colour">The colour to check for</param> /// <param name="position">The slot's position around the tile</param> /// <returns>The validity of the move</returns> public bool HasEmptySlotWithMatchingCube(ColouredObject.Colours colour, CardSlot.Position position) { if(HasCubeWithColour(colour)) // If a Cube with this colour exists { // Count how many cubes have this colour int numCubesWithColour = 0; foreach(Cube cube in _cubes) if(cube.Colour == colour) numCubesWithColour++; // See how many slots already have a card with this colour int numCardsWithColour = 0; foreach(CardSlot cardSlot in CardSlots) // If the slot already has a card of this colour in it if(cardSlot.SlotPosition == position && cardSlot.CurrentCard != null && cardSlot.CurrentCard.Colour == colour) numCardsWithColour++; // Are there already the same amount of cubes with this colour as cards with this colour? if (numCardsWithColour >= numCubesWithColour) return false; else return true; } else return false; }
/// <summary> /// Check if this tile contains a cube with a certain colour /// </summary> /// <param name="colour">The colour of cube to check for</param> /// <returns>True if the tile has a cube of that colour</returns> public bool HasCubeWithColour(ColouredObject.Colours colour) { foreach (Cube cube in Cubes) if (cube.Colour == colour) return true; return false; }