Exemple #1
0
 /// <summary>Zwróć piona  dla podanego koloru</summary>
 /// <param name="pc">Kolor</param>
 /// <returns>Pion w danym kolorze</returns>
 public static PawnType GetPawnByColor(PawnColor pc)
 {
     if (pc == PawnColor.Black)
         return PawnType.BlackPawn;
     if (pc == PawnColor.White)
         return PawnType.WhitePawn;
     return PawnType.None;
 }
Exemple #2
0
 /// <summary>Określ kolor przeciwnika dla podanego koloru</summary>
 /// <param name="pc">Kolor</param>
 /// <returns>Kolor przeciwnika</returns>
 public static PawnColor GetOpponentColor(PawnColor pc)
 {
     if (pc == PawnColor.Black)
         return PawnColor.White;
     if (pc == PawnColor.White)
         return PawnColor.Black;
     return PawnColor.None;
 }
Exemple #3
0
        /// <summary>
        /// Porównanie dwóch pionów ze względu na ich kolor (z pominięciem typu)
        /// </summary>
        public static bool EqualColor(PawnColor pc, PawnType pt)
        {
            if (pc == PawnColor.Black && (pt == PawnType.BlackPawn || pt == PawnType.BlackQueen))
                return true;
            if (pc == PawnColor.White && (pt == PawnType.WhitePawn || pt == PawnType.WhiteQueen))
                return true;

            return false;
        }
Exemple #4
0
        public void NewGame(PawnColor cpu_color, IBoard board)
        {
            /*
                TODO: Kod startowy nowej gry
                Kod uruchamiany jest każdorazowo podczas rozpoczynania nowej gry.
             */

            this.plansza = board;
        }
