Esempio n. 1
0
        public void ResetState()
        {
            state        = GameState.InProgress;
            moveSequence = new List <Direction>();

            // Create objects if they don't exist; if they do, clear out
            // their old state.
            if (objects == null)
            {
                objects = new List <GameObject>();

                // Player
                player = new PlayerObject(this);
                player.StartingLocation = board[0, 6];
                objects.Add(player);

                // Patrols
                PatrolObject pat1 = new PatrolObject(this, new GameSquare[] { board[2, 3],
                                                                              board[1, 4],
                                                                              board[2, 5],
                                                                              board[3, 5],
                                                                              board[3, 4],
                                                                              board[3, 3] });
                pat1.StartingLocation = board[2, 3];
                objects.Add(pat1);

                PatrolObject pat2 = new PatrolObject(this, new GameSquare[] { board[6, 2],
                                                                              board[5, 2],
                                                                              board[5, 3],
                                                                              board[5, 4],
                                                                              board[6, 4],
                                                                              board[7, 3] });
                pat2.StartingLocation = board[6, 2];
                objects.Add(pat2);

                // Probes
                ProbeObject probe1 = new ProbeObject(this,
                                                     new Direction[] { Direction.Left,
                                                                       Direction.Right },
                                                     false);
                probe1.StartingLocation = board[1, 0];
                objects.Add(probe1);

                ProbeObject probe2 = new ProbeObject(this,
                                                     new Direction[] { Direction.Left,
                                                                       Direction.DownLeft,
                                                                       Direction.Right,
                                                                       Direction.UpRight },
                                                     false);
                probe2.StartingLocation = board[3, 0];
                objects.Add(probe2);

                ProbeObject probe3 = new ProbeObject(this,
                                                     new Direction[] { Direction.Left,
                                                                       Direction.DownLeft,
                                                                       Direction.Right,
                                                                       Direction.UpLeft },
                                                     true);
                probe3.StartingLocation = board[2, 2];
                objects.Add(probe3);

                ProbeObject probe4 = new ProbeObject(this,
                                                     new Direction[] { Direction.Left,
                                                                       Direction.DownLeft,
                                                                       Direction.UpRight,
                                                                       Direction.UpLeft },
                                                     true);
                probe4.StartingLocation = board[4, 2];
                objects.Add(probe4);

                ProbeObject probe5 = new ProbeObject(this,
                                                     new Direction[] { Direction.DownLeft,
                                                                       Direction.Right },
                                                     false);
                probe5.StartingLocation = board[7, 2];
                objects.Add(probe5);

                ProbeObject probe6 = new ProbeObject(this,
                                                     new Direction[] { Direction.Left,
                                                                       Direction.DownRight,
                                                                       Direction.Right,
                                                                       Direction.UpRight },
                                                     true);
                probe6.StartingLocation = board[0, 3];
                objects.Add(probe6);

                ProbeObject probe7 = new ProbeObject(this,
                                                     new Direction[] { Direction.DownRight,
                                                                       Direction.UpLeft },
                                                     true);
                probe7.StartingLocation = board[4, 4];
                objects.Add(probe7);

                ProbeObject probe8 = new ProbeObject(this,
                                                     new Direction[] { Direction.Left,
                                                                       Direction.DownRight,
                                                                       Direction.UpRight },
                                                     false);
                probe8.StartingLocation = board[7, 4];
                objects.Add(probe8);

                ProbeObject probe9 = new ProbeObject(this,
                                                     new Direction[] { Direction.Left,
                                                                       Direction.DownRight,
                                                                       Direction.UpRight },
                                                     false);
                probe9.StartingLocation = board[1, 5];
                objects.Add(probe9);

                ProbeObject probe10 = new ProbeObject(this,
                                                      new Direction[] { Direction.DownLeft,
                                                                        Direction.DownRight,
                                                                        Direction.UpRight,
                                                                        Direction.UpLeft },
                                                      true);
                probe10.StartingLocation = board[2, 6];
                objects.Add(probe10);

                ProbeObject probe11 = new ProbeObject(this,
                                                      new Direction[] { Direction.DownLeft,
                                                                        Direction.Right,
                                                                        Direction.UpLeft },
                                                      true);
                probe11.StartingLocation = board[5, 6];
                objects.Add(probe11);
            }

            // Set initial object state
            foreach (GameObject obj in objects)
            {
                obj.ResetObjectState();
            }

            MarkSafeSquares();
        }
