Exemplo n.º 1
0
        // Return if one of the players or none won the game
        private static async Task <ESidesInGame> WinningInGame(SingleMatch gameObject)
        {
            ESidesInGame returnResult = ESidesInGame.None;

            await Task.Run(() =>
            {
                try
                {
                    // If Player A reached to 40 points
                    if (gameObject.ScorePlayerA == 4)
                    {
                        returnResult = ESidesInGame.PlayerA;
                    }
                    // If Player B reached to 40 points
                    else if (gameObject.ScorePlayerB == 4)
                    {
                        returnResult = ESidesInGame.PlayerB;
                    }
                    // None of the players won the game
                    else
                    {
                        returnResult = ESidesInGame.None;
                    }
                }
                catch
                {
                    returnResult = ESidesInGame.None;
                }
            });

            return(returnResult);
        }
    // Update is called once per frame
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {
            PhotonNetwork.Instantiate("ParticleFab", other.gameObject.transform.position, Quaternion.identity, 0);

            var spawnpoints       = GameObject.FindGameObjectsWithTag("Spawnpoint");
            int randomSpawnNumber = Random.Range(0, spawnpoints.Length);
            other.gameObject.transform.position = spawnpoints[randomSpawnNumber].transform.position;
            other.gameObject.transform.rotation = spawnpoints[randomSpawnNumber].transform.rotation;

            if (Application.loadedLevelName.Equals("SinglePlayer"))
            {
                SingleMatch rb = GameObject.Find("Scripts").GetComponent <SingleMatch>();
                rb.enemyScore--;
                rb.UpdateScore();
            }
        }
        if (other.gameObject.CompareTag("Player"))
        {
            PhotonNetwork.Instantiate("ParticleFab", other.gameObject.transform.position, Quaternion.identity, 0);

            var spawnpoints       = GameObject.FindGameObjectsWithTag("Spawnpoint");
            int randomSpawnNumber = Random.Range(0, spawnpoints.Length);
            other.gameObject.transform.position = spawnpoints[randomSpawnNumber].transform.position;
            other.gameObject.transform.rotation = spawnpoints[randomSpawnNumber].transform.rotation;

            if (Application.loadedLevelName.Equals("SinglePlayer"))
            {
                SingleMatch rb = GameObject.Find("Scripts").GetComponent <SingleMatch>();
                rb.playerScore--;
                rb.UpdateScore();
            }
        }
    }
Exemplo n.º 3
0
        public async Task TestAddPointsToPlayers1()
        {
            // Arrange
            SingleMatch match = new SingleMatch()
            {
                MatchID           = 8,
                NamePlayerA       = "Player A",
                NamePlayerB       = "Player B",
                ScorePlayerA      = 3,
                ScorePlayerB      = 3,
                AdvantageToPlayer = ESidesInGame.PlayerA,
                WinnerInMatch     = ESidesInGame.None,
                Set1 = new SingleSetInMatch()
                {
                    ScorePlayerA = 0,
                    ScorePlayerB = 0,
                    WinnerInSet  = ESidesInGame.None
                },
                Set2 = new SingleSetInMatch()
                {
                    ScorePlayerA = 0,
                    ScorePlayerB = 0,
                    WinnerInSet  = ESidesInGame.None
                },
                Set3 = new SingleSetInMatch()
                {
                    ScorePlayerA = 0,
                    ScorePlayerB = 0,
                    WinnerInSet  = ESidesInGame.None
                }
            };
            var gameData = Newtonsoft.Json.JsonConvert.SerializeObject(match);

            // Act
            string matchStr = await ScoreCalculations.CreateNemGame();

            SingleMatch matchObj      = Newtonsoft.Json.JsonConvert.DeserializeObject <SingleMatch>(matchStr);
            int         currentGameId = matchObj.MatchID;

            for (int i = 0; i < 3; i++)
            {
                matchStr = await ScoreCalculations.PlayerWinningPoint(currentGameId, ESidesInGame.PlayerA);
            }
            for (int i = 0; i < 3; i++)
            {
                matchStr = await ScoreCalculations.PlayerWinningPoint(currentGameId, ESidesInGame.PlayerB);
            }
            matchStr = await ScoreCalculations.PlayerWinningPoint(currentGameId, ESidesInGame.PlayerA);

            matchObj         = Newtonsoft.Json.JsonConvert.DeserializeObject <SingleMatch>(matchStr);
            matchObj.MatchID = 8;
            var actual = Newtonsoft.Json.JsonConvert.SerializeObject(matchObj);

            // Assert
            Assert.AreEqual(gameData, actual);
        }
