Exemplo n.º 1
0
        public void CommandDemo()
        {
            Monster monster    = new Zombie(10, 10, 10, 0, 0);
            Player  demoPlayer = new Player
            {
                Name  = "DemoPlayer",
                Score = 100,
                Life  = 100,
                PosX  = rnd.Next(1, 2),
                PosY  = rnd.Next(1, 2)
            };

            Form1.commandLogger.logMessage(AbstractLogger.TEST, "\t\nCommand Test:\n\n");
            Form1.commandLogger.logMessage(AbstractLogger.TEST, demoPlayer.Name + " " + demoPlayer.Life + "\n");
            Form1.commandLogger.logMessage(AbstractLogger.TEST, "executing attack command on " + demoPlayer.Name + "\n");

            AttackCommand demoCommand = new AttackCommand(monster, demoPlayer);

            Form1.commandLogger.logMessage(AbstractLogger.TEST, demoPlayer.Name + " " + demoPlayer.Life + "\n");
            Form1.commandLogger.logMessage(AbstractLogger.TEST, "UNDOing attack command on " + demoPlayer.Name + "\n");

            demoCommand.undo(ref demoPlayer);

            Form1.commandLogger.logMessage(AbstractLogger.TEST, demoPlayer.Name + " " + demoPlayer.Life + "\n\n");
        }
Exemplo n.º 2
0
        private async void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Down)
            {
                richTextBox1.AppendText($"Žemyn\n");
            }
            if (e.KeyCode == Keys.F1)
            {
                richTextBox1.AppendText($"F1\n");
            }
            if (e.KeyCode == Keys.F2)
            {
                richTextBox1.AppendText("1.1)\tCreate the player\n");
                Player player = new Player
                {
                    Name  = "Naujas-" + players.Count.ToString(),
                    Score = 100,
                    //Life = 100,
                    PosX = rnd.Next(150, 300),
                    PosY = rnd.Next(150, 300)
                };

                var url = await CreatePlayerAsync(player);

                richTextBox1.AppendText($"Created at {url}\n");

                // Get the created player
                richTextBox1.AppendText("1.2)\tGet created player\n");
                player = await GetPlayerAsync(url.PathAndQuery);

                ConsoleWrite(player);
                players = await GetAllPlayerAsync(client.BaseAddress.PathAndQuery);
            }
            if (e.KeyCode == Keys.F3)
            {
                Player p1 = players.FirstOrDefault();
                Player p2 = players.ElementAt(1);
                p1.Score += 10;
                p2.Score += 20;
                var updateStatusCode = await UpdatePlayerAsync(p1);

                var updateStatusCode2 = await UpdatePlayerAsync(p2);

                richTextBox1.AppendText($"Updated (HTTP Status = {(int)updateStatusCode})\n");
                p1.Notify(players);
                label6.Text = ScoreBoard.getStatus();
            }

            if (e.KeyCode == Keys.F4)
            {
                var statusCode = await DeleteAllPlayers();

                richTextBox1.AppendText($"Deleting ALL players)\n");
            }

            if (gamestate.message != "Game will begin soon" && gamestate.message != "Game over")
            {
                if (e.KeyCode == Keys.F5)
                {
                    commandLogger.logMessage(AbstractLogger.COMMAND, "F5\n");
                    int spawnx = 0;
                    int spawny = 0;
                    if (currentPlayer.Name == "Player-1")
                    {
                        spawnx = spawn1x;
                        spawny = spawn1y;
                    }
                    else
                    {
                        spawnx = spawn2x;
                        spawny = spawn2y;
                    }

                    Monster monster = factory.factoryMethod("skeleton", spawnx, spawny);

                    monster.setStrategy(new MoveFast());

                    monster.owner = players.Where(u => u.Name == currentPlayer.Name).FirstOrDefault();

                    monsters.Add(monster);
                }

                if (e.KeyCode == Keys.F6)
                {
                    commandLogger.logMessage(AbstractLogger.COMMAND, "F6\n");
                    int spawnx = 0;
                    int spawny = 0;
                    if (currentPlayer.Name == "Player-1")
                    {
                        spawnx = spawn1x;
                        spawny = spawn1y;
                    }
                    else
                    {
                        spawnx = spawn2x;
                        spawny = spawn2y;
                    }

                    Monster monster = factory.factoryMethod("zombie", spawnx, spawny);
                    monster.setStrategy(new MoveSlow());

                    monster.owner = players.Where(u => u.Name == currentPlayer.Name).FirstOrDefault();

                    monsters.Add(monster);
                }

                if (e.KeyCode == Keys.F7)
                {
                    commandLogger.logMessage(AbstractLogger.COMMAND, "F7\n");
                    int spawnx = 0;
                    int spawny = 0;
                    if (currentPlayer.Name == "Player-1")
                    {
                        spawnx = spawn1x;
                        spawny = spawn1y;
                    }
                    else
                    {
                        spawnx = spawn2x;
                        spawny = spawn2y;
                    }

                    Monster monster = factory.factoryMethod("slime", spawnx, spawny);
                    monster.setStrategy(new Fly());

                    monster.owner = players.Where(u => u.Name == currentPlayer.Name).FirstOrDefault();

                    monsters.Add(monster);
                }
            }

            if (e.KeyCode == Keys.F9)
            {
                var statusCode = await DeleteAllMonsters();

                richTextBox1.AppendText($"Deleting ALL monsters)\n");
            }

            if (e.KeyCode == Keys.F10)
            {
                if (currentPlayer.Name == "Player-1")
                {
                    Player p = players.First();
                    lastCommand.undo(ref p);

                    Player p1 = players.ElementAt(0);
                    var    updateStatusCode2 = await UpdatePlayerAsync(p1);
                }
                else
                {
                    Player p = players.Last();
                    lastCommand.undo(ref p);

                    Player p1 = players.ElementAt(1);
                    var    updateStatusCode2 = await UpdatePlayerAsync(p1);
                }

                richTextBox1.AppendText($"undo\n");
            }
        }