private void BtnAddColorClick(object sender, EventArgs e) { var availableColors = Enum.GetValues(typeof(ColorEnum)).Cast <ColorEnum>().ToList(); if (MapEditor.LevelProps.Colors != null) { foreach (var color in MapEditor.LevelProps.Colors) { availableColors.Remove(color); } } var dialog = new AddColorDialog(availableColors); if (dialog.ShowDialog() == DialogResult.OK) { ColorEnum color = dialog.GetColor(); if (MapEditor.LevelProps.Colors == null) { MapEditor.LevelProps.Colors = new List <ColorEnum>(); } MapEditor.LevelProps.Colors.Add(color); this.listColours.Items.Add(new ListViewItem(color.ToString())); } }
///Events /* * Starts a new game of chess, resets the board and variables */ private void Reset(object sender, EventArgs e) { PlayerColor = ColorEnum.White; aPlayerHasWon = false; lblPlayerTurn.Text = PlayerColor.ToString() + "'s Turn"; lblWinText.Text = ""; //Create a basic game of chess gameBoard.createNewBoard(); ColorEnum color = ColorEnum.Black; for (int i = 0; i < 2; i++) { gameBoard.addPiece(new Rook(color, new Location(0, i * 7 - 0))); gameBoard.addPiece(new Knight(color, new Location(1, i * 7 - 0))); gameBoard.addPiece(new Bishop(color, new Location(2, i * 7 - 0))); gameBoard.addPiece(new King(color, new Location(3, i * 7 - 0))); gameBoard.addPiece(new Queen(color, new Location(4, i * 7 - 0))); gameBoard.addPiece(new Bishop(color, new Location(5, i * 7 - 0))); gameBoard.addPiece(new Knight(color, new Location(6, i * 7 - 0))); gameBoard.addPiece(new Rook(color, new Location(7, i * 7 - 0))); for (int j = 0; j < 8; j++) { gameBoard.addPiece(new Pawn(color, new Location(j, Math.Abs(i * 7 - 1)))); } color = ColorEnum.White; } gameBoard.RefreshPieceImage(); }
public EnumSample() { ColorEnum white = ColorEnum.White; Console.WriteLine(white); Console.WriteLine((int)white); Console.WriteLine(white.ToString()); }
protected override void OnMouseUp(MouseEventArgs e) { CurrentMove.EndPosition = MouseOverCoordinate; movement = false; if (CurrentMove.piece != null) { if (Context.CurrentPlayer == CurrentMove.piece.Color) { var nextMove = CurrentMove.piece.GetNextLegalMoves(CurrentMove.StartPosition, Context); if (CurrentMove.piece.GetNextLegalMoves(CurrentMove.StartPosition, Context).Contains(CurrentMove.EndPosition)) { Context.Update(CurrentMove); this.Refresh(); if (CurrentMove.piece.Type == PieceEnum.Pawn && (CurrentMove.EndPosition.Y == 0 || CurrentMove.EndPosition.Y == 9)) { Context.Layout.Promote(CurrentMove.EndPosition, CurrentMove.piece.Color); this.Refresh(); } Cursor = Cursors.Default; if (VsAI) { AI ai = new AI(Context.Clone()); Context.Layout.Update(ai.GetNextMove()); Context.ToggleCurrentPlayer(); this.Refresh(); } if (Context.CheckMating()) { winner = CurrentMove.piece.Color; DialogResult res = MessageBox.Show(winner.ToString() + " won! Do you want to play again?! ", "Game over", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (res == DialogResult.Yes) { OnReplay?.Invoke(); } else { OnExit?.Invoke(); } } if (Context.AlertCheck()) { MessageBox.Show("Check! Save your king!"); Cursor = Cursors.Default; } } Cursor = Cursors.Default; } else { MessageBox.Show("Not your turn"); Cursor = Cursors.Default; } } }
private void button_Click(object sender, EventArgs e) { switch (colorVal) { case ColorEnum.Czerwony: colorVal = ColorEnum.Zielony; button.BackColor = Color.Green; break; case ColorEnum.Zielony: colorVal = ColorEnum.Niebieski; button.BackColor = Color.Blue; break; case ColorEnum.Niebieski: colorVal = ColorEnum.Czerwony; button.BackColor = Color.Red; break; } comboBox.SelectedItem = colorVal.ToString(); button.Text = colorVal.ToString(); }
public void SetDefaultColor(List <ColorEnum> pickedColors) { ColorEnum[] colors = { ColorEnum.Blue, ColorEnum.Red, ColorEnum.Green, ColorEnum.Yellow, ColorEnum.Black, ColorEnum.Purple }; List <ColorEnum> availableColors = new List <ColorEnum>(); foreach (var color in pickedColors) { for (int i = 0; i < colors.Length; i++) { if (color != colors[i]) { availableColors.Add(color); } } } for (int i = 0; i < 1; i++) { m_color = availableColors[Random.Range(0, availableColors.Count)]; Debug.Log(userName + ": " + m_color.ToString()); break; } }
private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { ColorEnum colorV; Enum.TryParse <ColorEnum>(comboBox.SelectedItem.ToString(), out colorV); switch (colorV) { case ColorEnum.Czerwony: button.BackColor = Color.Red; break; case ColorEnum.Zielony: button.BackColor = Color.Green; break; case ColorEnum.Niebieski: button.BackColor = Color.Blue; break; } colorVal = colorV; button.Text = colorVal.ToString(); }
/* * Handles turn shifting, and end game condition (Check, Checkmate, Stalemate) */ public void PieceMoved(object sender, EventArgs e) { //Switching the player ColorEnum previousPlayer = PlayerColor; PlayerColor = (ColorEnum)(((int)PlayerColor + 1) % Enum.GetNames(typeof(ColorEnum)).Length); lblPlayerTurn.Text = PlayerColor.ToString() + "'s Turn"; //Check for check, checkmate, stalemate //TODO IList <AbstractPiece> kings = gameBoard.getPieces(typeof(King), PlayerColor); IList <AbstractPiece> attackers = gameBoard.getAttackers(kings); if (attackers.Count > 0) { //Check if (ColorHasMoves(gameBoard, PlayerColor)) { //Just checked lblWinText.Text = PlayerColor + " Checked"; return; } else { aPlayerHasWon = true; lblWinText.Text = previousPlayer + " Checkmate!"; return; } } else if (!ColorHasMoves(gameBoard, PlayerColor)) { aPlayerHasWon = true; lblWinText.Text = "Stalemate"; return; } lblWinText.Text = ""; }
public Color(ColorEnum id) { Id = id; Name = id.ToString(); Description = id.GetEnumDescription(); }
private void SetAnswerOption(ref BaseQuestion question, ColorEnum randomColor, ConfusionTouch questionType) { ColorEnum color = GetColorBasedOnAnswerOrSpriteID(IDType.AnswerID, CurrentColorID); switch (questionType) { case ConfusionTouch.ColorX: for (int i = 0; i < question.Options.Count; i++) { question.Options[i].Sprite = AnswerInfos[i].SpriteID; question.Options[i].ID = AnswerInfos[i].AnswerID; question.Options[i].text = AnswerInfos[i].TextInBalloon.ToString(); question.Options[i].TextColor = GetColorBasedOnColorEnum(AnswerInfos[i].TextColor); if (CurrentColorID == AnswerInfos[i].AnswerID) { question.Options[i].IsCorrect = true; question.Question = "Touch the " + color.ToString() + " balloon."; } else { question.Options[i].IsCorrect = false; } } break; case ConfusionTouch.WordColorX: for (int i = 0; i < question.Options.Count; i++) { question.Options[i].Sprite = AnswerInfos[i].SpriteID; question.Options[i].ID = AnswerInfos[i].AnswerID; question.Options[i].text = AnswerInfos[i].TextInBalloon.ToString(); question.Options[i].TextColor = GetColorBasedOnColorEnum(AnswerInfos[i].TextColor); if (CurrentColorID == AnswerInfos[i].AnswerID) { question.Options[i].IsCorrect = true; question.Question = "Touch the " + AnswerInfos[i].TextColor.ToString() + " word."; } else { question.Options[i].IsCorrect = false; } } break; case ConfusionTouch.WordX: for (int i = 0; i < question.Options.Count; i++) { question.Options[i].Sprite = AnswerInfos[i].SpriteID; question.Options[i].ID = AnswerInfos[i].AnswerID; question.Options[i].text = AnswerInfos[i].TextInBalloon.ToString(); question.Options[i].TextColor = GetColorBasedOnColorEnum(AnswerInfos[i].TextColor); if (CurrentColorID == AnswerInfos[i].AnswerID) { question.Options[i].IsCorrect = true; question.Question = "Touch the word " + question.Options[i].text + "."; } else { question.Options[i].IsCorrect = false; } } break; } }
/// <summary> /// Main method to set the question property and answer button property for each answer button /// </summary> /// <param name="question">Question.</param> /// <param name="answer">Answer.</param> /// <param name="randomColor">Random color.</param> /// <param name="questionType">Question type.</param> private void SetAnswerOption(ref BaseQuestion question, List <SpeedTouchAnswerInfo> answer, ColorEnum randomColor, SpeedTouch questionType) { ColorEnum color = GetColorBasedOnAnswerOrSpriteID(IDType.AnswerID, CurrentColorID); switch (questionType) { case SpeedTouch.OneX: question.Question = "Touch the " + color.ToString() + " balloon."; for (int i = 0; i < question.Options.Count; i++) { question.Options[i].IsCorrect = (CurrentColorID == answer[i].AnswerID) ? true : false; question.Options[i].ID = answer[i].AnswerID; question.Options[i].Sprite = answer[i].SpriteID; } break; case SpeedTouch.ExceptX: question.Question = "Touch any balloon except the " + color.ToString() + " balloon."; for (int i = 0; i < question.Options.Count; i++) { question.Options[i].IsCorrect = (CurrentColorID == answer[i].AnswerID) ? false : true; question.Options[i].ID = answer[i].AnswerID; question.Options[i].Sprite = answer[i].SpriteID; } break; case SpeedTouch.AnyX: question.Question = "Touch any " + color.ToString() + " balloon."; int secondColorPos = -1; int firstColorPos = -1; for (int i = 0; i < question.Options.Count; i++) { question.Options[i].ID = answer[i].AnswerID; question.Options[i].Sprite = answer[i].SpriteID; Debug.Log("Answer Image = " + question.Options[i].Sprite.ToString()); if (answer[i].AnswerID == CurrentColorID) { firstColorPos = i; } question.Options[i].IsCorrect = (CurrentColorID == answer[i].AnswerID) ? true : false; } secondColorPos = Random.Range(0, question.Options.Count); while (secondColorPos == firstColorPos) { secondColorPos = Random.Range(0, question.Options.Count); } question.Options[secondColorPos].ID = CurrentColorID; question.Options[secondColorPos].Sprite = GetSpriteIDBasedOnAnswerID(CurrentColorID); question.Options[secondColorPos].IsCorrect = true; break; case SpeedTouch.LeftX: question.Question = "Touch the balloon on the left of the " + color.ToString() + " balloon."; int randomLeftx = Random.Range(0, 10); randomLeftx = (randomLeftx % 2 == 0) ? 1 : 3; Debug.Log("randomLeftx = " + randomLeftx); CheckAndRearrangeAnswers(answer, randomLeftx); for (int i = 0; i < question.Options.Count; i++) { question.Options[i].ID = answer[i].AnswerID; question.Options[i].Sprite = answer[i].SpriteID; question.Options[i].IsCorrect = (i + 1 == randomLeftx) ? true : false; } break; case SpeedTouch.RightX: question.Question = "Touch the balloon on the right of the " + color.ToString() + " balloon."; int randomRightX = Random.Range(0, 2); randomRightX = (randomRightX == 1) ? 0 : 2; CheckAndRearrangeAnswers(answer, randomRightX); for (int i = 0; i < question.Options.Count; i++) { question.Options[i].ID = answer[i].AnswerID; question.Options[i].Sprite = answer[i].SpriteID; question.Options[i].IsCorrect = (i - 1 == randomRightX) ? true : false; } break; case SpeedTouch.AboveX: question.Question = "Touch the balloon above the " + color.ToString() + " balloon."; int randomAboveX = Random.Range(0, 2); randomAboveX = (randomAboveX == 1) ? 2 : 3; CheckAndRearrangeAnswers(answer, randomAboveX); for (int i = 0; i < question.Options.Count; i++) { question.Options[i].ID = answer[i].AnswerID; question.Options[i].Sprite = answer[i].SpriteID; question.Options[i].IsCorrect = (i + 2 == randomAboveX) ? true : false; Debug.Log("Answer Image = " + question.Options[i].Sprite.ToString()); } break; case SpeedTouch.BelowX: question.Question = "Touch the balloon below the " + color.ToString() + " balloon."; int randomBelowX = Random.Range(0, 2); randomBelowX = (randomBelowX == 1) ? 0 : 1; CheckAndRearrangeAnswers(answer, randomBelowX); for (int i = 0; i < question.Options.Count; i++) { question.Options[i].ID = answer[i].AnswerID; question.Options[i].Sprite = answer[i].SpriteID; question.Options[i].IsCorrect = (i - 2 == randomBelowX) ? true : false; Debug.Log("Answer Image = " + question.Options[i].Sprite.ToString()); } break; } }