Exemple #5
0
 public Pawn(PawnColor color, PawnType type)
     : base("MasterMindPawn")
 {
     _effect = new Particle.ParticleSystem("light");
     _effect.SetLifeTime(10, 20);
     _effect.SetParent(this.EntityId);
     _effect.SetSize(0.2f, 0.2f);
     _effect.SetSpread(Helpers.PhysicsAndPositions.PI * 2);
     _effect.SetRandomSpeed(true, 0.05f);
     SetPawnColor(color);
     SetPawnType(type);
     SetTexture("pawn");
     Selected = false;
 }
        public MainWindow()
        {
            InitializeComponent();
            this.Text = this.Text + " - Wersja " + Application.ProductVersion.ToString();
            this.random = new Random();
            this.dbg = new DebugWindow();
            this.btnShowDebugWindow_Click(null, null);

            this.pawn_matrix = new PawnType[8, 8];
            this.field_matrix = new Label[8, 8];
            this.selected_color_matrix = new Color[8, 8];
            this.normal_color_matrix = new Color[8, 8];

            this.selected_field = PointExt.Invalid;

            for (int r = 0; r < 8; r++)
                for (int c = 0; c < 8; c++)
                {
                    string cname = string.Format("p{0}{1}", (char)('A' + r), 1 + c);
                    this.field_matrix[r, c] = this.panel1.Controls[cname] as Label;

                    this.normal_color_matrix[r, c] = (r + c) % 2 == 0 ? Color.White : Color.Silver;
                    this.selected_color_matrix[r, c] = (r + c) % 2 == 0 ? Color.FromArgb(255 - 50, 255, 255 - 50) : Color.FromArgb(192 - 50, 192, 192 - 50);

                    this.field_matrix[r, c].BackColor = this.normal_color_matrix[r, c];
                }

            this.current_turn = PawnColor.None;
            this.cpu_color = PawnColor.None;
            this.human_color = PawnColor.None;
            this.ShowGameState();

            // uruchomienie bota
            this.bot = new MojBot();
            this.lblBotAuthor.Text = this.bot.GetAuthor();
            this.lblBotDescription.Text = this.bot.GetDescripion();

            try
            {
                this.bot.Initialize();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Wyjątek podczas uruchamiania metody Bot.Initialize():\n{0}", ex.Message),
                    Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #7
0
        public static byte[] ConvertPawnColor(PawnColor color)
        {
            switch(color){
                case PawnColor.None:
                    return new byte[3] { 0, 0, 0 };
                    break;
                case PawnColor.Red:
                    return new byte[3] { 255, 0, 0 };
                    break;
                case PawnColor.Green:
                    return new byte[3] { 0, 255, 0 };
                    break;
                case PawnColor.Blue:
                    return new byte[3] { 0, 0 ,255};
                    break;
                case PawnColor.Orange:
                    return new byte[3] { 255, 100, 0 };
                    break;
                case PawnColor.Yellow:
                    return new byte[3] { 255, 255, 0 };
                    break;
                case PawnColor.Purple:
                    return new byte[3] { 255, 0, 255 };
                    break;
                case PawnColor.Brown:
                    return new byte[3] { 200, 110, 110 };
                    break;
                case PawnColor.Black:
                    return new byte[3] { 0, 0, 0 };
                    break;
                case PawnColor.White:
                    return new byte[3] { 255, 255, 255 };
                    break;
                default:
                    return new byte[3] { 0, 0, 0 };
                    break;

            }
        }
Exemple #8
0
 /// <summary>
 /// Porównanie dwóch pionów ze względu na ich kolor
 /// </summary>
 /// <param name="pc1">Kolor pionu pierwszego</param>
 /// <param name="pc2">Kolor pionu drugiego</param>
 /// <returns>Zwraca true jeśli kolory są zgodne</returns>
 static bool EqualColor(PawnColor pc1, PawnColor pc2)
 {
     return pc1 == pc2;
 }
Exemple #9
0
 public static bool IsNone(PawnColor pc)
 {
     return pc == PawnColor.None;
 }
Exemple #10
0
        private void EndTurn(bool new_game)
        {
            // test
            bool test = false;
            test |= move_count == 1 && capture_count == 0;  // był tylko ruch
            test |= move_count == 0 && capture_count >= 1;  // było jedno lub więcej bić
            test |= !(move_count > 0 && move_count > 0);    // niemozliwe: ruch i bicie
            Debug.Assert(test);

            if (new_game)
            {
                // przygotowania do nowej gry
                this.current_turn = PawnColor.White;
                this.white_score = 0;
                this.black_score = 0;
            }
            else
            {
                // zakończenie kolejnej tury w ramach danej gry
                // jeśli pion przeciwnika jest na pierwszym polu (najbliżej gracza) to awansuj go na damę
                foreach (PawnColor pc in new PawnColor[] { PawnColor.Black, PawnColor.White })
                    for (int c = 0; c < 8; c++)
                    {
                        Point p = PointExt.Invalid;
                        if (pc == PawnColor.Black)
                            p = new Point(c, 0);
                        else
                            p = new Point(c, 7);

                        bool coronation = false;
                        if (Pawn.GetColor(this.GetPawn(p)) == pc && Pawn.IsNormalPawn(this.GetPawn(p)))
                        {
                            this.InternalSetPawn(p, Pawn.GetQueenByColor(pc));
                            coronation = true;
                        }
                        if (coronation)
                            AddPlayerLog(string.Format("Koronacja na {0}", Pawn.PointToFieldAddress(p)));
                    }

                // podlicz punkty
                int points = 0;
                if (this.move_count == 0 && this.capture_count == 0)
                {
                    // człowiek lub bot nie wykonali żadnego ruchu - poddali ruch
                    points = -1;
                }
                else
                {
                    if (this.capture_count == 1) // jedno bicie
                        points += 2;
                    if (this.capture_count > 1) // wiele bić :)
                        points += 5 * this.capture_count;
                }

                if (this.current_turn == PawnColor.Black)
                    this.black_score += points;
                else
                    this.white_score += points;

                // zmiana tury
                this.current_turn = this.current_turn == PawnColor.Black ? PawnColor.White : PawnColor.Black;
            }

            this.capture_count = 0;
            this.move_count = 0;

            this.DeselectPawn();
            this.ShowGameState();
        }
Exemple #11
0
 public void SetPawnColor(PawnColor color)
 {
     _pawnColor = color;
     SetColor(ConvertPawnColor(color));
     _effect.SetColor(ConvertPawnColor(color));
 }
Exemple #12
0
 private bool isPawnColorInArray(List<PawnColor> array, PawnColor value)
 {
     foreach(PawnColor pc in array){
         if(pc.Equals(value)){
             return true;
         }
     }
     return false;
 }