예제 #1
0
 private void WriteLog(MoveResult moveresult)
 {
     this.txtLog.AppendText(string.Format("{0} {1}", moveresult.MoveResultStatus.ToString(), moveresult.ResultMessage));
     this.txtLog.AppendText(System.Environment.NewLine);
 }
예제 #2
0
        public static MoveResult isMoveAllowed(Hexagon fromhex, Hexagon tohex,int jumpup,int jumpdown)
        {
            MoveResult result = new MoveResult(MoveResult.eMoveResult.DNE, "");
            bool isBorder = false;
            string notallowed = "";
            string isalllowed = "";
            if (fromhex == null)
            {
                result.MoveResultStatus = MoveResult.eMoveResult.Success;
                result.ResultMessage = "First move.";
            }
            else
            {
                notallowed = string.Format("Move from height {0} to {1} is NOT allowed!", fromhex.Height.ToString(), tohex.Height.ToString());
                isalllowed = string.Format("Move from height {0} to {1} is allowed.", fromhex.Height.ToString(), tohex.Height.ToString());
                foreach (var hs in fromhex.HexSides)
                {
                    if (tohex.HexSides.Contains(hs))
                    {
                        isBorder = true;
                        break;
                    }
                }
                if (isBorder)
                {
                    if (fromhex.Height == tohex.Height)
                    {
                        result.MoveResultStatus = MoveResult.eMoveResult.Success;
                        result.ResultMessage = isalllowed;
                    }
                    if (fromhex.Height < tohex.Height)
                    {
                        if (fromhex.Height + jumpup >= tohex.Height)
                        {
                            result.MoveResultStatus = MoveResult.eMoveResult.Success;
                            result.ResultMessage = isalllowed;

                        }
                        else
                        {
                            result.MoveResultStatus = MoveResult.eMoveResult.TooLow;
                            result.ResultMessage = notallowed;
                        }
                    }
                    if (fromhex.Height > tohex.Height)
                    {
                        if (fromhex.Height - tohex.Height <= jumpdown)
                        {
                            result.MoveResultStatus = MoveResult.eMoveResult.Success;
                            result.ResultMessage = isalllowed;
                        }
                        else
                        {
                            result.MoveResultStatus = MoveResult.eMoveResult.TooHigh;
                            result.ResultMessage = notallowed;
                        }
                    }
                }
            }

            return result;
        }
예제 #3
0
        public MoveResult TryMove(HexUtils.eMoveDirection direction, Robot robot)
        {
            MoveResult result = new MoveResult(MoveResult.eMoveResult.DNE, "");

            Hexagon targethex = GetAdjacentHexagon(robot.CurrentHexagon, direction);

            if (targethex != null)
            {
                result = HexUtils.isMoveAllowed(robot.CurrentHexagon, targethex, robot.UpJump, robot.DownJump);

                if (result.MoveResultStatus == MoveResult.eMoveResult.Success)
                {
                    robot.SetCurrentHexagon(targethex);
                    if (targethex.NE.Y == toprowy)
                    {
                        result.MoveResultStatus = MoveResult.eMoveResult.Complete;
                        result.ResultMessage = string.Format("The robot {0} made it across!", robot.SerialNumber.ToString());
                    }
                }
            }
            return result;
        }
예제 #4
0
 public MoveResult TryMove(HexUtils.eMoveDirection direction, int index)
 {
     MoveResult result = new MoveResult(MoveResult.eMoveResult.DNE, "");
     result = TryMove(direction, this.Robots[index]);
     return result;
 }
예제 #5
0
파일: frmMain.cs 프로젝트: NoGoAway/Hexbot
        private void pboxMain_MouseDown(object sender, MouseEventArgs e)
        {
            var h1 = (from hx in hexagons
                      where hx.Selected
                      select hx).FirstOrDefault();
            HexPoint hp = new HexPoint(e.X, e.Y);
            hexagons.ForEach(h => h.Selected = false);
            var hex = (from h in hexagons
                       where h.NW.X <= e.X && h.NE.X >= e.X
                       && h.NW.Y <= e.Y && h.SW.Y >= e.Y
                       select h).FirstOrDefault();
            MoveResult moveresult = new MoveResult(MoveResult.eMoveResult.DNE, "");

            if (hex != null)
            {
                moveresult = HexUtils.isMoveAllowed(h1, hex,jumpup,jumpdown);
                if (moveresult.MoveResultStatus== MoveResult.eMoveResult.Success)
                {
                    if (h1 != null)
                    {
                        h1.Selected = false;
                    }
                    hex.Selected = true;
                }
                else
                {
                    if (h1 != null)
                    {
                        h1.Selected = true;
                        hex.Selected = false;
                    }
                }

            }

            WriteLog(moveresult);

            this.Refresh();
        }
예제 #6
0
 public void OnTryMoveComplete(MoveResult mresult, Hexagon newhex)
 {
     if (mresult.MoveResultStatus == MoveResult.eMoveResult.Success)
     {
         this.CurrentHexagon = newhex;
         InitiateLookAround();
     }
     else
     {
         CycleThroughMoves();
     }
 }
예제 #7
0
 public void OnMoveComplete(MoveResult mresult)
 {
     if (mresult.MoveResultStatus != MoveResult.eMoveResult.Success)
     {
         CycleThroughMoves();
     }
 }