Exemplo n.º 1
0
        private void CreateGrid()
        {
            //xml ontcijferen
            Field[,] Fields = new Field[columns, rows];
            int countrow = 0, countcolumn = 0;

            foreach (XmlNode node in xmldoc.SelectNodes("spel/map/row"))
            {
                string tempRow = node.SelectSingleNode("short").InnerText;

                string[] tempFields = tempRow.Split(';');
                foreach (string tempField in tempFields)
                {
                    Field temp = null;
                    switch (tempField)
                    {
                    case " ":
                        temp = null;
                        break;

                    case "F":
                        temp = new NormalField();
                        break;

                    case "W-r":
                        temp = new WaitingField(players[(int)PlayerColor.Red]);
                        temp.AddPin(new Pin(players[(int)PlayerColor.Red], temp));
                        players[(int)PlayerColor.Red].AddPin(temp.Pin);
                        break;

                    case "W-b":
                        temp = new WaitingField(players[(int)PlayerColor.Blue]);
                        temp.AddPin(new Pin(players[(int)PlayerColor.Blue], temp));
                        players[(int)PlayerColor.Blue].AddPin(temp.Pin);
                        break;

                    case "W-g":
                        temp = new WaitingField(players[(int)PlayerColor.Green]);
                        temp.AddPin(new Pin(players[(int)PlayerColor.Green], temp));
                        players[(int)PlayerColor.Green].AddPin(temp.Pin);
                        break;

                    case "W-e":
                        temp = new WaitingField(players[(int)PlayerColor.Yellow]);
                        temp.AddPin(new Pin(players[(int)PlayerColor.Yellow], temp));
                        players[(int)PlayerColor.Yellow].AddPin(temp.Pin);
                        break;

                    case "F-r":
                        temp = new FinishField(players[(int)PlayerColor.Red]);
                        break;

                    case "F-b":
                        temp = new FinishField(players[(int)PlayerColor.Blue]);
                        break;

                    case "F-g":
                        temp = new FinishField(players[(int)PlayerColor.Green]);
                        break;

                    case "F-e":
                        temp = new FinishField(players[(int)PlayerColor.Yellow]);
                        break;

                    case "F-F-b":
                        temp = new ExitField(players[(int)PlayerColor.Blue]);
                        break;

                    case "F-F-g":
                        temp = new ExitField(players[(int)PlayerColor.Green]);
                        break;

                    case "F-F-r":
                        temp = new ExitField(players[(int)PlayerColor.Red]);
                        break;

                    case "F-F-e":
                        temp = new ExitField(players[(int)PlayerColor.Yellow]);
                        break;

                    case "F-S-b":
                        temp = new StartField(players[(int)PlayerColor.Blue]);
                        players[(int)PlayerColor.Blue].StartField = temp;
                        break;

                    case "F-S-g":
                        temp = new StartField(players[(int)PlayerColor.Yellow]);
                        players[(int)PlayerColor.Green].StartField = temp;
                        break;

                    case "F-S-r":
                        temp = new StartField(players[(int)PlayerColor.Red]);
                        players[(int)PlayerColor.Red].StartField = temp;
                        break;

                    case "F-S-e":
                        temp = new StartField(players[(int)PlayerColor.Yellow]);
                        players[(int)PlayerColor.Yellow].StartField = temp;
                        break;

                    case "|":
                        temp = new WalkingPath("Vertical", "");
                        break;

                    case "-":
                        temp = new WalkingPath("Horizontal", "");
                        break;

                    case "\\":
                        temp = new WalkingPath("Vertical", "Block");
                        break;

                    case "/":
                        temp = new WalkingPath("Horizontal", "Block");
                        break;
                    }
                    if (Fields != null)
                    {
                        Fields[countrow, countcolumn] = temp;
                    }
                    countcolumn++;
                }
                countcolumn = 0;
                countrow++;
            }

            //koppelen van de velden.
            Field  firstField;
            Field  lastField;
            string position = "";
            string dotted   = "";

            //eerste veld opsporen
            for (int y = 0; y < columns; y++)
            {
                for (int x = 0; x < rows; x++)
                {
                    if (Fields[x, y] != null)
                    {
                        if (Fields[x, y].GetType() == typeof(WalkingPath))
                        {
                            switch (Fields[x, y].direction)
                            {
                            case "Vertical":
                                firstField = Fields[x - 1, y];
                                lastField  = Fields[x + 1, y];
                                position   = "Vertical";
                                dotted     = Fields[x, y].dotted;
                                break;

                            case "Horizontal":
                                firstField = Fields[x, y - 1];
                                lastField  = Fields[x, y + 1];
                                position   = "Horizontal";
                                dotted     = Fields[x, y].dotted;
                                break;
                            }

                            if (position.Equals("Vertical"))
                            {
                                if ((columns) / 2 < y)
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }
                                    else
                                    {
                                        //firstField.SetNext(lastField);
                                    }
                                }
                                else
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }

                                    /*else if (firstField.FieldName == "ExitField" && lastField.FieldName == "FinishField")
                                     * {
                                     *  ((ExitField)firstField).Exit = lastField;
                                     * }
                                     * else if (firstField.FieldName == "FinishField" && lastField.FieldName == "ExitField")
                                     * {
                                     *  ((ExitField)lastField).Exit = firstField;
                                     * }*/
                                    else
                                    {
                                        //lastField.SetNext(firstField);
                                    }
                                }
                            }
                            else
                            {
                                if ((rows) / 2 < x)
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }
                                    else
                                    {
                                        //lastField.SetNext(firstField);
                                    }
                                }
                                else
                                {
                                    if (dotted.Equals("Block")) // finish field
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }

                                    /*else if (lastField.FieldName == "ExitField" && firstField.FieldName == "FinishField")
                                     * {
                                     *  ((ExitField)lastField).Exit = firstField;
                                     * }
                                     * else if (firstField.FieldName == "ExitField" && lastField.FieldName == "FinishField")
                                     * {
                                     *  ((ExitField)firstField).Exit = lastField;
                                     * }*/
                                    else
                                    {
                                        //firstField.SetNext(lastField);
                                    }
                                }
                            }
                        }
                        else if (Fields[x, y].GetType() == typeof(WaitingField))
                        {
                            foreach (Player p in players)
                            {
                                if (Fields[x, y].Player == p)
                                {
                                    Fields[x, y].SetNext(p.StartField);
                                }
                            }
                        }
                    }
                }
            }

            //grid tekenen
            int        cellBig = 40, cellSmall = 28;
            GridLength CellSizeBig   = new GridLength(cellBig);
            GridLength CellSizeSmall = new GridLength(cellSmall);

            for (int x = 0; x < rows; x++)
            {
                ColumnDefinition colDef = new ColumnDefinition();
                if (x % 2 == 0)
                {
                    colDef.Width = CellSizeBig;
                }
                else
                {
                    colDef.Width = CellSizeSmall;
                }
                FieldGrid.ColumnDefinitions.Add(colDef);
            }

            for (int y = 0; y < columns; y++)
            {
                RowDefinition rowDef = new RowDefinition();
                if (y % 2 == 0)
                {
                    rowDef.Height = CellSizeBig;
                }
                else
                {
                    rowDef.Height = CellSizeSmall;
                }
                FieldGrid.RowDefinitions.Add(rowDef);
            }

            //Grid koppelen
            for (int y = 0; y < columns; y++)
            {
                for (int x = 0; x < rows; x++)
                {
                    if (Fields[y, x] != null)
                    {
                        if (Fields[y, x].GetType() == typeof(WalkingPath))
                        {
                            Image smallpic = new Image();

                            smallpic.Height = cellSmall;
                            smallpic.Width  = cellSmall;

                            smallpic.SetValue(Grid.RowProperty, y);
                            smallpic.SetValue(Grid.ColumnProperty, x);

                            //Fields[y, x].SetImage(smallpic);
                            FieldGrid.Children.Add(smallpic);
                        }
                        else
                        {
                            RoundButton button = new RoundButton(Fields[y, x], vm);

                            button.SetValue(Grid.RowProperty, y);
                            button.SetValue(Grid.ColumnProperty, x);

                            //Fields[y, x].SetButton(button);
                            FieldGrid.Children.Add(button);
                        }
                    }
                }
            }

            // grid kleuren
            foreach (Field fieldd in Fields)
            {
                //if(fieldd != null) fieldd.setButtonColor();
            }
        }