Exemplo n.º 4
0
        public void Render(BillettServiceEvent bsEvent, int width = 460, int height = 650)
        {
            var ctrl = new SingleMatch {
                DataContext = _vm = new SingleMatchViewmodel(bsEvent)
            };

            var path = Path.Combine(StautConfiguration.Current.StaticImageDirectory, bsEvent.EventNumber + ".png");

            RenderAndSave(ctrl, path, width, height);
        }
Exemplo n.º 5
0
        public async Task TestFailCreateNewGame()
        {
            // Arrange
            SingleMatch match = new SingleMatch();

            match.MatchID = int.MaxValue;
            var gameData = Newtonsoft.Json.JsonConvert.SerializeObject(match);

            // Act
            string actual = await ScoreCalculations.CreateNemGame();

            // Assert
            Assert.AreNotEqual(gameData, actual);
        }
Exemplo n.º 6
0
        // Check and update if one of the players or none won the match
        private static async Task WinningInMatch(SingleMatch match)
        {
            await Task.Run(() =>
            {
                // If the same player won the 2 first sets - no need for the 3rd, the result won't be changed
                if (match.Set1.WinnerInSet != ESidesInGame.None && match.Set2.WinnerInSet != ESidesInGame.None && match.Set1.WinnerInSet == match.Set2.WinnerInSet)
                {
                    // Update the winner
                    match.WinnerInMatch = match.Set1.WinnerInSet == ESidesInGame.PlayerA ? ESidesInGame.PlayerA : ESidesInGame.PlayerB;
                }
                // If all 3 sets were over
                else if (match.Set1.WinnerInSet != ESidesInGame.None && match.Set2.WinnerInSet != ESidesInGame.None && match.Set3.WinnerInSet != ESidesInGame.None)
                {
                    int playerA_Winnings = 0;
                    int playerB_Winnings = 0;

                    // Count winnings of the players
                    if (match.Set1.WinnerInSet == ESidesInGame.PlayerA)
                    {
                        playerA_Winnings++;
                    }
                    else
                    {
                        playerB_Winnings++;
                    }

                    if (match.Set2.WinnerInSet == ESidesInGame.PlayerA)
                    {
                        playerA_Winnings++;
                    }
                    else
                    {
                        playerB_Winnings++;
                    }

                    if (match.Set3.WinnerInSet == ESidesInGame.PlayerA)
                    {
                        playerA_Winnings++;
                    }
                    else
                    {
                        playerB_Winnings++;
                    }

                    // Update the winner
                    match.WinnerInMatch = playerA_Winnings > playerB_Winnings ? ESidesInGame.PlayerA : ESidesInGame.PlayerB;
                }
            });
        }
