Inheritance: MonoBehaviour, IResettable
        public SampleGameWindow(HumanPlayer p)
        {
            InitializeComponent();

            Player = p;
            this.Title = String.Concat("SharpScrabble - Player: ", p.Name);
        }
Esempio n. 2
0
 void Start()
 {
     phView = GetComponent<PhotonView>();
     humanScript = GetComponent<HumanPlayer>();
     _controller = GetComponent<CharacterController>();
     myCam = this.transform.FindChild("MyCam").GetComponent<Camera>();
 }
Esempio n. 3
0
 public void CreatePlayer()
 {
     game = new Game();
     input = new StubTextReader();
     output = new StringWriter();
     player = new HumanPlayer(game, input, output);
 }
Esempio n. 4
0
 public Game()
 {
     this.AI = new AIPlayer();
     this.Human = new HumanPlayer();
     EventManager.OnGameOver += this.GameOver;
     EventManager.OnGamePause += this.Pause;
     EventManager.OnGameResume += this.Resume;
 }
Esempio n. 5
0
        public void ThenTheBoardShouldLookLike(Table table)
        {
            var input = new StubTextReader();
            var output = new StringWriter();
            var player = new HumanPlayer(game, input, output);
            input.WriteLine(game.AvailableMoves[0]);
            player.GetNextMove();

            Assert.That(output.ToString(), Text.Contains(GetBoardRepresentation(table)));
        }
Esempio n. 6
0
        //Each player gets one of these, they "own" it
        public GameWindow(HumanPlayer p)
        {
            InitializeComponent();

            Player = p;
            PlayerTiles.PlayerName = p.Name;
            this.Title = String.Concat("SharpScrabble - Player: ", p.Name);
            WordInPlay = new Dictionary<Point, Tile>(); //initialize

            RedrawBoard();  //calling this again to show tiles.
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            HumanPlayer playerOne = new HumanPlayer();
             HumanPlayer playerTwo = new HumanPlayer();
             Engine engine = new Engine();
             Menu menu = new Menu();

             menu.ShowMenu();
             Console.Clear();
             engine.Run(playerOne, playerTwo);
        }
Esempio n. 8
0
        public MainWindow()
        {
            _humanPlayer = new HumanPlayer();
            _computerPlayer = new ComputerPlayer();
            _humanGrid = new HumanGridVM(_humanPlayer, _computerPlayer);
            _computerGrid = new ComputerGridVM(_humanPlayer, _computerPlayer);

            InitializeComponent();
            humanGrid.DataContext = _humanGrid;
            computerGrid.DataContext = _computerGrid;
        }
Esempio n. 9
0
        public async Task<IdentityResult> RegisterUser(UserViewModel userViewModel)
        {
			HumanPlayer user = new HumanPlayer
            {
                UserName = userViewModel.UserName
            };

            var result = await _userManager.CreateAsync(user, userViewModel.Password);

            return result;
        }
        public MainWindow()
        {
            _humanPlayer = new HumanPlayer();
            _computerPlayer = new ComputerPlayer();
            _humanGrid = new HumanGridVM(_humanPlayer, _computerPlayer);
            _computerGrid = new ComputerGridVM(_humanPlayer, _computerPlayer);

            InitializeComponent();
            _mainWindow = this;
            humanGrid.DataContext = _humanGrid;
            computerGrid.DataContext = _computerGrid;
            UpdateTb(0,19);
        }
Esempio n. 11
0
        public void Run(HumanPlayer playerOne,HumanPlayer playerTwo)
        {
            bool playerOneTurn = true;
             bool playerTwoTurn = false;

             while (true)
             {
               if (playerOneTurn == true)
             {
             Console.WriteLine("{0}'s turn", playerOne.PlayerName);
             Console.WriteLine("Enter a number: ");
             playerOne.Input = Console.ReadLine();
             }
             else
             {
             Console.WriteLine("{0}'s turn", playerTwo.PlayerName);
             Console.WriteLine("Enter a number: ");
             playerTwo.Input = Console.ReadLine();
             }

             if (playerOne.Input != playerTwo.Number && playerOneTurn == true)
             {

             CheckInput(playerTwo.Number, playerOne.Input);
             playerOneTurn = false;
             playerTwoTurn = true;
             continue;
             }
             else if (playerOne.Input == playerTwo.Number && playerOneTurn == true)
             {
             CheckInput(playerTwo.Number, playerOne.Input);
             Console.WriteLine("{0} WINS!", playerOne.PlayerName);
             break;
             }

             if (playerTwo.Input != playerOne.Number && playerTwoTurn == true)
             {
             CheckInput(playerOne.Number, playerTwo.Input);
             playerOneTurn = true;
             playerTwoTurn = false;
             }
             else if (playerTwo.Input == playerOne.Number && playerTwoTurn == true)
             {
             CheckInput(playerOne.Number, playerTwo.Input);
             Console.WriteLine("{0} WINS!", playerTwo.PlayerName);
             break;
             }
             }
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var humanHand = new Hand(true);
            var compHand1 = new Hand(true);
            //var compHand2 = new Hand();

            var human = new HumanPlayer("Gary", humanHand);
            var comp1 = new ComputerPlayer("Bob", compHand1);
            //var comp2 = new ComputerPlayer("Jane", compHand2);

            //var state = new State(comp1, comp2, compHand1, compHand2);
            var state = new State(human, comp1, humanHand, compHand1);

            GameManager.Play(state);
        }
Esempio n. 13
0
        public override void Initialize()
        {
            for (var i = 0; i < GameConfiguration.PlayerNumber; i++)
            {
                if (i >= CurrentMap.PlayerSpawnPoints.Count)
                    break;

                var player = new HumanPlayer(i, i) { Name = PlayerInfo.Username + i };
                player.SetGameManager(this);
                player.ChangePosition(CurrentMap.PlayerSpawnPoints[player.Id]);

                AddPlayer(player);
            }

            base.Initialize();
        }
Esempio n. 14
0
        /// <summary>
        /// Creates a new GameModel and its subcomponents.
        /// </summary>
        /// <returns>The created GameModel.</returns>
        public GameModel BuildModel()
        {
            // build game objects
            Planet planet = new Planet();
            planet.Radius = 300;

            // build planet in orbit
            int distance = 700;

            Planet planet2 = new Planet();
            planet2.Radius = 82;
            planet2.IsFlexible = true;
            planet2.Position = new Vector2(distance, 0);
            // calculate velocity needed to circuit in orbit
            float planet2Velocity = (float) Math.Sqrt(planet.Mass * GameAssets.G / distance / (GameAssets.N * 1000));
            planet2.Velocity = new Vector2(0, planet2Velocity);

            Spaceship spaceship1 = new Spaceship();
            Spaceship spaceship2 = new Spaceship();

            Player player1 = new HumanPlayer(1, this.playerHandler, Color.Green, this.configuration.GetKeyboardConfiguration(1));
            Player player2 = new HumanPlayer(2, this.playerHandler, Color.Orange, this.configuration.GetKeyboardConfiguration(2));
            player1.Spaceship = spaceship1;
            player2.Spaceship = spaceship2;

            player1.Spaceship.Position = new Vector2(-1900, 0);
            player2.Spaceship.Position = new Vector2(1900, 0);

            List<Player> players = new List<Player>();
            players.Add(player1);
            players.Add(player2);

            WorldObject[] worldObjects = {planet, planet2, spaceship1, spaceship2};

            // build ShortLifespanObjectFactory
            ShortLifespanObjectFactory shortLifespanObjectFactory = new SimpleShortLifespanObjectFactory();

            // build game model
            World world = new World(worldObjects);
            Physics physics = new SimplePhysicsAlgorithm(this.collisionHandler, world, configuration);
            GameModel gameModel = new GameModel(shortLifespanObjectFactory, physics, players, world);
            return gameModel;
        }
Esempio n. 15
0
	public void CreatePlayers() {
		boardInput = GetComponent<ChessInput> ();

		HumanPlayer whiteHuman = null;
		HumanPlayer blackHuman = null;	
		AIPlayer whiteAI = null;
		AIPlayer blackAI = null;

		if (blackPlayerType == PlayerType.Human) {
			ChessUI.instance.SetBoardOrientation(false);
			blackHuman = new HumanPlayer ();
			boardInput.AddPlayer (blackHuman);
		} else {
			blackAI = new AIPlayer ();
		}

		if (whitePlayerType == PlayerType.Human) {
			ChessUI.instance.SetBoardOrientation(true);
			whiteHuman = new HumanPlayer ();
			boardInput.AddPlayer (whiteHuman);
			FindObjectOfType<NotationInput>().SetPlayer(whiteHuman);
		} else {
			whiteAI = new AIPlayer ();
		}

		whitePlayer = (Player)whiteHuman ?? (Player)whiteAI;
		blackPlayer = (Player)blackHuman ?? (Player)blackAI;

		whitePlayer.OnMove += OnMove;
		blackPlayer.OnMove += OnMove;

		whitePlayer.Init (true);
		blackPlayer.Init (false);

		whiteToPlay = Board.IsWhiteToPlay ();
		RequestMove ();
	}
Esempio n. 16
0
        public static IPlayer createPlayerOfType(ePlayerType i_PlayerType)
        {
            IPlayer player = null;
            switch (i_PlayerType)
            {
                case ePlayerType.Human:
                    player = new HumanPlayer();
                    break;
                case ePlayerType.DumbComputer:
                    player = new ComputerPlayer();
                    break;
                case ePlayerType.OkComputer:
                    player = createSmartPlayerWithSearchDepthOf(0);
                    break;
                case ePlayerType.SmartComputer:
                    player = createSmartPlayerWithSearchDepthOf(2);
                    break;
                case ePlayerType.GeniusComputer:
                    player = createSmartPlayerWithSearchDepthOf(4);
                    break;
            }

            return player;
        }
