Ejemplo n.º 1
0
        /// <summary>
        /// Gets the unit which should be attacked by the given unit
        /// </summary>
        /// <param name="unit">Computer controlled unit for which to decide who to attack</param>
        /// <returns>Player unit to be attacked</returns>
        public PlayerCharacter getUnitToAttack(EnemyCharacter unit)
        {
            List <Character> enemies = GameBoard.getAttackableUnits(unit.xPos, unit.yPos, playerUnits.Cast <Character>().ToList());
            // TODO: Implement some kind of decision strategy
            // for now, just pick an attackable unit at random
            Random r = new Random();

            return((PlayerCharacter)enemies[r.Next(0, enemies.Count - 1)]);
        }
Ejemplo n.º 2
0
        private int canAttackOpponent(Character unit, List <Character> enemyUnits)
        {
            List <Character> attackable = GameBoard.getAttackableUnits(unit.xPos, unit.yPos, enemyUnits);

            if (attackable.Any())
            {
                return(HEURISTIC_ATTACK_OPPONENT_UNIT);
            }
            return(0);
        }
Ejemplo n.º 3
0
        public FlameBadge()
        {
            // Set up saves directory

            if (!Directory.Exists(save_dir))
            {
                Directory.CreateDirectory(save_dir);
            }

            // Check if any save files exist
            // If they don't we won't bother offering a load game option
            DirectoryInfo dir       = new DirectoryInfo(save_dir);
            Boolean       is_loaded = false;

            if (dir.GetFiles().Length != 0)
            {
                is_loaded = _offerContinue();
            }

            String loaded_file = "";

            if (is_loaded)
            {
                loaded_file = _getSavedGame(dir);
            }

            if (loaded_file == "")
            {
                is_loaded = false;
            }
            else
            {
                loaded_file = save_dir + loaded_file;
            }

            // if we loaded we need to know whose turn it was
            Char curr_turn = '0';

            if (is_loaded)
            {
                curr_turn = _getTurn(loaded_file);
            }

            // Draw the game board.
            GameBoard game_board = new GameBoard(is_loaded ? loaded_file : null);

            // Put the pieces on the board.
            PlayerCharacter.placePieces(is_loaded, loaded_file);
            EnemyCharacter.placePieces(is_loaded, loaded_file);

            // mainloop
            while (true)
            {
                for (int i = 0; i < player_units.Count; i++)
                {
                    // if we loaded a game, skip over everyone until the rightful
                    // unit goes
                    if (curr_turn != '0')
                    {
                        if (player_units[i].id != curr_turn)
                        {
                            continue;
                        }
                        else
                        {
                            curr_turn = '0';
                        }
                    }
                    player_units[i].takeTurn();
                    List <Character> victims = GameBoard.getAttackableUnits(player_units[i].xPos, player_units[i].yPos, cpu_units.Cast <Character>().ToList());
                    if (victims.Count > 0)
                    {
                        //pass in true to signify player
                        GameBoard.attack(player_units[i].id, victims[0].id, true);
                        GameBoard.redraw();
                        if (cpu_units.Count == 0)
                        {
                            FlameBadge.hasEnded = true;
                        }
                    }
                    Tuple <Int16, Int16> enemyCastle = GameBoard.getCPUCastle();
                    if ((int)enemyCastle.Item2 == (int)player_units[i].xPos && (int)enemyCastle.Item1 == (int)player_units[i].yPos)
                    {
                        FlameBadge.hasEnded = true;
                    }
                    if (FlameBadge.hasEnded)
                    {
                        _endGame();
                    }
                }

                for (int i = 0; i < cpu_units.Count; i++)
                {
                    cpu_units[i].takeTurn();
                    List <Character> victims = GameBoard.getAttackableUnits(cpu_units[i].xPos, cpu_units[i].yPos, player_units.Cast <Character>().ToList());
                    if (victims.Count > 0)
                    {
                        //pass in false to signify AI
                        GameBoard.attack(cpu_units[i].id, victims[0].id, false);
                        GameBoard.redraw();
                        if (player_units.Count == 0)
                        {
                            FlameBadge.hasEnded = true;
                        }
                    }
                    Tuple <Int16, Int16> enemyCastle = GameBoard.getPlayerCastle();
                    if ((int)enemyCastle.Item2 == (int)cpu_units[i].xPos && (int)enemyCastle.Item1 == (int)cpu_units[i].yPos)
                    {
                        FlameBadge.hasEnded   = true;
                        FlameBadge.cpuCapture = true;
                    }
                    if (FlameBadge.hasEnded)
                    {
                        _endGame();
                    }
                }
            }
        }