Esempio n. 2
0
        public void ResetState()
        {
            state = GameState.InProgress;
            moveSequence = new List<Direction>();

            // Create objects if they don't exist; if they do, clear out
            // their old state.
            if (objects == null)
            {
                objects = new List<GameObject>();

                // Player
                player = new PlayerObject(this);
                player.StartingLocation = board[0, 6];
                objects.Add(player);

                // Patrols
                PatrolObject pat1 = new PatrolObject(this, new GameSquare[] {board[2, 3],
                                                                             board[1, 4],
                                                                             board[2, 5],
                                                                             board[3, 5],
                                                                             board[3, 4],
                                                                             board[3, 3]});
                pat1.StartingLocation = board[2, 3];
                objects.Add(pat1);

                PatrolObject pat2 = new PatrolObject(this, new GameSquare[] {board[6, 2],
                                                                             board[5, 2],
                                                                             board[5, 3],
                                                                             board[5, 4],
                                                                             board[6, 4],
                                                                             board[7, 3]});
                pat2.StartingLocation = board[6, 2];
                objects.Add(pat2);

                // Probes
                ProbeObject probe1 = new ProbeObject(this,
                                                     new Direction[] {Direction.Left,
                                                                      Direction.Right},
                                                     false);
                probe1.StartingLocation = board[1, 0];
                objects.Add(probe1);

                ProbeObject probe2 = new ProbeObject(this,
                                                     new Direction[] {Direction.Left,
                                                                      Direction.DownLeft,
                                                                      Direction.Right,
                                                                      Direction.UpRight},
                                                     false);
                probe2.StartingLocation = board[3, 0];
                objects.Add(probe2);

                ProbeObject probe3 = new ProbeObject(this,
                                                     new Direction[] {Direction.Left,
                                                                      Direction.DownLeft,
                                                                      Direction.Right,
                                                                      Direction.UpLeft},
                                                     true);
                probe3.StartingLocation = board[2, 2];
                objects.Add(probe3);

                ProbeObject probe4 = new ProbeObject(this,
                                                     new Direction[] {Direction.Left,
                                                                      Direction.DownLeft,
                                                                      Direction.UpRight,
                                                                      Direction.UpLeft},
                                                     true);
                probe4.StartingLocation = board[4, 2];
                objects.Add(probe4);

                ProbeObject probe5 = new ProbeObject(this,
                                                     new Direction[] {Direction.DownLeft,
                                                                      Direction.Right},
                                                     false);
                probe5.StartingLocation = board[7, 2];
                objects.Add(probe5);

                ProbeObject probe6 = new ProbeObject(this,
                                                     new Direction[] {Direction.Left,
                                                                      Direction.DownRight,
                                                                      Direction.Right,
                                                                      Direction.UpRight},
                                                     true);
                probe6.StartingLocation = board[0, 3];
                objects.Add(probe6);

                ProbeObject probe7 = new ProbeObject(this,
                                                     new Direction[] {Direction.DownRight,
                                                                      Direction.UpLeft},
                                                     true);
                probe7.StartingLocation = board[4, 4];
                objects.Add(probe7);

                ProbeObject probe8 = new ProbeObject(this,
                                                     new Direction[] {Direction.Left,
                                                                      Direction.DownRight,
                                                                      Direction.UpRight},
                                                     false);
                probe8.StartingLocation = board[7, 4];
                objects.Add(probe8);

                ProbeObject probe9 = new ProbeObject(this,
                                                     new Direction[] {Direction.Left,
                                                                      Direction.DownRight,
                                                                      Direction.UpRight},
                                                     false);
                probe9.StartingLocation = board[1, 5];
                objects.Add(probe9);

                ProbeObject probe10 = new ProbeObject(this,
                                                      new Direction[] {Direction.DownLeft,
                                                                       Direction.DownRight,
                                                                       Direction.UpRight,
                                                                       Direction.UpLeft},
                                                      true);
                probe10.StartingLocation = board[2, 6];
                objects.Add(probe10);

                ProbeObject probe11 = new ProbeObject(this,
                                                      new Direction[] {Direction.DownLeft,
                                                                       Direction.Right,
                                                                       Direction.UpLeft},
                                                      true);
                probe11.StartingLocation = board[5, 6];
                objects.Add(probe11);
            }

            // Set initial object state
            foreach (GameObject obj in objects)
            {
                obj.ResetObjectState();
            }

            MarkSafeSquares();
        }
