Click here to Skip to main content
15,888,968 members
Home / Discussions / C#
   

C#

 
QuestionExecuting Powershell command from C# Pin
sudhi1641-Jul-15 4:15
sudhi1641-Jul-15 4:15 
AnswerRe: Executing Powershell command from C# Pin
phil.o1-Jul-15 5:57
professionalphil.o1-Jul-15 5:57 
QuestionDirectoryInfo.GetAccessControl() throws InvalidOperationException "Method failed with unexpected error code 1" Pin
Gerd Krause1-Jul-15 3:08
Gerd Krause1-Jul-15 3:08 
SuggestionRe: DirectoryInfo.GetAccessControl() throws InvalidOperationException "Method failed with unexpected error code 1" Pin
Richard Deeming1-Jul-15 7:46
mveRichard Deeming1-Jul-15 7:46 
GeneralRe: DirectoryInfo.GetAccessControl() throws InvalidOperationException "Method failed with unexpected error code 1" Pin
Gerd Krause1-Jul-15 23:21
Gerd Krause1-Jul-15 23:21 
QuestionHow i can pause/resume a thread in window form application ? Pin
Husnul karim30-Jun-15 20:59
Husnul karim30-Jun-15 20:59 
AnswerRe: How i can pause/resume a thread in window form application ? Pin
Pete O'Hanlon30-Jun-15 23:36
mvePete O'Hanlon30-Jun-15 23:36 
QuestionHow to check if pieces are ordered Pin
Aleksandar Jeftic30-Jun-15 11:22
Aleksandar Jeftic30-Jun-15 11:22 
picture 1

picture 2



I made method for checking if all pieces are in base or goal if yes it returns true,now i need another method.

If pieces are ordered like on Picture 1. i need to change number of throws to 3 ,if pieces are ordered like on Picture 2 i can allow only 1 throw cos of empty space between.

I got 4 goalPositions and 4 piecePositions,and need to check if pieces are ordered on them from 54-51 path positions(path is array of 55 fields 0-54) ,if yes return true if not return false.

I am new to C# never had chance to work with order checking till now.

I was trying to do it with 3 int lists goalPositions (populated with 51,52,53,54 path positions),piecePositions(populated with pieces positions with getPosition()),and piecesOnGoal. but no luck with that.

ill add some code. part of player class with that lists and method for checking pieces in goal or base

C#
class Player
    {
        protected PieceSet[] pieces;
        Color color;
        int numberOfThrows;
        Dice dice;
        public List<int> goalPositions;
        public List<int> piecePositions;
        public List<int> piecesOnGoal;

        public enum Color
        {
            Yellow, Green, Blue, Red
        }

        public Player(Color color)
        {
            int[] path = new int[55];
            this.color = color;
            dice = new Dice();
            numberOfThrows = 3;
            switch (color)
            {
                case Color.Yellow:
                    path = BoardHelper.getYellowPath();
                    break;
                case Color.Green:
                    path = BoardHelper.getGreenPath();
                    break;
                case Color.Blue:
                    path = BoardHelper.getBluePath();
                    break;
                case Color.Red:
                    path = BoardHelper.getRedPath();
                    break;
            }
            pieces = new PieceSet[4];
            pieces[0] = new PieceSet(path, 0);
            pieces[1] = new PieceSet(path, 1);
            pieces[2] = new PieceSet(path, 2);
            pieces[3] = new PieceSet(path, 3);

            piecePositions = new List<int>(4);
            piecePositions.Add(pieces[0].getPosition());
            piecePositions.Add(pieces[1].getPosition());
            piecePositions.Add(pieces[2].getPosition());
            piecePositions.Add(pieces[3].getPosition());

            goalPositions = new List<int>(4);
            goalPositions.Add(51);
            goalPositions.Add(52);
            goalPositions.Add(53);
            goalPositions.Add(54);
           
            piecesOnGoal= new list<int>();


           
        }

public bool isAllPiecesInBaseOrGoal()
        {
    if ((pieces[0].getPosition() < 4 || pieces[0].getPosition() > 50) &&
     (pieces[1].getPosition() < 4 || pieces[1].getPosition() > 50) &&
     (pieces[2].getPosition() < 4 || pieces[2].getPosition() > 50) &&
     (pieces[3].getPosition() < 4 || pieces[3].getPosition() > 50))
                return true;
            else
                return false;
        }


and this is how i was thinking to solve my problem ,check if goalPositions contains piecePositions if yes add that position into piecesOnGoal ...now i need somehow to check are that piecesOnGoal are ordered if yes return true if not false.

I am open for any suggestion.

C#
public bool isAllPiecesAreOrderedInGoal()
        {
            for (int i = 0; i < 4; i++)
            {
                if (goalPositions.Contains(piecePositions[i]))
                {
                    piecesOnGoal.Add(piecePositions[i]);
                }



            }
        }

Any help is appreciated.
Its kind of urgent.

Thank you in advance.
GeneralRe: How to check if pieces are ordered Pin
PIEBALDconsult30-Jun-15 11:25
mvePIEBALDconsult30-Jun-15 11:25 
GeneralRe: How to check if pieces are ordered Pin
Aleksandar Jeftic2-Jul-15 4:50
Aleksandar Jeftic2-Jul-15 4:50 
AnswerRe: How to check if pieces are ordered Pin
Freak3030-Jun-15 21:20
Freak3030-Jun-15 21:20 
QuestionHotSpot Management via ICS in C# Pin
spaika30-Jun-15 4:31
spaika30-Jun-15 4:31 
QuestionInsert Image in excel with transperancy enabled Pin
Member 1179983729-Jun-15 23:56
Member 1179983729-Jun-15 23:56 
AnswerRe: Insert Image in excel with transperancy enabled Pin
Richard Deeming30-Jun-15 1:02
mveRichard Deeming30-Jun-15 1:02 
QuestionRead/Write App Settings Not Working Pin
Kevin Marois29-Jun-15 9:16
professionalKevin Marois29-Jun-15 9:16 
AnswerRe: Read/Write App Settings Not Working Pin
Eddy Vluggen29-Jun-15 10:36
professionalEddy Vluggen29-Jun-15 10:36 
GeneralRe: Read/Write App Settings Not Working Pin
Kevin Marois29-Jun-15 11:23
professionalKevin Marois29-Jun-15 11:23 
QuestionRe: Read/Write App Settings Not Working Pin
Eddy Vluggen29-Jun-15 11:28
professionalEddy Vluggen29-Jun-15 11:28 
AnswerRe: Read/Write App Settings Not Working Pin
Kevin Marois29-Jun-15 12:00
professionalKevin Marois29-Jun-15 12:00 
GeneralRe: Read/Write App Settings Not Working Pin
Pete O'Hanlon29-Jun-15 19:42
mvePete O'Hanlon29-Jun-15 19:42 
GeneralRe: Read/Write App Settings Not Working Pin
Kevin Marois30-Jun-15 3:47
professionalKevin Marois30-Jun-15 3:47 
GeneralRe: Read/Write App Settings Not Working Pin
Dave Kreskowiak30-Jun-15 5:16
mveDave Kreskowiak30-Jun-15 5:16 
GeneralRe: Read/Write App Settings Not Working Pin
Kevin Marois30-Jun-15 5:21
professionalKevin Marois30-Jun-15 5:21 
GeneralRe: Read/Write App Settings Not Working Pin
Alex Casals30-Jun-15 13:35
professionalAlex Casals30-Jun-15 13:35 
GeneralRe: Read/Write App Settings Not Working Pin
Brisingr Aerowing1-Jul-15 7:34
professionalBrisingr Aerowing1-Jul-15 7:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.