Exemplo n.º 1
0
        public void createHugeJson(
            Controller gameController,
            UserSettings userSettings,
            List <string> listHistory,
            List <Game.Cases.Case> caseDico,
            Goban goban
            )
        {
            List <int>  listCaseX           = new List <int>();
            List <int>  listCaseY           = new List <int>();
            List <uint> listCaseUsedAtRound = new List <uint>();
            List <bool> listCaseUsed        = new List <bool>();

            foreach (Game.Cases.Case newCase in caseDico)
            {
                listCaseX.Add(newCase.Position.X);
                listCaseY.Add(newCase.Position.Y);
                listCaseUsedAtRound.Add(newCase.UsedAtRound);
                listCaseUsed.Add(newCase.IsUsed);
            }

            hugeJson = new HugeJson(
                userSettings.GobanSize,
                gameController.Round,
                userSettings.MaxTimeForPlayer,
                gameController.PlayingNow,
                gameController.GamePaused,
                gameController.GameStarted,
                listHistory,
                goban.AllGoban,
                listCaseX,
                listCaseY,
                listCaseUsedAtRound,
                listCaseUsed,
                gameController.Player1.Name,
                gameController.Player2.Name,
                gameController.Player1.Color,
                gameController.Player2.Color,
                (uint)gameController.Player1.TimerValue,
                (uint)gameController.Player2.TimerValue,
                (ushort)gameController.Player1.Score,
                (ushort)gameController.Player2.Score
                );
        }
Exemplo n.º 2
0
        public void LoadFromHugeJson(JsonGenerator.HugeJson hugeJson)
        {
            // uncomment when the player name can be setted by the users
            labelPlayer1.Text = hugeJson.playerName1;
            labelPlayer2.Text = hugeJson.playerName2;

            buttonSave.Enabled = true;

            // The labels for the timers and scores will be automatically updated when timervalue will be setted

            casesDictionnary.resetDico();
            for (int index = 0; index < hugeJson.caseDicoX.Count; index++)
            {
                casesDictionnary.useCase(new Vector2D(hugeJson.caseDicoX[index], hugeJson.caseDicoY[index]), hugeJson.caseDicoUsedAtRound[index]);
                if (!hugeJson.caseDicoUsed[index])
                {
                    casesDictionnary.unUseCase(new Vector2D(hugeJson.caseDicoX[index], hugeJson.caseDicoY[index]), hugeJson.caseDicoUsedAtRound[index]);
                }
            }

            foreach (string text in hugeJson.gameHistory)
            {
                listViewHistory.Items.Add(text);
            }
            if (listViewHistory.Items.Count > 0)                                // if Items.Count == 0 it throw an error (index can't be '-1')
            {
                listViewHistory.EnsureVisible(listViewHistory.Items.Count - 1); // set the index to the last one, it always display the last move
            }

            if (hugeJson.gameStarted)
            {
                buttonStart.Enabled = false;
            }
            else
            {
                buttonStart.Enabled = true;
            }

            if (hugeJson.gamePaused)
            {
                buttonPause.Text = "Reprendre";
            }
            else
            {
                buttonPause.Text = "Pause";
            }
            if (gameController.WhoIsPlayingBool())
            {
                pictureBoxPlaynowBlack.Visible = true;
                pictureBoxPlaynowWhite.Visible = false;
            }
            else
            {
                pictureBoxPlaynowBlack.Visible = false;
                pictureBoxPlaynowWhite.Visible = true;
            }

            // reset the goban with the new layout
            Panel panel = searchGobanPanelAndRemoveAllChilds();

            initGoban(panel);


            for (int indexX = 0; indexX < hugeJson.goban.Count; indexX++)
            {
                for (int indexY = 0; indexY < hugeJson.goban[indexX].Count; indexY++)
                {
                    if (hugeJson.goban[indexX][indexY] == 0)
                    {
                        continue;
                    }
                    if (hugeJson.goban[indexX][indexY] == 1)
                    {
                        ((PictureBox)Controls.Find(indexX + "." + indexY, true)[0]).Image = Image.FromFile(imageAjuster.getImageGobanFromPos(indexX, indexY, userSettings.GobanSize) + "_black.png");
                    }
                    else
                    {
                        ((PictureBox)Controls.Find(indexX + "." + indexY, true)[0]).Image = Image.FromFile(imageAjuster.getImageGobanFromPos(indexX, indexY, userSettings.GobanSize) + "_white.png");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void DeserializeFile(string filename)
        {
            string jsonFile = File.ReadAllText(filename);

            hugeJson = JsonConvert.DeserializeObject <HugeJson>(jsonFile);
        }