Exemplo n.º 7
0
        public async Task TestSuccessCreateNewGame()
        {
            // Arrange
            SingleMatch match = new SingleMatch()
            {
                MatchID           = 8,
                NamePlayerA       = "Player A",
                NamePlayerB       = "Player B",
                ScorePlayerA      = 0,
                ScorePlayerB      = 0,
                AdvantageToPlayer = ESidesInGame.None,
                WinnerInMatch     = ESidesInGame.None,
                Set1 = new SingleSetInMatch()
                {
                    ScorePlayerA = 0,
                    ScorePlayerB = 0,
                    WinnerInSet  = ESidesInGame.None
                },
                Set2 = new SingleSetInMatch()
                {
                    ScorePlayerA = 0,
                    ScorePlayerB = 0,
                    WinnerInSet  = ESidesInGame.None
                },
                Set3 = new SingleSetInMatch()
                {
                    ScorePlayerA = 0,
                    ScorePlayerB = 0,
                    WinnerInSet  = ESidesInGame.None
                }
            };
            var gameData = Newtonsoft.Json.JsonConvert.SerializeObject(match);

            // Act
            string matchStr = await ScoreCalculations.CreateNemGame();

            SingleMatch matchObj = Newtonsoft.Json.JsonConvert.DeserializeObject <SingleMatch>(matchStr);

            matchObj.MatchID = 8;
            var actual = Newtonsoft.Json.JsonConvert.SerializeObject(matchObj);

            // Assert
            Assert.AreEqual(gameData, actual);
        }
Exemplo n.º 8
0
        public void Render(BillettServiceEvent bsEvent, int width = 460, int height = 650)
        {
            var ctrl = new SingleMatch {
                DataContext = _vm = new SingleMatchViewmodel(bsEvent)
            };

            var path = Path.Combine(StautConfiguration.Current.StaticImageDirectory, bsEvent.EventNumber + ".png");

            Trace.TraceInformation("Rendering {0}x{1} chart for event {2} to {3}", width, height, bsEvent.EventNumber, path);

            var sw = new Stopwatch();

            sw.Start();

            RenderAndSave(ctrl, path, width, height);

            sw.Stop();
            Trace.TraceInformation("Chart render took {0}ms", sw.ElapsedMilliseconds);
        }
Exemplo n.º 9
0
        public AISelect(SingleMatch parent)
        {
            InitializeComponent();

            if (User.Locale != "ko")
            {
                ai1.Text = "Black AI vs White User";
                ai2.Text = "Black User vs White AI";
            }

            _parent = parent;

            //switch(User.myInfo.ai_rule)
            //{
            //    case 1:
            //        gomoku.IsChecked = true;
            //        break;
            //    case 2:
            //        normal.IsChecked = true;
            //        break;
            //    case 3:
            //        renju.IsChecked = true;
            //        break;
            //}

            //렌주룰로 고정
            User.myInfo.ai_rule = 3;

            switch (User.myInfo.ai_mode)
            {
            case 1:
                ai1.IsChecked = true;
                break;

            case 2:
                ai2.IsChecked = true;
                break;
            }
        }
Exemplo n.º 10
0
        public static async Task <string> CreateNemGame()
        {
            string gameData = string.Empty;

            await Task.Run(() =>
            {
                try
                {
                    if (!Directory.Exists(DbDirectory))
                    {
                        Directory.CreateDirectory(DbDirectory);
                    }

                    int idIndex = 0;

                    // Get the highest index of DB file to increase it with 1 and create a new game file
                    FileInfo[] allDbFiles = new DirectoryInfo(DbDirectory).GetFiles();
                    foreach (var file in allDbFiles)
                    {
                        int currentFileIndex = int.Parse(file.Name.Replace(".txt", ""));
                        if (currentFileIndex > idIndex)
                        {
                            idIndex = currentFileIndex;
                        }
                    }
                    // Create a new empty game object with the new index of file
                    SingleMatch match = new SingleMatch()
                    {
                        MatchID           = ++idIndex,
                        NamePlayerA       = "Player A",
                        NamePlayerB       = "Player B",
                        ScorePlayerA      = 0,
                        ScorePlayerB      = 0,
                        AdvantageToPlayer = ESidesInGame.None,
                        WinnerInMatch     = ESidesInGame.None,
                        Set1 = new SingleSetInMatch()
                        {
                            ScorePlayerA = 0,
                            ScorePlayerB = 0,
                            WinnerInSet  = ESidesInGame.None
                        },
                        Set2 = new SingleSetInMatch()
                        {
                            ScorePlayerA = 0,
                            ScorePlayerB = 0,
                            WinnerInSet  = ESidesInGame.None
                        },
                        Set3 = new SingleSetInMatch()
                        {
                            ScorePlayerA = 0,
                            ScorePlayerB = 0,
                            WinnerInSet  = ESidesInGame.None
                        }
                    };
                    gameData = Newtonsoft.Json.JsonConvert.SerializeObject(match);
                    File.WriteAllText($"{DbDirectory}\\{idIndex}.txt", gameData); // Write the data of the game to the game file
                }
                catch
                {
                    gameData = string.Empty;
                }
            });

            return(gameData);
        }