Esempio n. 17
0
    /// <summary>
    /// Processes a mouse click on the card.
    /// </summary>
    void ProcessClick()
    {
        if (!Clickable)
        {
            return;
        }
        // deselect sectors when processing click
        HumanPlayer currentPlayer = Game.Instance.CurrentPlayer as HumanPlayer;

        if (currentPlayer != null)
        {
            currentPlayer.DeselectSector();
        }

        EffectAvailableSelection selection = _effect.AvailableSelection(Game.Instance);

        if (_held)
        {
            // prevent the raycast from hitting the card
            Collider triggerCollider = gameObject.GetComponent <Collider>();
            triggerCollider.enabled = false;
            Ray        ray = _mainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                // check if a player UI was clicked
                // and if so attempt to apply the effect to the player
                PlayerUI playerUI = hit.collider.transform.parent?.gameObject.GetComponent <PlayerUI>();
                if (playerUI != null && (selection.Players?.Contains(playerUI.Player) ?? false))
                {
                    ConsumeEffect(playerUI.Player.Stats);
                }
                // check if a sector was clicked
                // if so, check if we can apply the effect to the unit,
                // otherwise just apply the effect to the sector
                Sector sector = hit.collider.gameObject.GetComponent <Sector>();
                if (sector != null)
                {
                    if (sector.Unit != null && (selection.Units?.Contains(sector.Unit) ?? false))
                    {
                        ConsumeEffect(sector.Unit.Stats);
                    }
                    else if (selection.Sectors?.Contains(sector) ?? false)
                    {
                        ConsumeEffect(sector.Stats);
                    }
                }
            }
            triggerCollider.enabled = true;
            ClearHighlights();
            CardHeld        = _held = false;
            PositionPercent = PositionPercent;
        }
        else
        {
            // activate highlight for all relevant objects
            SetSelectedHighlight(true, selection);
            SizePercent = 0;
            CardHeld    = _held = true;
        }
    }
Esempio n. 18
0
    static IPlayer CreatePlayer(GameManager.GameMode.Match.Player player, TeamGenerator team)
    {
        IPlayer newPlayer = (player.isComputer) ? CompPlayer.CreatePlayer(player.playerTeam, team) : HumanPlayer.CreatePlayer(player.playerTeam, team);

        return(newPlayer);
    }
Esempio n. 19
0
	public void SetPlayer(HumanPlayer p) {
		player = p;
	}
Esempio n. 20
0
        public GameServer(int port, int maxPlayers) : base(MakeConfig(port, maxPlayers))
        {
            server    = new NetServer(base.Config);
            base.peer = server;
            base.tag  = "Server";

            this.MaxPlayers = maxPlayers;

            this.connectedPlayers = new List <Player>();
            this.idToPlayer       = new Dictionary <uint, Player>();
            this.remoteIDToPlayer = new Dictionary <long, HumanPlayer>();
            this.worldUploads     = new List <ActiveWorldUpload>();

            base.SetHandler(NetMessageType.Req_BasicServerInfo, (id, msg) =>
            {
                // Note: this message never arrives from the client if they are a host, as they already know everything about the world.

                // Send a little info about the server and the map...
                NetOutgoingMessage first = CreateBaseMapInfo();
                SendMessage(msg.SenderConnection, first, NetDeliveryMethod.ReliableOrdered);

                // Send player list.
                SendAllPlayerData(msg.SenderConnection);

                // The client should send back a response asking for full map info. (see below for response)
            });

            base.SetHandler(NetMessageType.Req_WorldChunks, (id, msg) =>
            {
                // Client has request for map/entity data to be sent.
                // TODO check that the client hasn't already requested this before.

                // Send map chunks.

                // Add a new world upload. TODO also upload entities.
                var upload = new ActiveWorldUpload(msg.SenderConnection, Main.Map.GetNumberOfNetChunks(), MaxChunksToUploadPerFrame);
                worldUploads.Add(upload);

                Trace($"Now starting to send {upload.TotalChunksToSend} chunks of map data...");
            });

            // Add status change listener.
            base.OnStatusChange += (conn, status, msg) =>
            {
                HumanPlayer player = GetPlayer(conn);
                switch (status)
                {
                case NetConnectionStatus.Connected:
                    // At this point, the HumanPlayer object has already been set up because it's connection was approved.
                    // Nothing to do here for now.

                    if (player == null)
                    {
                        Error($"Remote client has connected, but a player object is not associated with them... Did setup fail?");
                        break;
                    }

                    Log($"Client has connected: {player.Name} {(player.IsHost ? "(host)" : "")}");
                    Net.BroadcastConnect(player);

                    // Notify all clients that a new player has joined (apart from the host who already knows)
                    var newConnectMsg = CreateMessage(NetMessageType.Data_PlayerData, 32);
                    newConnectMsg.Write((byte)1);
                    newConnectMsg.Write(false);           // IsBot
                    player.WriteToMessage(newConnectMsg); // Other data such as IsHost, name etc.
                    SendMessageToAll(newConnectMsg, NetDeliveryMethod.ReliableSequenced, HostConnection);

                    break;

                case NetConnectionStatus.Disconnected:
                    // Player has left the game, bye!
                    // Remove the player associated with them.
                    if (player == null)
                    {
                        Error($"Remote client has disconnected, but a player object is not associated with them...");
                        break;
                    }

                    string text = msg.PeekString();

                    Log($"Client '{player.Name}' has disconnected: {text}");
                    Net.BroadcastDisconnect(player);

                    // Notify all clients that a player has left (apart from the host who already knows)
                    var disconnectMsg = CreateMessage(NetMessageType.Data_PlayerData, 32);
                    disconnectMsg.Write((byte)2);
                    disconnectMsg.Write(player.ID);
                    SendMessageToAll(disconnectMsg, NetDeliveryMethod.ReliableSequenced, HostConnection);

                    RemovePlayer(player);
                    break;
                }
            };

            // Add handlers.
            base.SetBaseHandler(NetIncomingMessageType.ConnectionApproval, (msg) =>
            {
                // TODO add check for number of players currently in the game.

                ulong hostKey = msg.ReadUInt64();
                bool isHost   = false;
                if (hostKey != 0)
                {
                    // This means that the client is claiming to be the local host.
                    // If so, the host key should be the same as the one on this object,
                    // which is generated when the server Start() method is called.
                    // Otherwise, there is either a serious bug or a hacking attempt.
                    if (hostKey != this.HostKey)
                    {
                        Warn($"Connecting client from {msg.SenderConnection} has claimed they are the host with host key {hostKey}, but this in the incorrect host key. Bug or impersonator?");
                    }
                    else
                    {
                        // Correct host key, they are the real host (or 1 in 18.4 quintillion chance).
                        isHost = true;
                    }
                }

                // Password (or empty string).
                string password = msg.ReadString();
                if (this.Password != null && password.Trim() != this.Password.Trim())
                {
                    msg.SenderConnection.Deny("Incorrect password");
                    return;
                }

                // Player name.
                string name = msg.ReadString();
                if (string.IsNullOrWhiteSpace(name))
                {
                    msg.SenderConnection.Deny("Invalid name");
                    return;
                }

                // Create player object for them.
                HumanPlayer p        = new HumanPlayer();
                p.IsHost             = isHost;
                p.Name               = name;
                p.ConnectionToClient = msg.SenderConnection;

                // Add player to the game. (gives them an Id and stuff)
                AddPlayer(p);

                if (isHost)
                {
                    // Flag them as the host connection.
                    HostConnection = msg.SenderConnection;
                }

                // Accept the connection, everything looks good!
                msg.SenderConnection.Approve();
            });
        }
Esempio n. 21
0
 public RendererShould()
 {
     _gameBoard   = new GameBoard();
     _humanPlayer = new HumanPlayer(Symbol.Cross, new InputChecker());
 }
Esempio n. 22
0
    private void AirConsole_onConnect(int device_id)
    {
        var player = new HumanPlayer(device_id);

        this.Players.Add(player);
        this.AssignToTeam(player);

        // give the player the smallest number not yet assigned
        player.Number = this.GetNextNumber(this.Players.Select(p => p.Number));

        this.UpdatePlayerCount();
    }
