Beispiel #1
0
 private bool cekGerakanRat(Box second, Dictionary <string, Box> around)
 {
     if (around.ContainsValue(second))
     {
         if (first.isWater == second.isWater)
         {
             if (second.animal == null || ((second.animal.strength == 0 || second.animal.strength == 7) && second.animal.player != first.animal.player))
             {
                 second.removeAnimal();
                 second.animal          = clicked;
                 clicked                = null;
                 first.animal           = null;
                 second.animal.position = CoordsOf(papan, second).ToValueTuple();
                 return(true);
             }
         }
         else
         {
             if (second.animal == null)
             {
                 second.removeAnimal();
                 second.animal          = clicked;
                 clicked                = null;
                 first.animal           = null;
                 second.animal.position = CoordsOf(papan, second).ToValueTuple();
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #2
0
 private bool cekGerakanHewanBiasa(Box second, Dictionary <string, Box> around)
 {
     if (around.ContainsValue(second))
     {
         if (!second.isWater)
         {
             if (second.animal == null || (second.animal.strength <= first.animal.strength && second.animal.player != first.animal.player))
             {
                 second.removeAnimal();
                 second.animal          = clicked;
                 second.animal.position = CoordsOf(papan, second).ToValueTuple();
                 clicked      = null;
                 first.animal = null;
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #3
0
        private void panelGame_MouseClick(object sender, MouseEventArgs e)
        {
            int cX = -1, cY = -1;

            for (int y = 0; y < 9; y++)
            {
                for (int x = 0; x < 7; x++)
                {
                    Rectangle temp = displayed[x, y];
                    if (temp.Contains(e.Location))
                    {
                        cX = x; cY = y; break;
                    }
                }
            }

            if (cX == -1 || cY == -1)
            {
                clicked = null;
            }
            else
            {
                if (clicked != null)
                {
                    Box second = papan[cX, cY];
                    if (second.isDen && second.denOwner == other.giliran)
                    {
                    }
                    else
                    {
                        Tuple <int, int>         coordFirst = CoordsOf(papan, first);
                        Dictionary <string, Box> around     = AmbilSekeliling(coordFirst.Item1, coordFirst.Item2);
                        switch (clicked.strength)
                        {
                        case 0:
                            if (cekGerakanRat(second, around))
                            {
                                gantiGiliran(sender, e);
                            }
                            break;

                        case 1:
                        case 2:
                        case 3:
                        case 4:
                            if (cekGerakanHewanBiasa(second, around))
                            {
                                gantiGiliran(sender, e);
                            }
                            break;

                        case 5:
                        case 6:
                            if (around.ContainsValue(second))
                            {
                                if (!second.isWater)
                                {
                                    if (second.animal == null || (second.animal.strength <= first.animal.strength && second.animal.player != first.animal.player))
                                    {
                                        second.removeAnimal();
                                        second.animal          = clicked;
                                        clicked                = null;
                                        first.animal           = null;
                                        second.animal.position = CoordsOf(papan, second).ToValueTuple();
                                        gantiGiliran(sender, e);
                                    }
                                }
                                else
                                {
                                    string here = around.FirstOrDefault(item => item.Value == second).Key;
                                    switch (here)
                                    {
                                    case "atas":
                                        if (bisaNyebrangKeAtas(cX, cY, second))
                                        {
                                            first.animal = null;
                                            papan[cX, cY - 3].removeAnimal();
                                            papan[cX, cY - 3].animal = clicked;
                                            clicked.position         = (cX, cY - 3);
                                            clicked = null;
                                            gantiGiliran(sender, e);
                                        }
                                        break;

                                    case "bawah":
                                        if (bisaNyebrangKeBawah(cX, cY, second))
                                        {
                                            first.animal = null;
                                            papan[cX, cY + 3].removeAnimal();
                                            papan[cX, cY + 3].animal = clicked;
                                            clicked.position         = (cX, cY + 3);
                                            //MessageBox.Show(clicked.position.ToString());
                                            clicked = null;
                                            gantiGiliran(sender, e);
                                        }
                                        break;

                                    case "kiri":
                                        if (bisaNyebrangKeKiri(cX, cY, second))
                                        {
                                            first.animal = null;
                                            papan[cX - 2, cY].removeAnimal();
                                            papan[cX - 2, cY].animal          = clicked;
                                            papan[cX - 2, cY].animal.position = (cX - 2, cY);
                                            clicked = null;
                                            gantiGiliran(sender, e);
                                        }
                                        break;

                                    case "kanan":
                                        if (bisaNyebrangKeKanan(cX, cY, second))
                                        {
                                            first.animal = null;
                                            papan[cX + 2, cY].removeAnimal();
                                            papan[cX + 2, cY].animal          = clicked;
                                            papan[cX + 2, cY].animal.position = (cX + 2, cY);
                                            //MessageBox.Show(clicked.position.ToString());
                                            clicked = null;
                                            gantiGiliran(sender, e);
                                        }
                                        break;
                                    }
                                }
                            }
                            break;

                        case 7:
                            if (around.ContainsValue(second) && !second.isWater && (second.animal == null || (second.animal.strength <= first.animal.strength && second.animal.player != first.animal.player && second.animal.strength != 0)))
                            {
                                second.removeAnimal();
                                second.animal          = clicked;
                                clicked                = null;
                                first.animal           = null;
                                second.animal.position = CoordsOf(papan, second).ToValueTuple();
                                gantiGiliran(sender, e);
                            }
                            break;
                        }
                        displayPapan();
                    }
                }
                else if (papan[cX, cY].animal != null && papan[cX, cY].animal.player == giliran)
                {
                    AmbilAnimal(cX, cY);
                }
                Console.WriteLine(papan[cX, cY].ToString());
                if (papan[cX, cY].animal != null)
                {
                    Console.Write("POSISI TERSIMPAN HEWAN: ");
                    Console.WriteLine(papan[cX, cY].animal.position);
                    Console.WriteLine("INDEX PAPAN: " + (cX, cY));
                    Console.WriteLine(papan[cX, cY].animal.position == (cX, cY));
                }
            }
        }