Exemplo n.º 11
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {
            // instantiate eplosion effect
            PhotonNetwork.Instantiate("ParticleFab", other.gameObject.transform.position, Quaternion.identity, 0);


            // destroy the bullet
            if (PhotonNetwork.offlineMode)
            {
                Destroy(gameObject);
            }
            else
            {
                PhotonNetwork.Destroy(gameObject);
            }

            // destroy enemy game object
            if (PhotonNetwork.offlineMode)
            {
                SingleMatch.objectsToHide.Remove(gameObject);
                Destroy(other.gameObject);
            }
            else
            {
                PhotonNetwork.Destroy(other.gameObject);
            }



            if (Application.loadedLevelName.Equals("SinglePlayer"))
            {
                //
                // Create new enemy game object
                //
                Debug.Log("starting coroutine in main script");
                SingleMatch rb = GameObject.Find("Scripts").GetComponent <SingleMatch>();
                rb.CreateNewAI();                 // createNewAI could not be static

                //
                // Opdate Scrore
                //
                rb.playerScore++;
                rb.UpdateScore();
            }
        }
        if (other.gameObject.CompareTag("Player"))
        {
            PhotonView otherPhotonView = PhotonView.Get(other.gameObject);

            var spawnpoints = GameObject.FindGameObjectsWithTag("Spawnpoint");

            // Code to make shure the spawn is not to close to the previous spawn
            // TODO: this code is not working as planed
            randomSpawnNumber = Random.Range(0, spawnpoints.Length);
            while (randomSpawnNumber <= previousRandomSpawnNumber + 4 && randomSpawnNumber >= previousRandomSpawnNumber - 4)
            {
                randomSpawnNumber = Random.Range(0, spawnpoints.Length);
            }
            previousRandomSpawnNumber = randomSpawnNumber;


            if (Application.loadedLevelName.Equals("SinglePlayer"))
            {
                SingleMatch rb = GameObject.Find("Scripts").GetComponent <SingleMatch>();
                rb.enemyScore++;
                rb.UpdateScore();
            }



            if (!otherPhotonView.isMine)
            {
                //	Debug.Log("otherPhotonView NOT mine");

                // Add a particle prefab to show an explosion
                // TODO: needs to be destroyed after effect
                PhotonNetwork.Instantiate("ParticleFab", other.gameObject.transform.position, Quaternion.identity, 0);

                // Position and visibility, after respawn, needs to be set on other clients
                // TODO: Only other player should have visibility to false
                otherPhotonView.gameObject.transform.root.GetComponent <CarDriver>().visibility(false);
                otherPhotonView.transform.position = spawnpoints[randomSpawnNumber].transform.position;
                otherPhotonView.transform.rotation = spawnpoints[randomSpawnNumber].transform.rotation;

                // Update scoreboard
                PhotonView carView = other.gameObject.transform.root.GetComponent <PhotonView>();

                // Add a hit to the score to the car being hit
                photonView.RPC("UpdateScore", PhotonTargets.AllBuffered, carView.owner.ID, 1);
            }
            else
            {
                //	Debug.Log("otherPhotonView IS mine" + Time.deltaTime);

                // Set other object in this network instance to new position
                // had to remove bullet lerp to make shure this would always fire
                other.gameObject.transform.root.GetComponent <CarDriver>().visibility(false);
                other.gameObject.transform.position = spawnpoints[randomSpawnNumber].transform.position;
                other.gameObject.transform.rotation = spawnpoints[randomSpawnNumber].transform.rotation;
            }
        }
    }