Esempio n. 23
0
        /// <summary>
        /// Instantiates and registers all objects associated with a PSystem (planets, players, ships, etc)
        /// </summary>
        public static async Task <PSystem> DeserializePSystemAsync(PSystemModel system, RedisServer redisServer, LocatorService ls, IGalaxyRegistrationManager rm, IDatabaseManager dbm)
        {
            PSystem           retSys            = new PSystem(system, ls);
            List <IShip>      deserializedShips = new List <IShip>();
            List <IStructure> loadedStructures  = new List <IStructure>();
            List <Player>     loadedPlayers     = new List <Player>();

            //For now we just run the whole lambda synchronously in its own thread. Marking it async makes this method return complete before the task is complete, need to investigate...
            await Task.Factory.StartNew(() =>
            {
                HashSet <int> colonyIDsToLoad = new HashSet <int>();
                HashSet <int> shipIDsToLoad   = new HashSet <int>();
                HashSet <int> areaIDsToLoad   = new HashSet <int>();
                List <int> structureIDsToLoad = new List <int>();
                HashSet <int> layoutIDsToLoad = new HashSet <int>();

                foreach (int id in system.ShipIDs)
                {
                    if (shipIDsToLoad.Contains(id))
                    {
                        throw new CorruptStateException("Multiple areas contain the same shipID.");
                    }
                    shipIDsToLoad.Add(id);
                }
                foreach (var id in retSys.MoonIDs)
                {
                    areaIDsToLoad.Add(id);
                }

                foreach (var id in retSys.PlanetIDs)
                {
                    areaIDsToLoad.Add(id);
                }

                foreach (var id in retSys.PortIDs)
                {
                    areaIDsToLoad.Add(id);
                }

                IEnumerable <AreaModel> loadedAreaModels = dbm.GetAreasAsync(areaIDsToLoad).Result;

                foreach (var am in loadedAreaModels)
                {
                    switch (am.AreaType)
                    {
                    case AreaTypes.Planet:
                        layoutIDsToLoad.Add(((PlanetModel)am).LayoutId);
                        break;
                    }
                }


                IEnumerable <PlanetLayout> loadedLayouts = dbm.GetLayoutsAsync(layoutIDsToLoad).Result.Select(s => (PlanetLayout)s);
                Dictionary <int, PlanetLayout> layouts   = new Dictionary <int, PlanetLayout>();
                foreach (var l in loadedLayouts)
                {
                    layouts.Add(l.Id, l);
                }


                var loadedAreas = new List <IArea>();
                // Instantiate all areas
                foreach (AreaModel am in loadedAreaModels)
                {
                    IArea loadedArea = null;
                    structureIDsToLoad.AddRange(am.StructureIDs);

                    // Planets
                    if (am.AreaType == AreaTypes.Planet)
                    {
                        loadedArea = new Planet((PlanetModel)am, layouts[((PlanetModel)am).LayoutId], ls);
                        var p      = loadedArea as Planet;
                        //rm.RegisterObject(p);
                        if (p.ColonyID != null)
                        {
                            colonyIDsToLoad.Add((int)p.ColonyID);
                        }
                    }

                    // Ports
                    else if (am.AreaType == AreaTypes.Port)
                    {
                        loadedArea = new Port((PortModel)am, ls);
                    }
                    else
                    {
                        throw new Exception("Error: Loaded area not handled in DeserializePSystem()");
                    }



                    foreach (var id in am.ShipIDs)
                    {
                        if (shipIDsToLoad.Contains(id))
                        {
                            throw new CorruptStateException("Multiple areas contain the same shipID.");
                        }
                        shipIDsToLoad.Add(id);
                    }
                    loadedAreas.Add(loadedArea);
                    rm.RegisterObject(loadedArea);
                }

                // Colonies
                IEnumerable <AreaModel> LoadedColonies = dbm.GetAreasAsync(colonyIDsToLoad).Result;
                List <Colony> deserializedColonies     = new List <Colony>();
                foreach (AreaModel am in LoadedColonies)
                {
                    if (am.AreaType == AreaTypes.Colony)
                    {
                        Colony c         = new Colony((ColonyModel)am, ls);
                        c.DisableUpdates = true;
                        rm.RegisterObject(c);
                        deserializedColonies.Add(c);
                    }
                    else
                    {
                        throw new Exception("AreaID query resulted in an AreaModel which was not a ColonyModel in DeserializePSystem()");
                    }
                    foreach (var id in am.ShipIDs)
                    {
                        if (shipIDsToLoad.Contains(id))
                        {
                            throw new CorruptStateException("Multiple areas contain the same shipID.");
                        }
                        shipIDsToLoad.Add(id);
                    }
                }

                // Structures
                loadedStructures.AddRange(LoadStructures(retSys, dbm, rm, ls.PlayerLocator).Result);

                foreach (IArea loadedArea in loadedAreas)
                {
                    if (loadedArea is IHasStructures)
                    {
                        loadedStructures.AddRange(LoadStructures((IHasStructures)loadedArea, dbm, rm, ls.PlayerLocator).Result);
                    }
                }


                // Ships
                IEnumerable <ShipModel> loadedShipModels = dbm.GetShipsAsync(shipIDsToLoad).Result;
                HashSet <int> playerIDsToLoad            = new HashSet <int>();
                foreach (var s in loadedShipModels)
                {
                    var loadedShip = DeserializeShip(s, ls, rm);
                    deserializedShips.Add(loadedShip);
                    if (loadedShip.PlayerID != null)
                    {
                        playerIDsToLoad.Add((int)s.PlayerID);
                    }
                }


                // Players
                IEnumerable <PlayerModel> loadedPlayerModels = dbm.GetPlayersAsync(playerIDsToLoad).Result;

                HashSet <int> accountIDsToLoad = new HashSet <int>();
                foreach (var p in loadedPlayerModels)
                {
                    if (p.PlayerType == PlayerTypes.Human)
                    {
                        HumanPlayer hp = new HumanPlayer(p, ls);
                        rm.RegisterObject(hp);
                        loadedPlayers.Add(hp);
                    }
                    else
                    {
                        NPCPlayer np      = new NPCPlayer(p, ls);
                        np.MessageService = new RedisOutgoingMessageService(redisServer, np);
                        rm.RegisterObject(np);
                        loadedPlayers.Add(np);
                    }
                    if (p.AccountID != null)
                    {
                        accountIDsToLoad.Add((int)p.AccountID);
                    }
                }


                //Accounts
                IEnumerable <AccountModel> loadedAccounts = dbm.GetAccountsAsync(accountIDsToLoad).Result;

                foreach (var a in loadedAccounts)
                {
                    rm.RegisterObject(new Account(a));
                }

                foreach (var c in deserializedColonies)
                {
                    c.DisableUpdates = false;
                }
            }
                                        );

            rm.RegisterObject(retSys);

            foreach (Player p in loadedPlayers)
            {
                if (p.PlayerType == PlayerTypes.NPC)
                {
                    p.GetArea().MovePlayerHere(p, false);
                }
            }

            foreach (var s in deserializedShips)
            {
                IArea a = s.GetArea();

                if (a == null)//Corrupt state, the ship's CurrentAreaId doesn't match the list is for an area which hasn't been loaded yet. Abort the ship read.
                {
                    //I'm not sure that there's a way to gracefully handle this without a major rewrite and a bunch of overhead, so it'll be an exception for now.
                    throw new CorruptStateException("Ship's CurrentAreaId does not match the area from which it was loaded. Expect exceptions.");
                }
                else
                {
                    a.AddShip(s, true);
                }
            }


            return(retSys);
        }
Esempio n. 24
0
        public void HumanPlayer_Init()
        {
            var player = new HumanPlayer("John");

            Assert.IsNotNull(player.Turn);
        }
Esempio n. 25
0
    private void Start()
    {
        humanPlayer = GetComponentInParent<HumanPlayer>();

        SetTextToValue();
    }
Esempio n. 26
0
    // Update is called once per frame
    void Update()
    {
        switch (SimulationPhase)
        {
        case SimulationPhase.MatchesReady:
            //Debug.Log("Starting matchround " + Population.Generation + "." + (MatchesPlayed + 1));
            SimulationUI.TitleText.text = "Match Round " + Population.Generation + "." + (MatchesPlayed + 1);
            foreach (Match m in Matches)
            {
                if (m.Visual)
                {
                    SimulationUI.gameObject.SetActive(false);
                    VisualMatch = m;
                    m.StartMatch(VisualPlayer, VisualMinion, VisualBoardHeight, MatchUI);
                }
                else
                {
                    m.StartMatch();
                }
            }
            SimulationPhase = SimulationPhase.MatchesRunning;
            break;

        case SimulationPhase.MatchesRunning:
            foreach (Match m in Matches)
            {
                m.Update();
            }
            if (Matches.TrueForAll(x => x.Phase == MatchPhase.GameEnded))
            {
                MatchesPlayed++;
                SimulationPhase = SimulationPhase.MatchesFinished;
                if (VisualMatch != null)
                {
                    VisualMatch = null;
                    SimulationUI.gameObject.SetActive(true);
                }
            }
            break;

        case SimulationPhase.MatchesFinished:

            // Update Stats
            UpdateStatistics();

            if (MatchesPlayed >= MatchesPerGeneration)
            {
                // Init Human vs AI game if gen is finished
                if (SimulationUI.PlayGame.isOn)
                {
                    SimulationUI.PlayGame.isOn = false;
                    Matches.Clear();

                    // Create match
                    Match   match       = new Match();
                    Player  player1     = new HumanPlayer(match);
                    Subject bestSubject = Population.Subjects.OrderByDescending(x => x.Wins).First();
                    Player  player2     = new AIPlayer(match, bestSubject);
                    match.InitGame(player1, player2, StartHealth, StartCardOptions, MinCardOptions, MaxCardOptions, MaxMinions, MaxMinionsPerType, FatigueDamageStartTurn, true, false);

                    // Start match
                    Matches.Add(match);
                    VisualMatch = match;
                    SimulationUI.gameObject.SetActive(false);
                    match.StartMatch(VisualPlayer, VisualMinion, VisualBoardHeight, MatchUI);
                    SimulationPhase = SimulationPhase.MatchesReady;
                }

                else
                {
                    SimulationPhase = SimulationPhase.GenerationFinished;
                }
            }
            else
            {
                GenerateMatches();
                SimulationPhase = SimulationPhase.MatchesReady;
            }
            break;

        case SimulationPhase.GenerationFinished:

            // Reset stats
            ResetStatistics();
            MatchesPlayed = 0;

            // Evolve and Update UI
            EvolutionInformation info = Population.EvolveGeneration();
            SimulationUI.EvoStats.UpdateStatistics(info);
            SimulationUI.SpeciesScoreboard.UpdateScoreboard(Population);

            // Generate first match round
            GenerateMatches();
            SimulationPhase = SimulationPhase.MatchesReady;
            break;
        }
    }
