コード例 #1
0
ファイル: mqtt.cs プロジェクト: mikository/mqtt-game
        public void Shoot(char x, int y, string player, string region)
        {
            WeaponFireComm c   = new WeaponFireComm(x, y);
            string         msg = JsonConvert.SerializeObject(c);

            client.Publish(gametopic + "/" + region + "/" + player, Encoding.ASCII.GetBytes(msg));
        }
コード例 #2
0
ファイル: game.cs プロジェクト: mikository/mqtt-game
        private void M_ShotRecieved(object sender, EventArgs e)
        {
            if (!myTurn)
            {
                WeaponFireComm c   = (WeaponFireComm)sender;
                HitResponse    res = me.Battlefield.Hit(new Coords(getIntFromLetter(c.x), c.y));

                switch (res)
                {
                case HitResponse.Hit:
                    m.RespondToShot(FireResponse.hit, c.x, c.y, opponent.fleetName, this.region);
                    // myTurn = false;
                    break;

                case HitResponse.Miss:
                    m.RespondToShot(FireResponse.miss, c.x, c.y, opponent.fleetName, this.region);
                    //myTurn = true;
                    break;

                case HitResponse.Destroy:
                    //myTurn = false;
                    m.RespondToShot(FireResponse.hit, c.x, c.y, opponent.fleetName, this.region, me.isFleetDestroyed() ? FireResult.fleetdestroyed : FireResult.sunk);
                    break;

                default:
                    break;
                }
                if (me.isFleetDestroyed())
                {
                    Lost.Invoke(me, EventArgs.Empty);
                }

                myTurn = true;
            }
        }