Beispiel #1
0
 internal void EndGame(PacmanGameData data)
 {
     foreach (var player in data.PlayerData)
     {
         if (player.ID == userID)
         {
             labelState.Text = "Game Ended!";
         }
     }
 }
Beispiel #2
0
        public void GetPacmanStringResult(int round, IGameData gameData)
        {
            PacmanGameData data   = gameData as PacmanGameData;
            List <string>  result = new List <string>();

            data.PlayerData.ForEach((player) => result.Add(player.ToString()));
            data.GhostData.ForEach((ghost) => result.Add(ghost.ToString()));
            data.WallData.ForEach((wall) => result.Add(wall.ToString()));
            data.FoodData.ForEach((food) => result.Add(food.ToString()));

            gameDataByRound.Add(round, result);
        }
Beispiel #3
0
        internal void DrawGame(PacmanGameData gameData)
        {
            gameData.FoodData.ForEach((food) =>
                                      CreatePictureForEntity(food, Properties.Resources.cccc, 100));

            gameData.GhostData.ForEach((ghost) =>
                                       CreatePictureForEntity(ghost, Properties.Resources.pink_guy, 5));

            gameData.PlayerData.ForEach((player) =>
            {
                PictureBox pic = CreatePictureForEntity(player, imgLeft, 2);
                if (player.ID == userID)
                {
                    pic.BackColor = Color.Gray;
                }
            });

            gameData.WallData.ForEach((wall) => CreatePictureForEntity(wall, null, 4));
        }
Beispiel #4
0
        internal void UpdateGame(PacmanGameData gameData)
        {
            numRounds++;

            if (readingFromFile)
            {
                if (stdinLines.Count > 0)
                {
                    string[] line = stdinLines[0];
                    stdinLines.RemoveAt(0);
                    if (Int32.Parse(line?[0]) == numRounds)
                    {
                        switch (line?[1])
                        {
                        case "LEFT":
                            server.SendKeys(userID, new bool[] { true, false, false, false });
                            break;

                        case "UP":
                            server.SendKeys(userID, new bool[] { false, true, false, false });
                            break;

                        case "RIGHT":
                            server.SendKeys(userID, new bool[] { false, false, true, false });
                            break;

                        case "DOWN":
                            server.SendKeys(userID, new bool[] { false, false, false, true });
                            break;

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    readingFromFile = false;
                }
            }
            numRounds++;

            foreach (var player in gameData.PlayerData)
            {
                PictureBox pic = panelCanvas.Controls.Find(player.ID.ToString(), true)[0] as PictureBox;
                Image      img = GetPacmanDirectionImage(player.Direction);
                pic.Location = new Point(player.Position.X, player.Position.Y);
                if (!player.Alive)
                {
                    pic.BackColor = Color.Red;
                }
                if (img != null && pic.Image != img)
                {
                    pic.Image = img;
                }
                if (player.ID == userID)
                {
                    labelState.Text = player.Position.ToString();
                    labelScore.Text = player.Score.ToString();
                }
            }

            foreach (var ghost in gameData.GhostData)
            {
                PictureBox pic = panelCanvas.Controls.Find(ghost.ID.ToString(), true)[0] as PictureBox;
                pic.Location = new Point(ghost.Position.X, ghost.Position.Y);
            }

            foreach (var food in gameData.FoodData)
            {
                PictureBox pic = panelCanvas.Controls.Find(food.ID.ToString(), true)[0] as PictureBox;
                if (!food.Alive && pic.Visible)
                {
                    pic.Visible = false;
                }
            }
        }