コード例 #1
0
ファイル: ConsoleListener.cs プロジェクト: IAmTomaton/C-game
 public static void Update(ISpaceContext updateContext)
 {
     while (Console.KeyAvailable)
     {
         var command = Console.ReadLine();
         Process(command, updateContext);
         //Console.WriteLine(updateContext.FindLocalObject<Obstacle>().Count());
     }
 }
コード例 #2
0
        public static void LoadNextScene(ISpaceContext uc)
        {
            currentScene += 1;
            var path = scenes[currentScene % scenes.Count()];

            using (StreamReader sr = new StreamReader(path, System.Text.Encoding.Default))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    ConsoleListener.Process(line, uc);
                }
            }
        }
コード例 #3
0
ファイル: GameContext.cs プロジェクト: IAmTomaton/Cgame
 public static void Init(ISpaceContext spaceContext, IGUIManager GUIManager)
 {
     space         = spaceContext;
     gui           = GUIManager;
     IsInitialized = true;
 }
コード例 #4
0
ファイル: ConsoleListener.cs プロジェクト: IAmTomaton/C-game
        public static void Process(string command, ISpaceContext uc)
        {
            var commandParts            = command.Split();
            List <GameObject> listToAdd = null;
            var        add       = false;
            GameObject newObject = null;

            switch (commandParts[0])
            {
            case "add":
                //listToAdd = uc.objectsToAdd;
                add = true;
                break;

            case "cancel":
                var lastObj = gameObjectsStack.Pop();
                //uc.objectsToDelete.Add(lastObj);
                uc.DeleteObject(lastObj);
                break;

            default:
                //it is possible to throw exception here
                Console.WriteLine("some mistake in scene command(add/delete)");
                break;
            }
            //if (listToAdd != null)
            if (add)
            {
                try
                {
                    int          x = 0; int y = 0; bool gr = true; bool jumps = true;
                    MovementType move = MovementType.Continuos; ShootType shoot = ShootType.CreateBullet;
                    var          toInitPlayer = new List <Func <string, bool> >()
                    {
                        s => int.TryParse(s, out x),
                        s => int.TryParse(s, out y),
                        s => bool.TryParse(s, out gr),
                        s => bool.TryParse(s, out jumps),
                        s => Enum.TryParse(s, out move),
                        s => Enum.TryParse(s, out shoot)
                    };
                    bool ifParsed = commandParts
                                    .Skip(2)
                                    .Select((s, i) => toInitPlayer[i](s))
                                    .Aggregate((f, s) => f && s);
                    if (ifParsed)
                    {
                        if (commandParts[1] == "player")
                        {
                            newObject = creationDict[commandParts[1]]
                                            (new PlayerObjectParameter(new Vector3(x, y, 0), gr, jumps, move, shoot));
                        }
                        else
                        {
                            newObject = creationDict[commandParts[1]]
                                            (new GameObjectParameter(new Vector3(x, y, 0)));
                        }
                        gameObjectsStack.Push(newObject);
                    }
                    else
                    {
                        Console.WriteLine("some mistake in scene command(parameters of object)");
                    }
                }
                catch (KeyNotFoundException e)
                {
                    Console.WriteLine("some mistake in scene command(type of object)");
                }
                uc.AddLocalObject(newObject);
            }
        }