Esempio n. 27
0
        private void pictureBox1_MouseClick_1(object sender, MouseEventArgs e)
        {
            int x = e.Y / 64, y = e.X / 64;

            if (humanVsHuman)
            {
                if (player.getPlayerColor() == playerColor.White)
                {
                    if (mouseClickCounter == 0 && !board.isEmptyCell(x, y) && board.getBoardPieces()[x, y].getPieceColor() == pieceColor.BLack)
                    {
                        MessageBox.Show("It is white player turn");
                    }
                    else if (!board.isEmptyCell(x, y) && mouseClickCounter == 0 && e.Button == MouseButtons.Left)
                    {
                        ++mouseClickCounter;
                        tmp = board.getBoardPieces()[x, y].getLegalMovesWithCheck(board);
                        originalPiecePosition = Tuple.Create(x, y);
                        hightlightLegalMoves(tmp);
                    }
                    else if (mouseClickCounter == 1 && e.Button == MouseButtons.Left)
                    {
                        foreach (Move m in tmp)
                        {
                            if (m.getMovePosition().Item1 == x && m.getMovePosition().Item2 == y)
                            {
                                Piece tmpPiece = board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2];

                                if (tmpPiece.getPieceType() == (int)pieceType.whitePawn)
                                {
                                    tmpPiece.firstMoveOccurred();
                                    //this part handles pawn promotion
                                    if (x == 0)
                                    {
                                        if (m.isAttackMove())
                                        {
                                            KilledFromBlack(board.getBoardPieces()[x, y].getPieceType());
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                            playersound.Play();
                                        }
                                        else
                                        {
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                            playersound.Play();
                                        }
                                        board.getBoardPieces()[x, y] = new Queen(Tuple.Create(x, y), pieceType.whiteQueen, pieceColor.White);
                                        board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                        whiteMoveOccurred = true;
                                        break;
                                    }
                                    //this part handles  pawn move
                                    else
                                    {
                                        if (m.isAttackMove())
                                        {
                                            KilledFromBlack(board.getBoardPieces()[x, y].getPieceType());
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                            playersound.Play();
                                        }
                                        else
                                        {
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                            playersound.Play();
                                        }
                                        tmpPiece.setPiecePosition(x, y);
                                        board.getBoardPieces()[m.getMovePosition().Item1, m.getMovePosition().Item2]     = tmpPiece;
                                        board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                        whiteMoveOccurred = true;
                                        break;
                                    }
                                }
                                // this is for other pieces movements
                                else
                                {
                                    if (m.isAttackMove())
                                    {
                                        KilledFromBlack(board.getBoardPieces()[x, y].getPieceType());
                                        System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                        playersound.Play();
                                    }
                                    else
                                    {
                                        System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                        playersound.Play();
                                    }
                                    tmpPiece.setPiecePosition(x, y);
                                    board.getBoardPieces()[x, y] = tmpPiece;
                                    board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                    whiteMoveOccurred = true;
                                    break;
                                }
                            }
                        }
                        updateBoard();
                        if (whiteMoveOccurred)
                        {
                            whitePlayerActivePieces = player.getActivePlayerPieces(board);
                            whitePlayerLegalMoves   = player.getActivePlayerMoves(board, whitePlayerActivePieces);
                            player = new BlackPlayer();
                            blackPlayerActivePieces = player.getActivePlayerPieces(board);
                            blackPlayerLegalMoves   = player.getActivePlayerMoves(board, blackPlayerActivePieces);

                            if (blackPlayerActivePieces.Count() == 0)
                            {
                                MessageBox.Show("The game is over white player wins");
                            }

                            Tuple <int, int> blackPlayerKingPosition = board.getPlayerKingPosition(pieceColor.BLack);

                            if (player.kingInCheck(blackPlayerKingPosition, whitePlayerLegalMoves))
                            {
                                System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record2M_mp3cut);
                                playersound.Play();
                            }

                            whiteMoveOccurred = false;
                        }
                        mouseClickCounter = 0;
                    }
                }
                else
                {
                    if (mouseClickCounter == 0 && !board.isEmptyCell(x, y) && board.getBoardPieces()[x, y].getPieceColor() == pieceColor.White)
                    {
                        MessageBox.Show("It is black player turn");
                    }
                    else if (!board.isEmptyCell(x, y) && mouseClickCounter == 0 && e.Button == MouseButtons.Left)
                    {
                        ++mouseClickCounter;
                        tmp = board.getBoardPieces()[x, y].getLegalMovesWithCheck(board);
                        originalPiecePosition = Tuple.Create(x, y);
                        hightlightLegalMoves(tmp);
                    }
                    else if (mouseClickCounter == 1 && e.Button == MouseButtons.Left)
                    {
                        foreach (Move m in tmp)
                        {
                            if (m.getMovePosition().Item1 == x && m.getMovePosition().Item2 == y)
                            {
                                Piece tmpPiece = board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2];

                                if (tmpPiece.getPieceType() == (int)pieceType.blackPawn)
                                {
                                    tmpPiece.firstMoveOccurred();

                                    if (x == 7)
                                    {
                                        if (m.isAttackMove())
                                        {
                                            KilledFromWhite(board.getBoardPieces()[x, y].getPieceType());
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                            playersound.Play();
                                        }
                                        else
                                        {
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                            playersound.Play();
                                        }
                                        board.getBoardPieces()[x, y] = new Queen(Tuple.Create(x, y), pieceType.blackQueen, pieceColor.BLack);
                                        board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                        blackMoveOccurred = true;
                                        break;
                                    }
                                    else
                                    {
                                        if (m.isAttackMove())
                                        {
                                            KilledFromWhite(board.getBoardPieces()[x, y].getPieceType());
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                            playersound.Play();
                                        }
                                        else
                                        {
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                            playersound.Play();
                                        }
                                        tmpPiece.setPiecePosition(x, y);
                                        board.getBoardPieces()[m.getMovePosition().Item1, m.getMovePosition().Item2] = tmpPiece;

                                        board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                        blackMoveOccurred = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    if (!board.isEmptyCell(x, y))
                                    {
                                        KilledFromWhite(board.getBoardPieces()[x, y].getPieceType());
                                        System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                        playersound.Play();
                                    }
                                    else
                                    {
                                        System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                        playersound.Play();
                                    }
                                    tmpPiece.setPiecePosition(x, y);
                                    board.getBoardPieces()[x, y] = tmpPiece;
                                    board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                    blackMoveOccurred = true;
                                    break;
                                }
                            }
                        }
                        updateBoard();
                        if (blackMoveOccurred)
                        {
                            blackPlayerActivePieces = player.getActivePlayerPieces(board);
                            blackPlayerLegalMoves   = player.getActivePlayerMoves(board, blackPlayerActivePieces);
                            player = new WhitePlayer();
                            whitePlayerActivePieces = player.getActivePlayerPieces(board);
                            whitePlayerLegalMoves   = player.getActivePlayerMoves(board, whitePlayerActivePieces);
                            if (whitePlayerLegalMoves.Count() == 0)
                            {
                                MessageBox.Show("The game is over black player wins");
                            }

                            Tuple <int, int> whitePlayerKingPosition = board.getPlayerKingPosition(pieceColor.White);
                            if (player.kingInCheck(whitePlayerKingPosition, blackPlayerLegalMoves))
                            {
                                System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record2M_mp3cut);
                                playersound.Play();
                            }

                            blackMoveOccurred = false;
                        }
                        mouseClickCounter = 0;
                    }
                }
            }
            else if (!humanVsHuman)
            {
                if (player.getPlayerColor() == playerColor.White)
                {
                    if (mouseClickCounter == 0 && !board.isEmptyCell(x, y) && board.getBoardPieces()[x, y].getPieceColor() == pieceColor.BLack)
                    {
                        MessageBox.Show("It is white player turn");
                    }
                    else if (!board.isEmptyCell(x, y) && mouseClickCounter == 0 && e.Button == MouseButtons.Left)
                    {
                        ++mouseClickCounter;
                        tmp = board.getBoardPieces()[x, y].getLegalMovesWithCheck(board);
                        originalPiecePosition = Tuple.Create(x, y);
                        hightlightLegalMoves(tmp);
                    }
                    else if (mouseClickCounter == 1 && e.Button == MouseButtons.Left)
                    {
                        foreach (Move m in tmp)
                        {
                            if (m.getMovePosition().Item1 == x && m.getMovePosition().Item2 == y)
                            {
                                Piece tmpPiece = board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2];

                                if (tmpPiece.getPieceType() == (int)pieceType.whitePawn)
                                {
                                    tmpPiece.firstMoveOccurred();
                                    //this part handles pawn promotion
                                    if (x == 0)
                                    {
                                        if (m.isAttackMove())
                                        {
                                            KilledFromBlack(board.getBoardPieces()[x, y].getPieceType());
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                            playersound.Play();
                                        }
                                        else
                                        {
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                            playersound.Play();
                                        }
                                        board.getBoardPieces()[x, y] = new Queen(Tuple.Create(x, y), pieceType.whiteQueen, pieceColor.White);
                                        board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                        whiteMoveOccurred = true;
                                        break;
                                    }
                                    //this part handles  pawn move
                                    else
                                    {
                                        if (m.isAttackMove())
                                        {
                                            KilledFromBlack(board.getBoardPieces()[x, y].getPieceType());
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                            playersound.Play();
                                        }
                                        else
                                        {
                                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                            playersound.Play();
                                        }
                                        tmpPiece.setPiecePosition(x, y);
                                        board.getBoardPieces()[m.getMovePosition().Item1, m.getMovePosition().Item2]     = tmpPiece;
                                        board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                        whiteMoveOccurred = true;
                                        break;
                                    }
                                }
                                // this is for other pieces movements
                                else
                                {
                                    if (m.isAttackMove())
                                    {
                                        KilledFromBlack(board.getBoardPieces()[x, y].getPieceType());
                                        System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                        playersound.Play();
                                    }
                                    else
                                    {
                                        System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                        playersound.Play();
                                    }
                                    tmpPiece.setPiecePosition(x, y);
                                    board.getBoardPieces()[x, y] = tmpPiece;
                                    board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                                    whiteMoveOccurred = true;
                                    break;
                                }
                            }
                        }
                        updateBoard();
                        if (whiteMoveOccurred)
                        {
                            whitePlayerActivePieces = player.getActivePlayerPieces(board);
                            whitePlayerLegalMoves   = player.getActivePlayerMoves(board, whitePlayerActivePieces);
                            player = new BlackPlayer();
                            blackPlayerActivePieces = player.getActivePlayerPieces(board);
                            blackPlayerLegalMoves   = player.getActivePlayerMoves(board, blackPlayerActivePieces);

                            if (blackPlayerActivePieces.Count() == 0)
                            {
                                MessageBox.Show("The game is over white player wins");
                            }

                            Tuple <int, int> blackPlayerKingPosition = board.getPlayerKingPosition(pieceColor.BLack);

                            if (player.kingInCheck(blackPlayerKingPosition, whitePlayerLegalMoves))
                            {
                                System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record2M_mp3cut);
                                playersound.Play();
                            }

                            whiteMoveOccurred = false;
                        }
                        mouseClickCounter = 0;
                    }
                }
                else
                {
                    //this part handles Computer Play
                    Tuple <int, int, int, int> nextMove = Computer.getBestMove(board, gameDifficulty);
                    if (nextMove.Item1 == -1)
                    {
                        MessageBox.Show("THE GAME IS OVER YOU WIN");
                    }
                    //MessageBox.Show(nextMove.Item1.ToString() + nextMove.Item2.ToString() + nextMove.Item3.ToString() + nextMove.Item4.ToString());
                    Piece tmpPiece1 = board.getBoardPieces()[nextMove.Item1, nextMove.Item2];

                    if (tmpPiece1.getPieceType() == (int)pieceType.blackPawn)
                    {
                        tmpPiece1.firstMoveOccurred();
                        //this part handles pawn promotion
                        if (nextMove.Item3 == 7)
                        {
                            if (!board.isEmptyCell(nextMove.Item3, nextMove.Item4))
                            {
                                KilledFromWhite(board.getBoardPieces()[x, y].getPieceType());
                                System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                playersound.Play();
                            }
                            else
                            {
                                System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                playersound.Play();
                            }
                            board.getBoardPieces()[nextMove.Item3, nextMove.Item4] = new Queen(Tuple.Create(nextMove.Item3, nextMove.Item4), pieceType.blackQueen, pieceColor.BLack);
                            board.getBoardPieces()[originalPiecePosition.Item1, originalPiecePosition.Item2] = null;
                        }
                        //this part handles  pawn move
                        else
                        {
                            if (!board.isEmptyCell(nextMove.Item3, nextMove.Item4))
                            {
                                KilledFromWhite(board.getBoardPieces()[nextMove.Item3, nextMove.Item4].getPieceType());
                                System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                                playersound.Play();
                            }
                            else
                            {
                                System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                                playersound.Play();
                            }
                            tmpPiece1.setPiecePosition(nextMove.Item3, nextMove.Item4);
                            board.getBoardPieces()[nextMove.Item3, nextMove.Item4] = tmpPiece1;
                            board.getBoardPieces()[nextMove.Item1, nextMove.Item2] = null;
                        }
                    }
                    // this is for other pieces movements
                    else
                    {
                        if (!board.isEmptyCell(nextMove.Item3, nextMove.Item4))
                        {
                            KilledFromWhite(board.getBoardPieces()[nextMove.Item3, nextMove.Item4].getPieceType());
                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record20160425102455PM_mp3cut);
                            playersound.Play();
                        }
                        else
                        {
                            System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.recordM_mp3cut);
                            playersound.Play();
                        }
                        tmpPiece1.setPiecePosition(nextMove.Item3, nextMove.Item4);
                        board.getBoardPieces()[nextMove.Item3, nextMove.Item4] = tmpPiece1;
                        board.getBoardPieces()[nextMove.Item1, nextMove.Item2] = null;
                    }

                    updateBoard();
                    blackPlayerActivePieces = player.getActivePlayerPieces(board);
                    blackPlayerLegalMoves   = player.getActivePlayerMoves(board, blackPlayerActivePieces);
                    player = new WhitePlayer();
                    whitePlayerActivePieces = player.getActivePlayerPieces(board);
                    whitePlayerLegalMoves   = player.getActivePlayerMoves(board, whitePlayerActivePieces);

                    Tuple <int, int> whitePlayerKingPosition = board.getPlayerKingPosition(pieceColor.White);
                    if (player.kingInCheck(whitePlayerKingPosition, blackPlayerLegalMoves))
                    {
                        System.Media.SoundPlayer playersound = new System.Media.SoundPlayer(Properties.Resources.record2M_mp3cut);
                        playersound.Play();
                    }
                }
            }
        }
