Ejemplo n.º 1
0
        public void changer(Button clickedButton, ref Turns currentTurn)
        {
            int buttonID = int.Parse(clickedButton.Tag.ToString());

            //Zero-based row and column
            int row = buttonID / 3;
            int col = buttonID % 3;
            if (GameBoard[row][col] == State.N)
            {
                if (currentTurn == Turns.X)
                {
                    GameBoard[row][col] = State.X;
                    pGameBoard[row][col] = State.X;
                }
                else
                {
                    GameBoard[row][col] = State.O;
                    pGameBoard[row][col] = State.O;
                }
                clickedButton.Text = GameBoard[row][col].ToString();
                currentTurn++;
                turns++;
            }
            label2.Text = currentTurn.ToString();
        }
Ejemplo n.º 2
0
        // Draw factory
        public void Draw()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("Turns left: " + Turns.ToString());
            sb.Append(Environment.NewLine);
            for (int j = 1; j <= Height; j++)
            {
                for (int i = 1; i <= Width; i++)
                {
                    // Insert an M for the position of the mechanic
                    if (Mechanic.XPosition == i & Mechanic.YPosition == j)
                    {
                        sb.Append(" M ");
                    }
                    // Insert an R for the position of a robot
                    else if (RobotList.Any(robot => robot.XPosition == i & robot.YPosition == j & robot.Alive))
                    {
                        sb.Append(" R ");
                    }
                    // Insert a dot for every empty position
                    else
                    {
                        sb.Append(" . ");
                    }
                }
                sb.Append(Environment.NewLine);
            }

            Console.WriteLine(sb.ToString());
        }
Ejemplo n.º 3
0
        public void changer(Button clickedButton, ref Turns currentTurn)
        {
            int buttonID = int.Parse(clickedButton.Tag.ToString());

            //Zero-based row and column
            int row = buttonID / 3;
            int col = buttonID % 3;

            if (GameBoard[row][col] == State.N)
            {
                if (currentTurn == Turns.X)
                {
                    GameBoard[row][col]  = State.X;
                    pGameBoard[row][col] = State.X;
                }
                else
                {
                    GameBoard[row][col]  = State.O;
                    pGameBoard[row][col] = State.O;
                }
                clickedButton.Text = GameBoard[row][col].ToString();
                currentTurn++;
                turns++;
            }
            label2.Text = currentTurn.ToString();
        }
Ejemplo n.º 4
0
        //Method Run
        public void Run()
        {
            //In this method, all the methods from factory, robot and mechanic are used to run the application
            GameRulesExplanation();
            //Initialise the mechanic, and the list of robots
            Mechanic mechanic = new Mechanic();

            robotsPlacement = Robot.PlaceRobots(Width, Height, NrOfRobots);
            List <Robot> robotListNew = null;
            string       factoryEmpty = InitialiseEmptyFactoryGrid();                                 //Make the empty factory
            string       factoryGrid  = ShowMovementFactory(factoryEmpty, robotsPlacement, mechanic); //Make the initial factory

            Console.WriteLine(factoryGrid);                                                           //Show in console
            int initialTurn = Turns;                                                                  //Keep track of initial turns

            do                                                                                        //while (Turns > 0 & robotsPlacement.Count > 0)
            {
                //Show turns and get movement mechanic
                string NumberOfTurns = Turns.ToString();
                Console.WriteLine("Number of turns:" + NumberOfTurns);
                Console.Write("Give movement of the mechanic (w,a,s,d) ... ");
                string inputDirection = Console.ReadLine();

                //Replace the mechanic according to movement
                Mechanic.ReplaceMechanic(inputDirection, mechanic, Width, Height);

                //Als de boolean RobotsMove == true, dan bewegen de robots
                if (RobotsMove)
                {
                    for (int m = 0; m < inputDirection.Length; m++)
                    {
                        robotListNew = Robot.MoveAllRobots(NrOfRobots, robotsPlacement, Width, Height);
                    }
                }

                //Overwrite robotsPlacement with the new coordinates for the robots
                robotsPlacement = robotListNew;
                //If the mechanic and robot are on the same coordinate, remove the robot
                WhenMechanicAndRobotsTouch(mechanic, robotsPlacement);
                //Show the new grid
                string updatedGrid = ShowMovementFactory(factoryEmpty, robotsPlacement, mechanic);
                Console.WriteLine(updatedGrid);
                //Decrease turns with one
                Turns--;
            } while (Turns > 0 & robotsPlacement.Count > 0);

            //Messages for when the game is won or lost.
            if (Turns > 0 & robotsPlacement.Count == 0)
            {
                Console.WriteLine("Congratulations, you won the game in " + (initialTurn - Turns) + " turns");
                Console.ReadLine();
            }
            else if (Turns == 0 & robotsPlacement.Count > 0)
            {
                Console.WriteLine("Unfortunately, you lost the game after " + (initialTurn) + " turns");
                Console.ReadLine();
            }
        }
Ejemplo n.º 5
0
        protected virtual void DrawTruns(Graphics g, float extraX = 0, float extraY = 0, float extraWidth = 0, float extraHeight = 0)
        {
            TurnsImage.Draw(g, extraX, extraY, extraWidth, extraHeight);

            SizeF turnsStringSize = g.MeasureString("X " + Turns.ToString(), FontTurns);

            g.DrawString("X " + Turns.ToString(), new Font("David", 15, FontStyle.Bold), Brushes.White,
                         extraX + TurnsImage.Right, extraY + TurnsImage.Top + (TurnsImage.Height - turnsStringSize.Height) / 2 + 2);
        }
Ejemplo n.º 6
0
 public void turn(ref Turns currentTurn)
 {
     if (turns > 8)
     {
         MessageBox.Show("Tie!!!");
         initializer(GameBoard, pGameBoard);
     }
     if (currentTurn.ToString() == "2")
     {
         label2.Text = "X";
         currentTurn = 0;
     }
 }
Ejemplo n.º 7
0
    private void Start()
    {
        minRecord = 0;
        if (!PlayerPrefs.HasKey("MinRecord"))
        {
            PlayerPrefs.SetInt("MinRecord", minRecord);
        }
        minRecord = PlayerPrefs.GetInt("MinRecord");

        Turns           = 3;
        Scores          = 0;
        turnsText.text  = Turns.ToString();
        scoresText.text = Scores.ToString();
        AdsController.InitializeAdvertisment();
    }
Ejemplo n.º 8
0
        private void gameFinish(Turns winner)
        {
            isFinish = true;

            if (winner != Turns.P)
            {
                status = winner.ToString() + " Won";
                reloadBoard();
            }
            else
            {
                status = "Tied";
                reloadBoard();
            }
        }
Ejemplo n.º 9
0
 public void turn(ref Turns currentTurn)
 {
     if (turns > 8)
     {
         MessageBox.Show("Tie!!!");
         initializer(GameBoard,pGameBoard);
     }
     if (currentTurn.ToString() == "2")
     {
         label2.Text = "X";
         currentTurn = 0;
     }
 }
Ejemplo n.º 10
0
 public void MinusTurns()
 {
     Turns--;
     turnsText.text = Turns.ToString();
     CheckLose();
 }
Ejemplo n.º 11
0
 private void reloadBoard()
 {
     lb_turn.Text   = turn.ToString();
     lb_status.Text = status;
 }