}//ShowBoard

        public override Task <GameState> PlayTurn(PlaceUnit unit, ServerCallContext context)
        {
            return(Task.FromResult(new GameState
            {
                Valid = _board.Insert(unit.Row, unit.Col, unit.Unit),
                Board = _board.ToString()
            }));
        }//PlayTurn
Exemple #2
0
        }//PlayGame

        /// <summary>
        /// Turn functionality.
        /// If user turn, prompts for row, then column, then attempts to insert at chosen location.
        /// If AI turn, generates 2 random integers from 0 to 3 for row and column, then attempts to insert at that location.
        /// </summary>
        /// <param name="player">X or O to place</param>
        /// <param name="rng">Randum number generator. If null, it is user turn. If it exists, AI turn.</param>
        private async static Task TurnAsync(string player, TicTacToeServ.TicTacToeServClient client, Random rng = null)
        {
            int       row = -1, col = -1;
            bool      valid   = false;
            PlaceUnit toPlace = new PlaceUnit();

            toPlace.Unit = player;

            do                  //attempt to place token, repeat until valid location chosen
            {
                var board = await client.ShowBoardAsync(new Null { });

                Console.WriteLine(board.Board);
                if (rng == null) //if rng is null, we're processing player actions
                {
                    while (!valid)
                    {
                        Console.Write("Please enter the row you wish to place in: ");
                        valid = Int32.TryParse(Console.ReadLine(), out row);
                    }
                    valid = valid ^ valid;
                    while (!valid)
                    {
                        Console.Write("Please enter the column you wish to place in: ");
                        valid = Int32.TryParse(Console.ReadLine(), out col);
                    }
                    toPlace.Row = row;
                    toPlace.Col = col;
                }//if
                else            //if rng is not null, it's ai move
                {
                    row         = rng.Next(0, 3);
                    col         = rng.Next(0, 3);
                    toPlace.Row = row;
                    toPlace.Col = col;
                }//else

                var gamestate = await client.PlayTurnAsync(toPlace);

                valid = gamestate.Valid;
                if (!valid)
                {
                    if (rng != null)
                    {
                        Console.WriteLine("Invalid choice by AI. Rechoosing..)");
                    }
                    else
                    {
                        Console.WriteLine("Invalid choice. Please choose again.");
                    }
                }
            } while (!valid);
        } //Turn(Socket, TicTacToeBoard, string, Random)
Exemple #3
0
 public void StorePlaceUnit(PlaceUnit pu)
 {
     PlayerPrefs.SetString("PlaceUnit" + pu.unitId + "Para", pu.actionParam);
     for (int i = 0; i < p.Length; i++)
     {
         if (p [i].unitId == pu.unitId)
         {
             p [i].actionParam = pu.actionParam;
             break;
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            if (combat == true)
            {
                this.IsMouseVisible = true;
                puzzle.Update(gameTime);
            }
            else
            {
                this.IsMouseVisible = false;

                select.Move(Keyboard.GetState(), Mouse.GetState(), gameTime);

                bool ifSelect = select.Select(Mouse.GetState(), Keyboard.GetState(), gameTime);

                if (ifSelect == true && (place == null || select._posSelect != place._posPerso))
                {
                    Unit currUnit = new Unit(units.Last());
                    currUnit._position = select._posSelect;


                    if (units.Contains(currUnit))
                    {
                        int id = units.IndexOf(currUnit);

                        place = new PlaceUnit(Content.Load <Texture2D>("_images_/fleche_move"),
                                              Content.Load <Texture2D>("_images_/case_deplace"), map, units, currUnit._position);
                    }
                }
                if (ifSelect == true && place != null)
                {
                    place.Tracer_chemin(select._position);

                    if (place.Place(Mouse.GetState(), Keyboard.GetState(), gameTime))
                    {
                        place             = null;
                        select._select    = false;
                        select._posSelect = select._position;
                    }
                }
            }
            base.Update(gameTime);
        }
Exemple #5
0
    public void LoadPlaces(bool isRebirth)
    {
//		Debug.Log ("正在读取数据*******************************************");
        PlaceDic = new Dictionary <int, Places> ();
        string[][] strs = ReadTxt.ReadText("places");
        p = new PlaceUnit[strs.Length - 1];
        for (int i = 0; i < p.Length; i++)
        {
            p [i]            = new PlaceUnit();
            p [i].unitId     = int.Parse(ReadTxt.GetDataByRowAndCol(strs, i + 1, 0));
            p [i].actionType = int.Parse(ReadTxt.GetDataByRowAndCol(strs, i + 1, 1));

            string s = "PlaceUnit" + p [i].unitId.ToString() + "Para" + (isRebirth ? "_Memory" : "");
            if (PlayerPrefs.GetString(s, "") == "")
            {
                p [i].actionParam = 1 + ";" + ReadTxt.GetDataByRowAndCol(strs, i + 1, 2);
            }
            else
            {
                p [i].actionParam = PlayerPrefs.GetString(s, "");
            }
            p [i].name = ReadTxt.GetDataByRowAndCol(strs, i + 1, 3);
            p [i].desc = ReadTxt.GetDataByRowAndCol(strs, i + 1, 4);
        }

        for (int i = 0; i < MapDic.Count; i++)
        {
            Places ps = new Places();
            ps.id = MapDic [i].id;
            for (int j = 0; j < p.Length; j++)
            {
                if ((int)(p [j].unitId / 100) == ps.id)
                {
                    ps.placeUnits.Add(p [j]);
                }
            }
            PlaceDic.Add(ps.id, ps);
        }
    }