Esempio n. 3
0
        protected void DrawOccupant(Graphics g, GameObject occupant, float x, float y)
        {
            if (occupant == null)
            {
                return;
            }

            // Draw tag
            string occupantTag = "";
            Brush  occupantBrush;

            if (occupant is PlayerObject)
            {
                occupantTag   = "M";
                occupantBrush = Brushes.White;
            }
            else if (occupant is PatrolObject)
            {
                occupantTag   = "SD";
                occupantBrush = Brushes.Red;
            }
            else if (occupant is ProbeObject)
            {
                occupantBrush = Brushes.White;
                // Do not show symbol for probe
            }
            else
            {
                throw new ArgumentException("Unrecognized occupant type");
            }

            g.DrawString(occupantTag, objectFont, occupantBrush, x + 15, y + 20);

            // Draw probe search directions
            if (occupant is ProbeObject)
            {
                ProbeObject probe = (ProbeObject)occupant;

                // Draw center dot
                g.FillEllipse(Brushes.Red,
                              x + (HEX_WIDTH / 2) - 6,
                              y + (HEX_HEIGHT / 2) - 6,
                              12F, 12F);

                // Draw arrows
                foreach (Direction dir in probe.Scans)
                {
                    float lineEndX;
                    float lineEndY;
                    switch (dir)
                    {
                    case Direction.Left:
                        lineEndX = x + 5;
                        lineEndY = y + HEX_HEIGHT / 2;
                        break;

                    case Direction.UpLeft:
                        lineEndX = x + 18;
                        lineEndY = y + 3;
                        break;

                    case Direction.UpRight:
                        lineEndX = x + HEX_WIDTH - 18;
                        lineEndY = y + 3;
                        break;

                    case Direction.Right:
                        lineEndX = x + HEX_WIDTH - 5;
                        lineEndY = y + HEX_HEIGHT / 2;
                        break;

                    case Direction.DownRight:
                        lineEndX = x + HEX_WIDTH - 18;
                        lineEndY = y + HEX_HEIGHT - 3;
                        break;

                    case Direction.DownLeft:
                        lineEndX = x + 18;
                        lineEndY = y + HEX_HEIGHT - 3;
                        break;

                    default:
                        throw new ArgumentException("Unknown Direction");
                    }
                    g.DrawLine(probePen, x + HEX_WIDTH / 2, y + HEX_HEIGHT / 2, lineEndX, lineEndY);
                }

                // Draw direction
                if (probe.RotateClockwise)
                {
                    g.DrawArc(Pens.Red,
                              x + (HEX_WIDTH / 2) - 20,
                              y + (HEX_HEIGHT / 2) - 20,
                              40F, 40F,
                              180, 270);
                    g.DrawLine(Pens.Red,
                               x + (HEX_WIDTH / 2),
                               y + (HEX_HEIGHT / 2) + 20,
                               x + (HEX_WIDTH / 2) + 5,
                               y + (HEX_HEIGHT / 2) + 20 - 5);
                    g.DrawLine(Pens.Red,
                               x + (HEX_WIDTH / 2),
                               y + (HEX_HEIGHT / 2) + 20,
                               x + (HEX_WIDTH / 2) + 5,
                               y + (HEX_HEIGHT / 2) + 20 + 5);
                }
                else
                {
                    g.DrawArc(Pens.Red,
                              x + (HEX_WIDTH / 2) - 20,
                              y + (HEX_HEIGHT / 2) - 20,
                              40F, 40F,
                              90, 270);
                    g.DrawLine(Pens.Red,
                               x + (HEX_WIDTH / 2),
                               y + (HEX_HEIGHT / 2) + 20,
                               x + (HEX_WIDTH / 2) - 5,
                               y + (HEX_HEIGHT / 2) + 20 - 5);
                    g.DrawLine(Pens.Red,
                               x + (HEX_WIDTH / 2),
                               y + (HEX_HEIGHT / 2) + 20,
                               x + (HEX_WIDTH / 2) - 5,
                               y + (HEX_HEIGHT / 2) + 20 + 5);
                }
            }
        }