Esempio n. 28
0
 private void Start()
 {
     _humanPlayer = FindObjectOfType <HumanPlayer>();
 }
Esempio n. 29
0
 public GridVMBase(HumanPlayer humanPlayer, ComputerPlayer computerPlayer)
 {
     _humanPlayer    = humanPlayer;
     _computerPlayer = computerPlayer;
 }
 public async Task <Card> PromptPlayerCardSelection(HumanPlayer player, IReadOnlyList <Card> playableCards)
 {
     return(await _dispatcher.RunAsyncWithResult(CoreDispatcherPriority.Normal, async() => await _principalFrontend.PromptPlayerCardSelection(player, playableCards)));
 }
Esempio n. 31
0
 public override void SendEntryData(HumanPlayer sendHere, bool warping, IShip playerShip)
 {
 }
Esempio n. 32
0
        public MainWindowVM()
        {
            dice = new List<int>();
            status = new StringBuilder();
            addHuman = new DelegateCommand(() =>
            {
                var human = new HumanPlayer(startingDice);
                status.Insert(0, string.Format("{0} was added to the game\n", human));
                GameState.Instance.AddPlayer(human);
                Console.WriteLine("I did get hit");
                NotifyPropertyChanged("GameStatus");
                startGame.RaiseCanExecuteChanged();
            });

            addMonte = new DelegateCommand(() =>
            {
                var comp = new Monte(startingDice);
                status.Insert(0, string.Format("{0} was added to the game\n", comp));
                GameState.Instance.AddPlayer(comp);
                NotifyPropertyChanged("GameStatus");
                startGame.RaiseCanExecuteChanged();
            });

            addMaybeBluff = new DelegateCommand(() =>
            {
                var comp = new MaybeBluff(startingDice);
                status.Insert(0, string.Format("{0} was added to the game\n", comp));
                GameState.Instance.AddPlayer(comp);
                NotifyPropertyChanged("GameStatus");
                startGame.RaiseCanExecuteChanged();
            });

            addRandomMonte = new DelegateCommand(() =>
            {
                var comp = new RandomMonte(startingDice);
                status.Insert(0, string.Format("{0} was added to the game\n", comp));
                GameState.Instance.AddPlayer(comp);
                NotifyPropertyChanged("GameStatus");
                startGame.RaiseCanExecuteChanged();
            });

            startGame = new DelegateCommand(() =>
            {
                GameState.Instance.Rolling = true;
                roll.RaiseCanExecuteChanged();
                RollHandler();
            },
            ()=>
            {
                return GameState.Instance.TotalPlayers > 1;
            });

            call = new DelegateCommand(() =>
            {
                status.Insert(0, string.Format("{0} Calls.\n", GameState.Instance.CurrentTurn));
                status.Insert(0, GameState.Instance.GetAllRolls());
                var result = GameState.Instance.EndRound();
                status.Insert(0, string.Format("{0}.\n", result));
                dice = new List<int>();
                NotifyDiceChange();
                NotifyPropertyChanged("GameStatus");
                RoundHandler();
            //},
            //() => 
            //{
            //    return GameState.Instance.ValidMove(new PlayerMove() { Call = true });
            });

            guess = new DelegateCommand(async () =>
            {
                var move = new PlayerMove() { GuessAmount = amount, DiceNumber = diceValue };
                status.Insert(0, string.Format("{0} guesses {1}.\n", GameState.Instance.CurrentTurn, move));
                GameState.Instance.AddMove(move);
                GameState.Instance.EndTurn();
                NotifyPropertyChanged("GameStatus");
                dice = new List<int>();
                NotifyDiceChange();
                NotifyPropertyChanged("LastMove");
                await TurnHandler();
            //},
            //() =>
            //{
            //    return GameState.Instance.ValidMove(new PlayerMove() {DiceNumber = diceValue, GuessAmount = amount });
            });

            roll = new DelegateCommand(() =>
            {
                GameState.Instance.CurrentTurn.Roll();
                dice = GameState.Instance.CurrentTurn.hand;
                NotifyDiceChange();
                rollOk.RaiseCanExecuteChanged();
            },
            () =>
            {
                return GameState.Instance.Rolling;
            });

            rollOk = new DelegateCommand(() =>
            {
                GameState.Instance.EndTurn();
                dice = new List<int>();
                NotifyDiceChange();
                RollHandler();
            },
            () =>
            {
                return dice.Count != 0 && !dice.Contains(0) && GameState.Instance.Rolling; 
            });

            if (hideDice)
                diceVisibility = Visibility.Hidden;
            else
                diceVisibility = Visibility.Visible;
        }
Esempio n. 33
0
    private void AssignToTeam(HumanPlayer player)
    {
        var leastTeamMembers = this.Teams.Select(t => t.Players.Count).Min();
        var smallestTeam = this.Teams.First(t => t.Players.Count == leastTeamMembers);

        smallestTeam.Players.Add(player);

        AirConsole.instance.Message(player.DeviceId, new Message<string>(TEAM_MESSAGE, smallestTeam.Color));
    }
        public ActionResult Index(GameModel gameModel)
        {
            gameModel.GameResult = string.Empty;
            IPlayer player1 = null;
            IPlayer player2 = null;

            string playerChoices = string.Empty;

            // Set Player1
            if ( gameModel.Player1Move == PlayerMoveChoices.computer)
            {
                player1 = new ComputerPlayer();
            }
            else
            {
                player1 = new HumanPlayer();

                switch(gameModel.Player1Move)
                {
                    case PlayerMoveChoices.paper:
                        player1.Move = Move.Paper;
                        break;
                    case PlayerMoveChoices.scissors:
                        player1.Move = Move.Scissors;
                        break;
                    case PlayerMoveChoices.rock:
                        player1.Move = Move.Rock;
                        break;
                }
            }

            // Set Player2
            if (gameModel.Player2Move == PlayerMoveChoices.computer)
            {
                player2 = new ComputerPlayer();
            }
            else
            {
                throw new ApplicationException();
            }

            IGame game = new Game(player1, player2);
            GameResult gameResult = game.DecideWinner();

            string playerChoicesDescription = " (" + player1.Move.ToString() + "/" + player2.Move.ToString() + ")";

            switch(gameResult)
            {
                case GameResult.Draw:
                    gameModel.GameResult = "Draw " + playerChoicesDescription;
                    break;
                case GameResult.Player1Wins:
                    gameModel.GameResult = "Player 1 won " + playerChoicesDescription;
                    break;
                case GameResult.Player2Wins:
                    gameModel.GameResult = "Player 2 won " + playerChoicesDescription;
                    break;
            }

            return View(gameModel);
        }
