/// <summary> /// Starts a game session /// </summary> /// <param name="playerNames">List of player names</param> public void Setup(List <string> playerNames, ImagePool.FrontTypes frontType, ImagePool.BackTypes backType, Board.Layouts layout) { currentSession = new Session(board, playerViews); currentSession.Setup(playerNames, frontType, backType, layout); currentSession.GameFinished += FinishGame; }
/// <summary> /// Setup the board /// </summary> /// <param name="layout">Layout for the board</param> /// <param name="frontTypes">Fronttype for the cards</param> /// <param name="backTypes">Backtype for the cards</param> public void Setup(Layouts layout, ImagePool.FrontTypes frontTypes, ImagePool.BackTypes backTypes) { // Reset all variables cards.Clear(); clickedCards.Clear(); cardsLeftCount = 0; this.layout = layout; switch (layout) { case Layouts.FourByFour: MakeFourByFour(frontTypes, backTypes); break; case Layouts.FiveByFive: MakeFiveByFive(frontTypes, backTypes); break; case Layouts.SixByFour: MakeSixByFour(frontTypes, backTypes); break; case Layouts.SixBySix: MakeSixBySix(frontTypes, backTypes); break; } }
public void Setup(List <string> playerNames, ImagePool.FrontTypes frontType, ImagePool.BackTypes backType, Board.Layouts layout) { Done = false; initialPlayerNames = playerNames; initialFrontType = frontType; initialBackType = backType; initialLayout = layout; // Make board board.Setup(initialLayout, frontType, backType); board.MatchMade += OnMatchMade; board.GameFinished += OnGameFinished; // Make players players.Clear(); for (int i = 0; i < initialPlayerNames.Count; i++) { Player player = new Player(initialPlayerNames[i]); players.Add(player); } BindPlayersToViews(); CurrentPlayerIndex = 0; }
/// <summary> /// Navigate to the game /// </summary> /// <param name="playerNames">List of all player names</param> /// <param name="frontType">Fronttype for the cards</param> /// <param name="backType">Backtype for the cards</param> /// <param name="layout">Layout for the board</param> public void NavigateToGame(List <string> playerNames, ImagePool.FrontTypes frontType, ImagePool.BackTypes backType, Board.Layouts layout) { PageGame game = new PageGame(this); currentPage = game; Navigate(game); game.Setup(playerNames, frontType, backType, layout); }
private void MakeSixBySix(ImagePool.FrontTypes frontType, ImagePool.BackTypes backType) { List <ImageDefinition> imageDefinitions = PrepareImageDefinitions(frontType, backType, 36); MakeGrid(6, 6); for (int i = 0; i < 36; i++) { MakeCard(i % 6, i / 6, imageDefinitions[i]); } }
private void MakeFourByFour(ImagePool.FrontTypes frontType, ImagePool.BackTypes backType) { List <ImageDefinition> imageDefinitions = PrepareImageDefinitions(frontType, backType, 16); MakeGrid(4, 4); for (int i = 0; i < 16; i++) { MakeCard(i % 4, i / 4, imageDefinitions[i]); } }
/// <summary> /// Sets up the board as six by four /// </summary> /// <param name="frontType">Fronttype of the cards</param> /// <param name="backType">Backtype of the cards</param> private void MakeSixByFour(ImagePool.FrontTypes frontType, ImagePool.BackTypes backType) { List <ImageDefinition> imageDefinitions = CreateImageDefinitions(frontType, backType, 24); MakeGrid(6, 4); for (int i = 0; i < 24; i++) { MakeCard(i % 4, i / 4, 100, 100, imageDefinitions[i]); } }
private void MakeFiveByFive(ImagePool.FrontTypes frontType, ImagePool.BackTypes backType) { List <ImageDefinition> imageDefinitions = PrepareImageDefinitions(frontType, backType, 24); MakeGrid(5, 5); for (int i = 0; i < 25; i++) { if (i == 12) { continue; // Skip the center tile } MakeCard(i % 5, i / 5, imageDefinitions[i]); } }
private List <ImageDefinition> PrepareImageDefinitions(ImagePool.FrontTypes frontType, ImagePool.BackTypes backType, int count) { List <ImageDefinition> newImageDefintions = new List <ImageDefinition>(count); List <int> indexes = Utilities.GetRandomIntSet(ImagePool.frontImages[frontType].Count, count / 2); for (int i = 0; i < count / 2; i++) { int frontImageId = indexes[i]; for (int j = 0; j < 2; j++) { newImageDefintions.Add(new ImageDefinition(frontType, frontImageId, backType)); } } Utilities.Shuffle(newImageDefintions); return(newImageDefintions); }
/// <summary> /// Sets up the board as five by five /// </summary> /// <param name="frontType">Fronttypes for the cards</param> /// <param name="backType">Backtypes for the cards</param> private void MakeFiveByFive(ImagePool.FrontTypes frontType, ImagePool.BackTypes backType) { List <ImageDefinition> imageDefinitions = CreateImageDefinitions(frontType, backType, 24); MakeGrid(5, 5); for (int i = 0; i < 25; i++) { int id = i; if (id == 12) { continue; // Skip the center tile } if (id > 12) { id--; // Decrement the id when over 12 } MakeCard(i % 5, i / 5, 80, 80, imageDefinitions[id]); } }
/// <summary> /// Creates image definitions for the cards /// </summary> /// <param name="frontType">Fronttype for the cards</param> /// <param name="backType">Backtype for the cards</param> /// <param name="count">Amount of image definitions to prepare</param> /// <returns>List of image definition of size count. Each image definition is in the list twice</returns> private List <ImageDefinition> CreateImageDefinitions(ImagePool.FrontTypes frontType, ImagePool.BackTypes backType, int count) { // Prepare list List <ImageDefinition> imageDefinitions = new List <ImageDefinition>(count); // Create list of random indexes of size count/2 List <int> indexes = Utilities.GetRandomIntSet(ImagePool.frontImages[frontType].Count, count / 2); // Create two image definitions for each index foreach (int index in indexes) { imageDefinitions.Add(new ImageDefinition(frontType, index, backType)); imageDefinitions.Add(new ImageDefinition(frontType, index, backType)); } // Shuffle the image definitions list Utilities.Shuffle(imageDefinitions); return(imageDefinitions); }
public void Setup(Layouts layouts, ImagePool.FrontTypes frontTypes, ImagePool.BackTypes backTypes) { cards.Clear(); switch (layouts) { case Layouts.FourByFour: MakeFourByFour(frontTypes, backTypes); break; case Layouts.FiveByFive: MakeFiveByFive(frontTypes, backTypes); break; case Layouts.FourBySix: MakeFourBySix(frontTypes, backTypes); break; case Layouts.SixBySix: MakeSixBySix(frontTypes, backTypes); break; } }
private void Start() { ImagePool.FrontTypes frontType = ImagePool.FrontTypes.POKEMON; ImagePool.BackTypes backType = ImagePool.BackTypes.POKEMON; // Make board board.Setup(initialLayout, frontType, backType); board.CardClicked += OnCardClicked; // Make players and bind them to views players.Clear(); for (int i = 0; i < initialPlayerNames.Count; i++) { Player player = new Player(initialPlayerNames[i]); playerViews[i].Bind(player); players.Add(player); } CurrentPlayerIndex = 0; clickedCards.Clear(); }
public ImageDefinition(ImagePool.FrontTypes frontImageName, int frontImageId, ImagePool.BackTypes backImageName) { this.frontImageType = frontImageName; this.frontImageId = frontImageId; this.backImageType = backImageName; }
/// <summary> /// On play button clicked /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Events</param> private void OnButtonPlayClicked(object sender, MouseEventArgs e) { // Create lists of players List <string> playerNames = new List <string>(); foreach (CustomTextbox textBox in textBoxes) { playerNames.Add(textBox.textbox.Text); } // Create front type ImagePool.FrontTypes frontType = default; if (selectedForeCard == cardForePokemon) { frontType = ImagePool.FrontTypes.POKEMON; } else if (selectedForeCard == cardForeAnimals) { frontType = ImagePool.FrontTypes.ANIMALS; } else if (selectedForeCard == cardForeMario) { frontType = ImagePool.FrontTypes.MARIO; } // Create back type ImagePool.BackTypes backType = default; if (selectedBackCard == cardBackPokemon) { backType = ImagePool.BackTypes.POKEMON; } else if (selectedBackCard == cardBackVintage) { backType = ImagePool.BackTypes.VINTAGE; } else if (selectedBackCard == cardBackMario) { backType = ImagePool.BackTypes.MARIO; } // Create boar layout Board.Layouts layout = default; if (selectedGridSizeButton == buttonFourByFour) { layout = Board.Layouts.FourByFour; } else if (selectedGridSizeButton == buttonFiveByFive) { layout = Board.Layouts.FiveByFive; } else if (selectedGridSizeButton == buttonSixByFour) { layout = Board.Layouts.SixByFour; } else if (selectedGridSizeButton == buttonSixBySix) { layout = Board.Layouts.SixBySix; } // Navigate window.NavigateToGame(playerNames, frontType, backType, layout); }