Esempio n. 1
0
        private static bool checkEndGame(game g)
        {
            for (int y = 0; y < g.height; y++)
            {
                for (int x = 0; x < g.width; x++)
                {
                    area a = g.boxes[y][x].lineup;
                    if (a.isAreaUsedInGame && a.isSet == false)
                    {
                        return(false);
                    }

                    a = g.boxes[y][x].linedown;
                    if (a.isAreaUsedInGame && a.isSet == false)
                    {
                        return(false);
                    }

                    a = g.boxes[y][x].lineleft;
                    if (a.isAreaUsedInGame && a.isSet == false)
                    {
                        return(false);
                    }

                    a = g.boxes[y][x].lineright;
                    if (a.isAreaUsedInGame && a.isSet == false)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        public static void clickOnArea(area a, game g, gamepanel gp)
        {
            if (a.isAreaUsedInGame == false || a.isSet || a.parents[0].thisBox == a)
            {
                return;
            }

            a.isSet = true;
            a.refpanel.BackColor = g.players[0].colour;

            //check boxes
            bool goodmove = false;

            foreach (var v in a.parents)
            {
                if (v.thisBox.isAreaUsedInGame == false || v.thisBox.isSet)
                {
                    continue;
                }

                bool val = checkAndSetFilledBox(v, g);
                if (val)
                {
                    goodmove = true;
                }
            }
            //if the box gets set, that means it was a filled square- the player gets another turn
            if (goodmove == false)
            {
                g.requeuePlayers();
                gp.currentplayercolour.BackColor = g.players[0].colour;
            }
            else
            {
                gamecontroller.updateScoreTable(g, gp);
            }

            //check end game
            if (checkEndGame(g))
            {
                gamecontroller.endGame(g, gp);
            }

            if (g.players[0].isAI)
            {
                Thread.Sleep(100);
                performTurn(g, gp);
            }
        }
Esempio n. 3
0
        public static void clickOnArea(area a, game g, gamepanel gp)
        {
            if (a.isAreaUsedInGame == false || a.isSet || a.parents[0].thisBox == a)
                return;

            a.isSet = true;
            a.refpanel.BackColor = g.players[0].colour;

            //check boxes
            bool goodmove = false;
            foreach (var v in a.parents)
            {
                if (v.thisBox.isAreaUsedInGame == false || v.thisBox.isSet)
                    continue;

                bool val = checkAndSetFilledBox(v, g);
                if (val)
                    goodmove = true;
            }
            //if the box gets set, that means it was a filled square- the player gets another turn
            if (goodmove == false)
            {
                g.requeuePlayers();
                gp.currentplayercolour.BackColor = g.players[0].colour;
            }
            else
            {
                gamecontroller.updateScoreTable(g, gp);
            }

            //check end game
            if (checkEndGame(g))
            {
                gamecontroller.endGame(g,gp);
            }

            if (g.players[0].isAI)
            {
                Thread.Sleep(100);
                performTurn(g, gp);
            }
        }
Esempio n. 4
0
        private static void addLine(area a, PanelReplacement p, int count, bool horiz, bool last)
        {
            var P = new PanelReplacement();

            P.Tag = a;

            if (a.isAreaUsedInGame)
            {
                P.BorderWidth  = 1;
                P.BorderColour = defaultcolourline;
                P.BackColor    = Color.White;
            }
            else
            {
                P.BackColor = defaultcolorlinedisabled;
            }

            P.MouseClick += P_MouseClick;

            if (horiz)
            {
                P.Width  = horizw;
                P.Height = horizh;

                a.refpanel = P;
                p.AddControl(P, !last);
            }
            else
            {
                P.Width    = horizh;
                P.Height   = horizw;
                a.refpanel = P;
                p.AddControl(P, !last);
            }
            if (a.isAreaUsedInGame)
            {
                a.parents[0].parent.lines.Add(a);
            }
        }
Esempio n. 5
0
        private static int checkFilledBoxBlankEdges(area proposedLine)
        {
            int setedgemax = 0;
            int setedge    = 0;

            foreach (box b in proposedLine.parents)
            {
                if (b.thisBox.isAreaUsedInGame == false)
                {
                    continue;
                }

                setedge = 0;
                if (b.lineup.isSet || proposedLine == b.lineup)
                {
                    setedge++;
                }
                if (b.linedown.isSet || proposedLine == b.linedown)
                {
                    setedge++;
                }
                if (b.lineleft.isSet || proposedLine == b.lineleft)
                {
                    setedge++;
                }
                if (b.lineright.isSet || proposedLine == b.lineright)
                {
                    setedge++;
                }

                if (setedgemax == -1 || setedgemax < setedge)
                {
                    setedgemax = setedge;
                }
            }
            return(setedgemax);
        }
Esempio n. 6
0
        private static void addSquareArea(area a, PanelReplacement p)
        {
            var P = new PanelReplacement();

            P.Tag = a;
            if (a.isAreaUsedInGame)
            {
                P.BorderWidth  = 1;
                P.BorderColour = defaultcolourbox;
                P.BackColor    = Color.White;
            }
            else
            {
                P.BackColor = defaultcolorboxdisabled;
            }

            P.MouseClick += P_MouseClick;

            P.Width    = horizw;
            P.Height   = horizw;
            a.refpanel = P;

            p.AddControl(P, true);
        }
Esempio n. 7
0
 public static gamepanel getGamePanel(area a)
 {
     return(a.refpanel.Parent.Parent.Parent as gamepanel);
 }
Esempio n. 8
0
        private static int checkFilledBoxBlankEdges(area proposedLine)
        {
            int setedgemax = 0;
            int setedge = 0;
            foreach (box b in proposedLine.parents)
            {
                if (b.thisBox.isAreaUsedInGame==false)
                    continue;

                setedge = 0;
                if (b.lineup.isSet || proposedLine == b.lineup)
                    setedge++;
                if (b.linedown.isSet || proposedLine == b.linedown)
                    setedge++;
                if (b.lineleft.isSet || proposedLine == b.lineleft)
                    setedge++;
                if (b.lineright.isSet || proposedLine == b.lineright)
                    setedge++;

                if (setedgemax == -1 || setedgemax < setedge)
                    setedgemax = setedge;
            }
            return setedgemax;
        }
Esempio n. 9
0
        private static void addSquareArea(area a, PanelReplacement p)
        {
            var P = new PanelReplacement();
            P.Tag = a;
            if (a.isAreaUsedInGame)
            {
                P.BorderWidth = 1;
                P.BorderColour = defaultcolourbox;
                P.BackColor = Color.White;
            }
            else
                P.BackColor = defaultcolorboxdisabled;

            P.MouseClick += P_MouseClick;

            P.Width = horizw;
            P.Height = horizw;
            a.refpanel = P;

            p.AddControl(P, true);
        }
Esempio n. 10
0
        private static void addLine(area a, PanelReplacement p, int count, bool horiz, bool last)
        {
            var P = new PanelReplacement();
            P.Tag = a;

            if (a.isAreaUsedInGame)
            {
                P.BorderWidth = 1;
                P.BorderColour = defaultcolourline;
                P.BackColor = Color.White;
            }
            else
                P.BackColor = defaultcolorlinedisabled;

            P.MouseClick += P_MouseClick;

            if (horiz)
            {
                P.Width = horizw;
                P.Height = horizh;

                a.refpanel = P;
                p.AddControl(P, !last);
            }
            else
            {
                P.Width = horizh;
                P.Height = horizw;
                a.refpanel = P;
                p.AddControl(P, !last);
            }
            if (a.isAreaUsedInGame)
            a.parents[0].parent.lines.Add(a);
        }
Esempio n. 11
0
 public static gamepanel getGamePanel(area a)
 {
     return a.refpanel.Parent.Parent.Parent as gamepanel;
 }