Esempio n. 35
0
    protected void ShowCurrentMenu()
    {
        HumanPlayer myPlayer     = null;
        int         playersCount = playersList.transform.childCount;

        for (int i = 0; i < playersCount; i++)
        {
            myPlayer = playersList.transform.GetChild(i).GetComponent <HumanPlayer>();
            if (myPlayer.PlayerNumber == this.PlayerNumber)
            {
                break;
            }
        }

        if (myPlayer == null)
        {
            return;
        }

        switch (buildingType)
        {
        case MatIndex.BuildSite:
            buildSiteMenu.SetActive(true);
            break;

        case MatIndex.City:
            cityMenu.SetActive(true);
            cityMenu.GetComponentInChildren <Text>().text = "Income Addition " + (moneyGen * (moneyGen / 1000)).ToString();
            selected = true;
            break;

        case MatIndex.Barracks:
            dynamicBuildingMenu.SetActive(true);
            Debug.LogError(myPlayer.name);
            Debug.LogError(myPlayer.transform.GetChild(0).name);
            Debug.LogError(myPlayer.transform.GetChild(0).GetChild(0).name);
            dynamicBuildingMenu.GetComponent <DynamicBuildingMenu>().CreateMenu(myPlayer.gameObject.transform.GetChild(0).GetChild(0).gameObject);
            break;

        case MatIndex.Airport:
            dynamicBuildingMenu.SetActive(true);
            dynamicBuildingMenu.GetComponent <DynamicBuildingMenu>().CreateMenu(myPlayer.gameObject.transform.GetChild(0).GetChild(1).gameObject);
            break;

        default:
            break;
        }

        //if(faction == Faction.BASIC)
        //{
        //    switch(buildingType)
        //    {
        //        case MatIndex.BuildSite:
        //            buildSiteMenu.SetActive(true);
        //            break;
        //        case MatIndex.City:
        //            cityMenu.SetActive(true);
        //            cityMenu.GetComponentInChildren<Text>().text = "Income Addition " + (moneyGen * (moneyGen / 1000)).ToString();
        //            selected = true;
        //            break;
        //        case MatIndex.Barracks:
        //            basicRaxMenu.SetActive(true);
        //            break;
        //        case MatIndex.Airport:
        //            basicAirportMenu.SetActive(true);
        //            break;
        //        default:
        //            break;
        //    }
        //}
        //else if(faction == Faction.CHEAP)
        //{
        //    switch (buildingType)
        //    {
        //        case MatIndex.BuildSite:
        //            buildSiteMenu.SetActive(true);
        //            break;
        //        case MatIndex.City:
        //            cityMenu.SetActive(true);
        //            cityMenu.GetComponentInChildren<Text>().text = "Income Addition " + (moneyGen * (moneyGen / 1000)).ToString();
        //            selected = true;
        //            break;
        //        case MatIndex.Barracks:
        //            cheapRaxMenu.SetActive(true);
        //            break;
        //        case MatIndex.Airport:
        //            cheapAirportMenu.SetActive(true);
        //            break;
        //        default:
        //            break;
        //    }
        //}
    }
Esempio n. 36
0
 public void PassObject(HumanPlayer hp)
 {
     this.humanPlayer = hp;
 }
 public async Task <int> PromptPlayerBid(HumanPlayer player)
 {
     return(await _dispatcher.RunAsyncWithResult(CoreDispatcherPriority.Normal, async() => await _principalFrontend.PromptPlayerBid(player)));
 }
Esempio n. 38
0
 public WinRefereeShould()
 {
     _gameBoard      = new GameBoard();
     _humanPlayerOne = new HumanPlayer(Symbol.Nought, new InputChecker());
     _humanPlayerTwo = new HumanPlayer(Symbol.Cross, new InputChecker());
 }
Esempio n. 39
0
        /// <summary>
        /// Run all games chain.
        /// </summary>
        public void Run()
        {
            playerTwoAI = new AIPlayer();
            playerTwoAI.SetAllShips();

            playerOneHuman = new HumanPlayer();
            playerOneHuman.SetAllShips();

            playerTwoAI.SetEnemyField(playerOneHuman.HomeField);
            playerOneHuman.SetEnemyField(playerTwoAI.HomeField);


            Console.WriteLine("Корабли противника");
            PrintHomeField(playerTwoAI.HomeField);
            Console.WriteLine("\n\n");

            Console.WriteLine("Корабли ВАши");
            PrintHomeField(playerOneHuman.HomeField);

            int turnShooting = 1;

            while (!playerOneHuman.IsAllShipsHitted() || !playerTwoAI.IsAllShipsHitted())
            {
                int horizontalCoordinateShootingCell = 0;
                int verticalCoordinateShootingCell   = 0;

                if (turnShooting == 1)
                {
                    PrintEnemyField(playerOneHuman.EnemyField);
                    Console.WriteLine("Ваш ход. Формат ввода 1А");
                    char[] humanShootingCell = Console.ReadLine().Trim().ToCharArray();

                    horizontalCoordinateShootingCell = (Convert.ToInt32(humanShootingCell[1])) - 1;
                    switch (humanShootingCell[1])
                    {
                    case 'А': verticalCoordinateShootingCell = 0; break;

                    case 'Б': verticalCoordinateShootingCell = 1; break;

                    case 'В': verticalCoordinateShootingCell = 2; break;

                    case 'Г': verticalCoordinateShootingCell = 3; break;

                    case 'Д': verticalCoordinateShootingCell = 4; break;

                    case 'Е': verticalCoordinateShootingCell = 5; break;

                    case 'Ж': verticalCoordinateShootingCell = 6; break;

                    case 'З': verticalCoordinateShootingCell = 7; break;

                    case 'И': verticalCoordinateShootingCell = 8; break;

                    case 'К': verticalCoordinateShootingCell = 9; break;

                    default:
                        break;
                    }
                    if (playerOneHuman.ShootCell(horizontalCoordinateShootingCell, verticalCoordinateShootingCell))
                    {
                        Console.WriteLine("Вы попали, следующий ход опять ваш.");
                        turnShooting = 1;
                    }
                    else
                    {
                        Console.WriteLine("Увы, Вы не попали, следующий ход противника.");
                        turnShooting = 1;
                    }
                }
                else
                {
                    if (playerTwoAI.ShootCell(horizontalCoordinateShootingCell, verticalCoordinateShootingCell))
                    {
                        turnShooting = 1;
                    }
                    else
                    {
                        Console.WriteLine("Увы, Вы не попали, следующий ход противника.");
                        turnShooting = 2;
                    }
                }
            }
        }
Esempio n. 40
0
        private Player playerO()
        {
            Player playerO = new HumanPlayer('o');

            return(playerO);
        }
        public void return_player_name_default()
        {
            IPlayer player = new HumanPlayer();

            Assert.AreEqual(HumanPlayer.DEFAULT_NAME, player.GetName());
        }
 public void DeadPlayer(HumanPlayer player)
 {
     // Hard coded for single player
     UIManager.Instance.GameEndOptions.ShowDefeat();
     StartCoroutine(Defeat());
 }