Exemplo n.º 2
0
        private void CreateGrid()
        {
            //xml ontcijferen
            Field[,] Fields = new Field[columns, rows];
            int countrow = 0, countcolumn = 0;

            foreach (XmlNode node in xmldoc.SelectNodes("spel/map/row")) 
            {

                string tempRow = node.SelectSingleNode("short").InnerText;
                
                string[] tempFields = tempRow.Split(';');
                foreach (string tempField in tempFields)
                {
                    Field temp = null;
                    switch (tempField) 
                    {
                        case " ":
                            temp = null;
                            break;
                        case "F":
                            temp = new NormalField();
                            break;
                        case "W-r":
                            temp = new WaitingField(players[(int)PlayerColor.Red]);
                            temp.AddPin(new Pin(players[(int)PlayerColor.Red], temp));
                            players[(int)PlayerColor.Red].AddPin(temp.Pin);
                            break;
                        case "W-b":
                            temp = new WaitingField(players[(int)PlayerColor.Blue]);
                            temp.AddPin(new Pin(players[(int)PlayerColor.Blue],temp));
                            players[(int)PlayerColor.Blue].AddPin(temp.Pin);
                            break;
                        case "W-g":
                            temp = new WaitingField(players[(int)PlayerColor.Green]);
                            temp.AddPin(new Pin(players[(int)PlayerColor.Green], temp));
                            players[(int)PlayerColor.Green].AddPin(temp.Pin);
                            break;
                        case "W-e":
                            temp = new WaitingField(players[(int)PlayerColor.Yellow]);
                            temp.AddPin(new Pin(players[(int)PlayerColor.Yellow], temp));
                            players[(int)PlayerColor.Yellow].AddPin(temp.Pin);
                            break;
                        case "F-r":
                            temp = new FinishField(players[(int)PlayerColor.Red]);
                            break;
                        case "F-b":
                            temp = new FinishField(players[(int)PlayerColor.Blue]);
                            break;
                        case "F-g":
                            temp = new FinishField(players[(int)PlayerColor.Green]);
                            break;
                        case "F-e":
                            temp = new FinishField(players[(int)PlayerColor.Yellow]);
                            break;
                        case "F-F-b":
                            temp = new ExitField(players[(int)PlayerColor.Blue]);
                            break;
                        case "F-F-g":
                            temp = new ExitField(players[(int)PlayerColor.Green]);
                            break;
                        case "F-F-r":
                            temp = new ExitField(players[(int)PlayerColor.Red]);
                            break;
                        case "F-F-e":
                            temp = new ExitField(players[(int)PlayerColor.Yellow]);
                            break;
                        case "F-S-b":
                            temp = new StartField(players[(int)PlayerColor.Blue]);
                            players[(int)PlayerColor.Blue].StartField = temp;
                            break;
                        case "F-S-g":
                            temp = new StartField(players[(int)PlayerColor.Yellow]);
                            players[(int)PlayerColor.Green].StartField = temp;
                            break;
                        case "F-S-r":
                            temp = new StartField(players[(int)PlayerColor.Red]);
                            players[(int)PlayerColor.Red].StartField = temp;
                            break;
                        case "F-S-e":
                            temp = new StartField(players[(int)PlayerColor.Yellow]);
                            players[(int)PlayerColor.Yellow].StartField = temp;
                            break;
                        case "|":
                            temp = new WalkingPath("Vertical", "");
                            break;
                        case "-":
                            temp = new WalkingPath("Horizontal", "");
                            break;
                        case "\\":
                            temp = new WalkingPath("Vertical", "Block");
                            break;
                        case "/":
                            temp = new WalkingPath("Horizontal", "Block");
                            break;

                    }
                    if (Fields != null) Fields[countrow, countcolumn] = temp;
                    countcolumn++;
                }
                countcolumn = 0;
                countrow++;
            }

            //koppelen van de velden.
            Field firstField;
            Field lastField;
            string position = "";
            string dotted = "";

            //eerste veld opsporen
            for (int y = 0; y < columns; y++)
            {
                for (int x = 0; x < rows; x++)
                {
                    if (Fields[x, y] != null)
                    {
                        if (Fields[x, y].GetType() == typeof(WalkingPath))
                        {
                            switch (Fields[x, y].direction)
                            {
                                case "Vertical":
                                    firstField = Fields[x - 1, y];
                                    lastField = Fields[x + 1, y];
                                    position = "Vertical";
                                    dotted = Fields[x, y].dotted;
                                    break;
                                case "Horizontal":
                                    firstField = Fields[x, y - 1];
                                    lastField = Fields[x, y + 1];
                                    position = "Horizontal";
                                    dotted = Fields[x, y].dotted;
                                    break;
                            }

                            if (position.Equals("Vertical"))
                            {
                                if ((columns) / 2 < y)
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }
                                    else
                                    {
                                        //firstField.SetNext(lastField);
                                    }
                                }
                                else
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }
                                    /*else if (firstField.FieldName == "ExitField" && lastField.FieldName == "FinishField")
                                    {
                                        ((ExitField)firstField).Exit = lastField;
                                    }
                                    else if (firstField.FieldName == "FinishField" && lastField.FieldName == "ExitField")
                                    {
                                        ((ExitField)lastField).Exit = firstField;
                                    }*/
                                    else
                                    {
                                        //lastField.SetNext(firstField);
                                    }
                                }
                            }
                            else
                            {
                                if ((rows) / 2 < x)
                                {
                                    if (dotted.Equals("Block")) // finish field, moet heen terug
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }
                                    else
                                    {
                                        //lastField.SetNext(firstField);
                                    }
                                }
                                else
                                {
                                    if (dotted.Equals("Block")) // finish field
                                    {
                                        //firstField.SetNext(lastField);
                                        //((FinishField)lastField).SetPrevious(firstField);
                                    }
                                    /*else if (lastField.FieldName == "ExitField" && firstField.FieldName == "FinishField")
                                    {
                                        ((ExitField)lastField).Exit = firstField;
                                    }
                                    else if (firstField.FieldName == "ExitField" && lastField.FieldName == "FinishField")
                                    {
                                        ((ExitField)firstField).Exit = lastField;
                                    }*/
                                    else
                                    {
                                        //firstField.SetNext(lastField);
                                    }
                                }
                            }
                        }
                        else if (Fields[x, y].GetType() == typeof(WaitingField))
                        {
                            foreach (Player p in players)
                            {
                                if (Fields[x,y].Player == p)
                                {
                                    Fields[x, y].SetNext(p.StartField);
                                }
                            }

                        }
                    }
                }
            }

            //grid tekenen
            int cellBig = 40, cellSmall = 28;
            GridLength CellSizeBig = new GridLength(cellBig);
            GridLength CellSizeSmall = new GridLength(cellSmall);

            for (int x = 0; x < rows; x++)
            {
                ColumnDefinition colDef = new ColumnDefinition();
                if (x % 2 == 0)
                {
                    colDef.Width = CellSizeBig;
                }
                else
                {
                    colDef.Width = CellSizeSmall;
                }
                FieldGrid.ColumnDefinitions.Add(colDef);
            }

            for (int y = 0; y < columns; y++)
            {
                RowDefinition rowDef = new RowDefinition();
                if (y % 2 == 0)
                {
                    rowDef.Height = CellSizeBig;
                }
                else
                {
                    rowDef.Height = CellSizeSmall;
                }
                FieldGrid.RowDefinitions.Add(rowDef);
            }

            //Grid koppelen
            for (int y = 0; y < columns; y++)
            {
                for (int x = 0; x < rows; x++)
                {
                    if (Fields[y, x] != null)
                    {
                        if(Fields[y, x].GetType() == typeof(WalkingPath))
                        {
                            Image smallpic = new Image();

                            smallpic.Height = cellSmall;
                            smallpic.Width = cellSmall;

                            smallpic.SetValue(Grid.RowProperty, y);
                            smallpic.SetValue(Grid.ColumnProperty, x);

                            //Fields[y, x].SetImage(smallpic);
                            FieldGrid.Children.Add(smallpic);
                        }
                        else
                        {
                            RoundButton button = new RoundButton(Fields[y, x], vm);

                            button.SetValue(Grid.RowProperty, y);
                            button.SetValue(Grid.ColumnProperty, x);

                            //Fields[y, x].SetButton(button);
                            FieldGrid.Children.Add(button);
                        }
                     }
                }
            }

            // grid kleuren
            foreach(Field fieldd in Fields)
            {
                //if(fieldd != null) fieldd.setButtonColor();
            }
        }