private bool IWin(Game.Engine.Game game)
 {
     GameStats stats= this.gameData.GetGameStats();
     switch (this.gameData.GetCurrentTurn()) // my color
     {
         case TileType.yellow:
             return (stats.YellowCount > stats.BlueCount && stats.YellowCount > stats.RedCount);
         case TileType.blue:
             return (stats.BlueCount > stats.YellowCount && stats.BlueCount > stats.RedCount);
         case TileType.red:
             return (stats.RedCount > stats.YellowCount && stats.RedCount > stats.BlueCount);
     }
     return false;
 }
        public void StartNewGame(GameConfiguration configuration)
        {
            File.Delete(HostingEnvironment.MapPath("/App_Data/TIC.log"));
            logger.Debug("StartNewGame()");
            try
            {
                current = null;
                if (File.Exists(Filename(configuration.GameId)))
                {
                    File.Delete(Filename(configuration.GameId));
                }

                current = new Game(configuration);
                LoadLevel();

                this.SaveGame(configuration.GameId);
            }
            catch (Exception e)
            {
                logger.Error(e);
                throw;
            }
        }
Ejemplo n.º 3
0
 private HexagonTile GetClone(HexagonTile tile, Game target)
 {
     if (this.hexagonList.IndexOf(tile) >= 0)
     {
         return target.hexagonList[this.hexagonList.IndexOf(tile)];
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a clone of this object.
        /// </summary>
        /// <returns>A new object witg cloned data</returns>
        public Game Clone()
        {
            Game target = new Game(this.Configuration);

            // first step: set basic info
            for (int i = 0; i < this.hexagonList.Count; i++)
            {
                target.hexagonList.Add(new HexagonTile()
                {
                    Id = this.hexagonList[i].Id,
                    TileType = this.hexagonList[i].TileType,
                    TileValue = this.hexagonList[i].TileValue,
                    X = this.hexagonList[i].X,
                    Y = this.hexagonList[i].Y,
                });
            }
            // second step: set relations
            for (int i = 0; i < this.hexagonList.Count; i++)
            {
                target.hexagonList[i].North = GetClone(this.hexagonList[i].North, target);
                target.hexagonList[i].NorthEast = GetClone(this.hexagonList[i].NorthEast, target);
                target.hexagonList[i].NorthWest = GetClone(this.hexagonList[i].NorthWest, target);

                target.hexagonList[i].South = GetClone(this.hexagonList[i].South, target);
                target.hexagonList[i].SouthEast = GetClone(this.hexagonList[i].SouthEast,target);
                target.hexagonList[i].SouthWest = GetClone(this.hexagonList[i].SouthWest,target);
            }

            target.Configuration = new GameConfiguration()
            {
                GameId = this.Configuration.GameId,
                numberOfAI = this.Configuration.numberOfAI,
            };


            foreach (TileType tileType in this.PlayerMessages.Keys)
            {
                target.PlayerMessages.Add(tileType, new Queue<PlayerStatus>(this.PlayerMessages[tileType].ToArray()));
            }

            target.playerGuids.AddRange(this.playerGuids);
            target.currentTurn = this.currentTurn;
            target.playerProperties = new Dictionary<TileType, PlayerProperties>(this.playerProperties);
            target.playerColorMapping = new TwoWayMapper<Guid, TileType>(this.playerColorMapping);

            target.firstCapture = this.firstCapture;

            target.turnOrder = new List<TileType>(this.turnOrder);

            return target;
        }
 public GameOverStrategy(Game.Engine.Game gameData, Guid playerId)
     : base(gameData, playerId)
 {
 }
 private void LoadGame(Guid gameId)
 {
     bool exit = false;
     while (!exit)
     {
         try
         {
             using (FileStream loadFile = File.Open(Filename(gameId), FileMode.Open))
             {
                 DataContractSerializer formatter = new DataContractSerializer(typeof(Game));
                 current = (Game)formatter.ReadObject(loadFile);
             }
             exit = true;
         }
         catch (FileNotFoundException ex)
         {
             break;
         }
         catch (IOException ex)
         {
             Thread.Sleep(TimeSpan.FromMilliseconds(1.0));
         }
     }
 }