Esempio n. 43
0
        private void OnStartGameClick(object sender, MouseButtonEventArgs e)
        {
            IPlayer player1;
            IPlayer player2;
            bool hasHuman = false;

            if (String.IsNullOrWhiteSpace(Vm.Player1Name))
            {
                MessageBox.Show("X Player must have a name", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (String.IsNullOrWhiteSpace(Vm.Player2Name))
            {
                MessageBox.Show("O Player must have a name", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            if (Player1Type.Text == "AI")
            {
                player1 = new AiPlayer(Vm.Player1Name, 400);
            }
            else
            {
                Player1Type.Text = "Human";
                player1 = new HumanPlayer(Vm.Player1Name);
                hasHuman = true;
            }
            if (Player2Type.Text == "AI")
            {
                player2 = new AiPlayer(Vm.Player2Name, 400);
            }
            else
            {
                Player2Type.Text = "Human";
                player2 = new HumanPlayer(Vm.Player2Name);
                hasHuman = true;
            }
            Vm.Reset(player1,player2);
            if (!hasHuman)
            {
            // ReSharper disable PossibleNullReferenceException
                (Vm.Game.Player1 as AiPlayer).TurnDelay = 800;
                (Vm.Game.Player2 as AiPlayer).TurnDelay = 800;
            // ReSharper restore PossibleNullReferenceException
            }
            Vm.Player1Name = player1.Name;
            Vm.Player2Name = player2.Name;
            SetupVisible = false;
            Vm.Start();
        }
Esempio n. 44
0
 // Methods to set the players
 public void SetHumanPlayer(HumanPlayer humanPlayer)
 {
     this.humanPlayer = humanPlayer;
     aIPlayer         = null;
     isActive         = true;
 }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            base.LoadContent();

            //create a new player and set the morito model to it.
            Player1 = new HumanPlayer(this, new Vector3(30, 20, 0)) { PlayersIndex = PlayerIndex.One };
            Player1.PlayersShip.ObjectModel = MoritoModel;
            //If we start having multiple meshes in our models, this may not work as intended.
            Player1.PlayersShip.BSphere = Player1.PlayersShip.ObjectModel.Meshes[0].BoundingSphere;
            Player1.PlayersShip.ReferenceCamera = Camera1;
            Collisions.Collidables.Add(Player1.PlayersShip);

            _player2 = new HumanPlayer(this, new Vector3(-30, -20, 0)) { PlayersIndex = PlayerIndex.Two };
            _player2.PlayersShip.ObjectModel = MoritoModel;
            //If we start having multiple meshes in our models, this may not work as intended.
            _player2.PlayersShip.BSphere = _player2.PlayersShip.ObjectModel.Meshes[0].BoundingSphere;
            _player2.PlayersShip.ReferenceCamera = Camera1;
            Collisions.Collidables.Add(_player2.PlayersShip);

            _objectsToBeWrapper.Add(Player1.PlayersShip);
            _objectsToBeWrapper.Add(_player2.PlayersShip);

            foreach (VisualObject3D piece in Level.Pieces)
            {
                _objectsToBeWrapper.Add(piece);
                //untested! Pieces that are collidable work, but untested with pieces that are not collidable. So untested if the the check works.
                if(piece is isCollidable)
                    Collisions.Collidables.Add((isCollidable)piece);
            }

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
Esempio n. 46
0
        private void ParseMap(string file)
        {
            try
            {
                var streamReader = new StreamReader("Content/Maps/" + file);
                string line = streamReader.ReadLine();
                string[] lineSplit = line.Split(' ');
                var parsedMapSize = new int[] { int.Parse(lineSplit[0]), int.Parse(lineSplit[1]) };

                var mapSize = new Point(parsedMapSize[0], parsedMapSize[1]);
                var tilesets = new List<Tileset>() { new Tileset(_mapTexture, 64, 32, 32, 32) };

                var collisionLayer = new bool[mapSize.X, mapSize.Y];
                var mapPlayersPosition = new int[mapSize.X, mapSize.Y];
                var map = new IEntity[mapSize.X, mapSize.Y];
                var layer = new MapLayer(mapSize.X, mapSize.Y);
                var voidPosition = new List<Point>();
                var playerPositions = new Dictionary<int, Point>();

                int j = 0;
                while (!streamReader.EndOfStream)
                {
                    line = streamReader.ReadLine();
                    Debug.Assert(line != null, "line != null");
                    lineSplit = line.Split(' ');
                    for (int i = 0; i < lineSplit.Length; i++)
                    {
                        int id = int.Parse(lineSplit[i]);
                        switch (id)
                        {
                            case 1:
                                var unbreakableWall = new UnbreakableWall(new Point(i, j));
                                map[i, j] = unbreakableWall;
                                UnbreakableWallList.Add(unbreakableWall);
                                collisionLayer[i, j] = true;
                                break;
                            case 2:
                                var edgeWall = new EdgeWall(new Point(i, j));
                                map[i, j] = edgeWall;
                                _edgeWallList.Add(edgeWall);
                                collisionLayer[i, j] = true;
                                break;
                            case 3:
                                var wall = new Wall(new Point(i, j));
                                _wallList.Add(wall);
                                map[i, j] = wall;
                                collisionLayer[i, j] = true;
                                break;
                            case 6:
                                var teleporter = new Teleporter(new Point(i, j));
                                map[i, j] = teleporter;
                                TeleporterList.Add(teleporter);
                                break;
                            case 7:
                                var arrow = new Arrow(new Point(i, j), LookDirection.Down);
                                ArrowList.Add(arrow);
                                map[i, j] = arrow;
                                break;
                            default:
                                if (id < 0 && Math.Abs(id) <= Config.PlayersNumber)
                                {
                                    playerPositions[Math.Abs(id)] = new Point(i, j);
                                }
                                break;
                        }
                    }
                    j++;
                }

                var mapLayers = new List<MapLayer> { layer };

                var tileMap = new TileMap(tilesets, mapLayers);
                Map level = null;//new Map(mapSize, tileMap, map, collisionLayer);

                World = new World(FinalBomber.Instance, FinalBomber.Instance.ScreenRectangle);
                World.Levels.Add(level);
                World.CurrentLevel = 0;

                foreach (int playerID in playerPositions.Keys)
                {
                    if (Config.AIPlayers[playerID])
                    {
                        var player = new AIPlayer(Math.Abs(playerID));
                        PlayerList.Add(player);
                        map[playerPositions[playerID].X, playerPositions[playerID].Y] = player;
                    }
                    else
                    {
                        var player = new HumanPlayer(Math.Abs(playerID), playerID);
                        PlayerList.Add(player);
                        map[playerPositions[playerID].X, playerPositions[playerID].Y] = player;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 47
0
		public async Task<IdentityResult> CreateAsync(HumanPlayer user)
        {
            var result = await _userManager.CreateAsync(user);

            return result;
        }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            base.LoadContent();

            if (players >= 1)
            {

                //create a new player and set the morito model to it.
                Player1 = new HumanPlayer(this, new Vector3(30, 20, 0)) { PlayersIndex = PlayerIndex.One };
                Player1.PlayersShip.ObjectModel = MoritoModel;
                //If we start having multiple meshes in our models, this may not work as intended.
                Player1.PlayersShip.BSphere = Player1.PlayersShip.ObjectModel.Meshes[0].BoundingSphere;
                Player1.PlayersShip.ReferenceCamera = Camera1;
                Collisions.Collidables.Add(Player1.PlayersShip);
                _objectsToBeWrapped.Add(Player1.PlayersShip);
            }

            if (players >= 2)
            {
                Player2 = new HumanPlayer(this, new Vector3(-30, -20, 0)) { PlayersIndex = PlayerIndex.Two };
                Player2.PlayersShip.ObjectModel = MoritoModel;
                //If we start having multiple meshes in our models, this may not work as intended.
                Player2.PlayersShip.BSphere = Player2.PlayersShip.ObjectModel.Meshes[0].BoundingSphere;
                Player2.PlayersShip.ReferenceCamera = Camera1;
                Collisions.Collidables.Add(Player2.PlayersShip);
                _objectsToBeWrapped.Add(Player2.PlayersShip);
            }

            if (players >= 3)
            {
                Player3 = new HumanPlayer(this, new Vector3(-50, -60, 0)) { PlayersIndex = PlayerIndex.Three };
                Player3.PlayersShip.ObjectModel = MoritoModel;
                //If we start having multiple meshes in our models, this may not work as intended.
                Player3.PlayersShip.BSphere = Player3.PlayersShip.ObjectModel.Meshes[0].BoundingSphere;
                Player3.PlayersShip.ReferenceCamera = Camera1;
                Collisions.Collidables.Add(Player3.PlayersShip);
                _objectsToBeWrapped.Add(Player3.PlayersShip);
            }

            if (players == 4)
            {
                Player4 = new HumanPlayer(this, new Vector3(50, 60, 0)) { PlayersIndex = PlayerIndex.Four };
                Player4.PlayersShip.ObjectModel = MoritoModel;
                //If we start having multiple meshes in our models, this may not work as intended.
                Player4.PlayersShip.BSphere = Player4.PlayersShip.ObjectModel.Meshes[0].BoundingSphere;
                Player4.PlayersShip.ReferenceCamera = Camera1;
                Collisions.Collidables.Add(Player4.PlayersShip);
                _objectsToBeWrapped.Add(Player4.PlayersShip);
            }

            foreach (VisualObject3D piece in Level.Pieces)
            {
                _objectsToBeWrapped.Add(piece);
                //untested! Pieces that are collidable work, but untested with pieces that are not collidable. So untested if the the check works.
                if(piece is isCollidable)
                    Collisions.Collidables.Add((isCollidable)piece);
            }

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();

            // Once all players have been created pass the screen to the hudManager to have
            // set up HUDs for active players
            hudManager.PlayerOne = Player1;
            hudManager.PlayerTwo = Player2;
            hudManager.PlayerThree = Player3;
            hudManager.PlayerFour = Player4;
            hudManager.initilizeHUD(this);
        }
Esempio n. 49
0
 public void SetAiPlayer(AIPlayer aiPlayer)
 {
     this.aIPlayer = aiPlayer;
     humanPlayer   = null;
     isActive      = true;
 }
Esempio n. 50
0
        private Player playerX()
        {
            Player playerX = new HumanPlayer('x');

            return(playerX);
        }
Esempio n. 51
0
        private void CreateWorld()
        {
            var tilesets = new List<Tileset>() { new Tileset(_mapTexture, 64, 32, 32, 32) };

            var collisionLayer = new bool[Config.MapSize.X, Config.MapSize.Y];
            var mapPlayersPosition = new int[Config.MapSize.X, Config.MapSize.Y];
            var map = new IEntity[Config.MapSize.X, Config.MapSize.Y];
            var layer = new MapLayer(Config.MapSize.X, Config.MapSize.Y);
            var voidPosition = new List<Point>();

            // Item Map
            IEntity entity;

            // List of player position
            var playerPositions = new Dictionary<int, Point>();

            // We don't put wall around the players
            for (int i = 0; i < Config.PlayersNumber; i++)
            {
                Point playerPosition = Config.PlayersPositions[i];
                playerPositions[i + 1] = playerPosition;

                mapPlayersPosition[playerPosition.X, playerPosition.Y] = 2;
                mapPlayersPosition[playerPosition.X + 1, playerPosition.Y] = 1;
                mapPlayersPosition[playerPosition.X, playerPosition.Y + 1] = 1;
                mapPlayersPosition[playerPosition.X, playerPosition.Y - 1] = 1;
                mapPlayersPosition[playerPosition.X - 1, playerPosition.Y] = 1;

                mapPlayersPosition[playerPosition.X - 1, playerPosition.Y - 1] = 1;
                mapPlayersPosition[playerPosition.X - 1, playerPosition.Y + 1] = 1;
                mapPlayersPosition[playerPosition.X + 1, playerPosition.Y - 1] = 1;
                mapPlayersPosition[playerPosition.X + 1, playerPosition.Y + 1] = 1;
            }

            /*
            entity = new Teleporter(FinalBomber.Instance, new Vector2(
                        5 * Engine.TileWidth,
                        1 * Engine.TileHeight));
            teleporterList.Add((Teleporter)entity);
            map[5,1] = entity;

            entity = new Teleporter(FinalBomber.Instance, new Vector2(
                        10 * Engine.TileWidth,
                        1 * Engine.TileHeight));
            teleporterList.Add((Teleporter)entity);
            map[10, 1] = entity;
            */

            for (int x = 0; x < Config.MapSize.X; x++)
            {
                for (int y = 0; y < Config.MapSize.Y; y++)
                {
                    if (!(x == 0 || y == 0 || x == (Config.MapSize.X - 1) || y == (Config.MapSize.Y - 1) ||
                        (x % 2 == 0 && y % 2 == 0)) && (mapPlayersPosition[x, y] != 1 && mapPlayersPosition[x, y] != 2))
                        voidPosition.Add(new Point(x, y));
                }
            }

            #region Teleporter
            if (Config.ActiveTeleporters)
            {
                if (Config.TeleporterPositionType == TeleporterPositionTypeEnum.Randomly)
                {
                    int randomVoid = 0;
                    for (int i = 0; i < MathHelper.Clamp(Config.TeleporterNumber, 0, voidPosition.Count - 1); i++)
                    {
                        randomVoid = Random.Next(voidPosition.Count);
                        entity = new Teleporter(new Point(
                            voidPosition[randomVoid].X,
                            voidPosition[randomVoid].Y));
                        TeleporterList.Add((Teleporter)entity);
                        map[voidPosition[randomVoid].X, voidPosition[randomVoid].Y] = entity;
                        voidPosition.Remove(voidPosition[randomVoid]);
                    }
                }
                else if (Config.TeleporterPositionType == TeleporterPositionTypeEnum.PlusForm)
                {
                    var teleporterPositions = new Point[]
                    {
                        new Point((int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)2), 1),
                        new Point(1, (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)2)),
                        new Point((int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)2), Config.MapSize.Y - 2),
                        new Point(Config.MapSize.X - 2, (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)2))
                    };

                    for (int i = 0; i < teleporterPositions.Length; i++)
                    {
                        entity = new Teleporter(new Point(
                            teleporterPositions[i].X,
                            teleporterPositions[i].Y));
                        TeleporterList.Add((Teleporter)entity);
                        map[teleporterPositions[i].X, teleporterPositions[i].Y] = entity;
                    }
                }
            }
            #endregion

            #region Arrow
            if (Config.ActiveArrows)
            {
                if (Config.ArrowPositionType == ArrowPositionTypeEnum.Randomly)
                {
                    var lookDirectionArray = new LookDirection[] { LookDirection.Up, LookDirection.Down, LookDirection.Left, LookDirection.Right };
                    for (int i = 0; i < MathHelper.Clamp(Config.ArrowNumber, 0, voidPosition.Count - 1); i++)
                    {
                        int randomVoid = Random.Next(voidPosition.Count);
                        entity = new Arrow(new Point(
                            voidPosition[randomVoid].X,
                            voidPosition[randomVoid].Y),
                            lookDirectionArray[Random.Next(lookDirectionArray.Length)]);
                        ArrowList.Add((Arrow)entity);
                        map[voidPosition[randomVoid].X, voidPosition[randomVoid].Y] = entity;
                        voidPosition.Remove(voidPosition[randomVoid]);
                    }
                }
                else if (Config.ArrowPositionType == ArrowPositionTypeEnum.SquareForm)
                {
                    int outsideArrowsLag = 0;
                    var ratio = (int)Math.Ceiling((double)(4 * (Config.MapSize.X - 2)) / (double)5);
                    if (ratio % 2 == 0)
                        outsideArrowsLag = 1;

                    var arrowPositions = new Point[]
                    {
                        // ~~ Inside ~~ //
                        // Top left
                        new Point(
                            (int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)4) + 1,
                            (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)4) + 1),

                        // Top right
                        new Point(
                            (int)Math.Ceiling((double)(3 * (Config.MapSize.X - 2))/(double)4) - 1,
                            (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)4) + 1),

                        // Bottom left
                        new Point(
                            (int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)4) + 1,
                            (int)Math.Ceiling((double)(3 * (Config.MapSize.Y - 2))/(double)4) - 1),

                        // Bottom right
                        new Point(
                            (int)Math.Ceiling((double)(3 * (Config.MapSize.X - 2))/(double)4) - 1,
                            (int)Math.Ceiling((double)(3 * (Config.MapSize.Y - 2))/(double)4) - 1),

                        // ~~ Outside ~~ //
                        // Top left
                        new Point(
                            (int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)5),
                            (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)5)),

                        // Top right
                        new Point(
                            (int)Math.Ceiling((double)(4 * (Config.MapSize.X - 2))/(double)5) + outsideArrowsLag,
                            (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)5)),

                        // Bottom left
                        new Point(
                            (int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)5),
                            (int)Math.Ceiling((double)(4 * (Config.MapSize.Y - 2))/(double)5) + outsideArrowsLag),

                        // Bottom right
                        new Point(
                            (int)Math.Ceiling((double)(4 * (Config.MapSize.X - 2))/(double)5 + outsideArrowsLag),
                            (int)Math.Ceiling((double)(4 * (Config.MapSize.Y - 2))/(double)5) + outsideArrowsLag)
                    };

                    for (int i = 0; i < arrowPositions.Length; i++)
                    {
                        entity = new Arrow(new Point(
                            arrowPositions[i].X,
                            arrowPositions[i].Y),
                            Config.ArrowLookDirection[i % 4]);
                        ArrowList.Add((Arrow)entity);
                        map[arrowPositions[i].X, arrowPositions[i].Y] = entity;
                    }
                }
            }
            #endregion

            int counter = 0;
            for (int x = 0; x < Config.MapSize.X; x++)
            {
                for (int y = 0; y < Config.MapSize.Y; y++)
                {
                    var tile = new Tile(0, 0);
                    if (x == 0 || y == 0 || x == (Config.MapSize.X - 1) || y == (Config.MapSize.Y - 1) ||
                        (x % 2 == 0 && y % 2 == 0))
                    {
                        // Inside wallList
                        if ((x % 2 == 0 && y % 2 == 0 && !(x == 0 || y == 0 || x == (Config.MapSize.X - 1) || y == (Config.MapSize.Y - 1))) && mapPlayersPosition[x, y] != 2)
                        {
                            entity = new UnbreakableWall(new Point(x, y));
                            this.UnbreakableWallList.Add((UnbreakableWall)entity);
                            map[x, y] = entity;
                            collisionLayer[x, y] = true;
                        }
                        // Outside wallList
                        else if (mapPlayersPosition[x, y] != 2)
                        {
                            entity = new EdgeWall(new Point(x, y));
                            this._edgeWallList.Add((EdgeWall)entity);
                            counter++;
                            map[x, y] = entity;
                            collisionLayer[x, y] = true;
                        }
                    }
                    else
                    {
                        // Wall
                        if ((mapPlayersPosition[x, y] != 1 && mapPlayersPosition[x, y] != 2) && map[x, y] == null &&
                            Random.Next(0, 100) < GameConfiguration.WallPercentage)
                        {
                            collisionLayer[x, y] = true;
                            entity = new Wall(new Point(x, y));
                            _wallList.Add((Wall)entity);
                            map[x, y] = entity;
                        }
                        //tile = new Tile(0, 0);
                    }
                    layer.SetTile(x, y, tile);
                }
            }

            var mapLayers = new List<MapLayer> { layer };

            var tileMap = new TileMap(tilesets, mapLayers);
            Map level = null;//new Map(Config.MapSize, tileMap, map, collisionLayer);

            World = new World(FinalBomber.Instance, FinalBomber.Instance.ScreenRectangle);
            World.Levels.Add(level);
            World.CurrentLevel = 0;

            foreach (int playerID in playerPositions.Keys)
            {
                if (Config.AIPlayers[playerID - 1])
                {
                    var player = new AIPlayer(Math.Abs(playerID));
                    PlayerList.Add(player);
                    map[playerPositions[playerID].X, playerPositions[playerID].Y] = player;
                }
                else
                {
                    var player = new HumanPlayer(Math.Abs(playerID), playerID);
                    PlayerList.Add(player);
                    map[playerPositions[playerID].X, playerPositions[playerID].Y] = player;
                }
            }
        }
Esempio n. 52
0
	public void AddPlayer(HumanPlayer player) {
		players.Add (player);
		active = true;
	}
Esempio n. 53
0
        public async Task <HumanPlayer> FindAsync(UserLoginInfo loginInfo)
        {
            HumanPlayer user = await _userManager.FindAsync(loginInfo);

            return(user);
        }
Esempio n. 54
0
        public async Task <HumanPlayer> FindUser(string userName, string password)
        {
            HumanPlayer user = await _userManager.FindAsync(userName, password);

            return(user);
        }
 protected override void Awake()
 {
     base.Awake();
     _player = GetComponent <HumanPlayer>();
 }
Esempio n. 56
0
 protected void Awake()
 {
     _player = GetComponent <HumanPlayer>();
 }
Esempio n. 57
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="card"></param>
 /// <param name="owner"></param>
 public StackCard(Card card, HumanPlayer owner)
 {
     _card  = card;
     _owner = owner;
 }
Esempio n. 58
0
 //Controller can have multiple human players
 public void Next(HumanPlayer player)
 {
     this.player = player;
 }
Esempio n. 59
0
        static void Main(string[] args)
        {
            // Create two players
            HumanPlayer    pA = new HumanPlayer();
            ComputerPlayer pB = new ComputerPlayer();

            pA.Name   = "User";
            pB.Name   = "AI";
            pA.Symbol = 'x';
            pB.Symbol = 'o';
            // Create two boards - with starting and with current fields
            char[,] startBoard = new char[, ] {
                { '7', '8', '9' },
                { '4', '5', '6' },
                { '1', '2', '3' }
            };

            /* char[,] gameBoardBoard = new char[,] {
             *   { '1', '2', '3' },
             *   { '4', '5', '6' },
             *   { '7', '8', '9' }
             * }; */
            char[,] gameBoard = startBoard.Clone() as char[, ];
            // Flags
            bool gameEnded   = false;
            bool player1Move = true; // true - player 1 move, false - player 2 move

            ////////////////////////////////////////////////////////////////////////////////
            // Loop over rounds
            for (int round = 0; round < gameBoard.Length; round++)
            {
                Console.Clear();
                Draw(gameBoard);
                if (player1Move)
                {
                    Console.WriteLine(pA.Name + " turn");
                    gameEnded   = pA.MakeMove(startBoard, gameBoard);
                    player1Move = false;
                }
                else
                {
                    Console.WriteLine(pB.Name + " turn");
                    gameEnded   = pB.MakeMove(startBoard, gameBoard);
                    player1Move = true;
                }
                if (gameEnded)
                {
                    break;
                }
            }
            ////////////////////////////////////////////////////////////////////////////////
            // End the game
            Console.Clear();
            Draw(gameBoard);
            Console.Write("Game ended! ");
            if (gameEnded)
            {
                Console.Write("Winner: ");
                if (player1Move)
                {
                    Console.WriteLine(pB.Name);
                }
                else
                {
                    Console.WriteLine(pA.Name);
                }
            }
            else
            {
                Console.WriteLine("A tie.");
            }
        }
Esempio n. 60
0
        public async Task <IdentityResult> CreateAsync(HumanPlayer user)
        {
            var result = await _userManager.CreateAsync(user);

            return(result);
        }