示例#1
0
文件: SnakeHead.cs 项目: K0bin/Snake
 public SnakeHead(Game game, IRenderItemFactory factory)
     : base(game, factory, new Vector2I(0, 0))
 {
     Direction = Game.Rules.SnakeStartDirection;
     direction = Direction;
     Position = Game.Rules.SnakeStartPosition;
     RenderItem = factory.CreateRenderItem(RenderItemType.SnakeHead);
 }
示例#2
0
        public MainWindow()
        {
            InitializeComponent();

            game = new Game(this, this, new WPFInput());
            timer.Tick += timer_Tick;
            timer.Interval = new TimeSpan(0, 0, 0, 0, 16);
            timer.Start();
        }
示例#3
0
文件: World.cs 项目: K0bin/Snake
        public World(Game game, IRenderItemFactory factory, GameRules rules)
        {
            this.game = game;
            this.factory = factory;

            Head = new SnakeHead(game, factory);
            CreateWorld(game, factory, rules, rules.WorldSize);

            Random random = new Random();
            Treat = new Treat(game, factory, new Vector2I(random.Next(1, rules.WorldSize.X - 1), random.Next(1, rules.WorldSize.Y - 1)));
        }
示例#4
0
文件: Program.cs 项目: Dr1N/Snake
 static void Main(string[] args)
 {
     try
     {
         Game game = new Game();
         game.BeginGame();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
示例#5
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.SnakeGame = ((Snake.Game)(target));
                return;

            case 2:
                this.gameCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 3:
                this.txtMessage = ((System.Windows.Controls.TextBlock)(target));
                return;
            }
            this._contentLoaded = true;
        }
示例#6
0
文件: Program.cs 项目: Naxmars/Snake
        static void Main(string[] args)
        {
            Console.SetWindowSize(WindowHeight, WindowWidth);
            Console.SetBufferSize(WindowHeight, WindowWidth);
            Console.BackgroundColor = ConsoleColor.DarkCyan;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.CursorVisible = false;
            game = new Game(Console.BufferHeight - 1, Console.BufferWidth);
            Thread inputThread = new Thread(new ThreadStart(Control));
            game.Start();
            inputThread.Start();

            while (game.IsRunning)
            {
                Console.SetCursorPosition(0, 0);
                Console.Write(game.MapToString());
                game.UpdateSnake();
                Console.Title = WindowTitle + " :: " + "[Skóre: " + game.Score + "]";
                Thread.Sleep(100);
            }
        }
示例#7
0
        public void Clear_Level()
        {
            int level= mygame.game_level + 1;
            int game_height = mygame.game_height;
            int game_width = mygame.game_width;
            string sound = mygame.sound_control;
            MyGame_timer.Enabled = false;
            if(level > mygame.max_level)
            {
                level = 1;
                mygame.Finish_Game();
                pictureBox1.Refresh();
                mygame.game_status = "game_over";
            }
            else {
                mygame.Clear_Level();

                pictureBox1.Refresh();
                mygame = new Game(game_height,game_width);
                mygame.game_status = "clear";
                mygame.sound_control = sound;
                mygame.game_level = level;
            }
        }
示例#8
0
文件: Field.cs 项目: K0bin/Snake
 public Field(Game game, IRenderItemFactory factory, Vector2I position)
 {
     Position = position;
     Game = game;
     Factory = factory;
 }
示例#9
0
文件: Treat.cs 项目: K0bin/Snake
 public Treat(Game game, IRenderItemFactory factory, Vector2I position)
     : base(game, factory, position)
 {
     RenderItem = factory.CreateRenderItem(RenderItemType.Treat);
 }
示例#10
0
 static void Main(string[] args)
 {
     Game game = new Game();
     Console.ReadKey();
 }
示例#11
0
文件: SnakeBody.cs 项目: K0bin/Snake
 public SnakeBody(Game game, IRenderItemFactory factory, Vector2I position)
     : base(game, factory, position)
 {
     RenderItem = factory.CreateRenderItem(RenderItemType.SnakeBody);
 }
示例#12
0
 public SpeedPowerup(Game game, IRenderItemFactory factory, Vector2I position)
     : base(game, factory, position)
 {
     RenderItem = factory.CreateRenderItem(RenderItemType.SpeedPowerup);
 }
示例#13
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            int width, height, size;
            width = height = 30;
            size = 20;

            this.pictureBox1.Width = width * size;
            this.pictureBox1.Height = height * size;
              //  this.Width = pictureBox1.Width + 30;
               // this.Height = pictureBox1.Height + 60;
            G = new Game(width, height, size, Graphics.FromHwnd(this.pictureBox1.Handle));
        }
示例#14
0
        //Create the game board again for changed size
        void Game_Create_Again()
        {
            string sound = mygame.sound_control;
            int h = mygame.game_height;
            int w = mygame.game_width;
            mygame = new Game(h,w);
            top_menu_panel.Size = new Size(w,top_menu_panel.Size.Height);

            mygame.sound_control = sound;
            MyGame_Form_Load(this,System.EventArgs.Empty);
        }
示例#15
0
文件: World.cs 项目: K0bin/Snake
 private void CreateWorld(Game game, IRenderItemFactory factory, GameRules rules, Vector2I size)
 {
     for (int x = 0; x < size.X; x++)
         for (int y = 0; y < size.Y; y++)
             if ((x == 0 || x == size.X - 1) || (y == 0 || y == size.Y - 1))
                 blocks.Add(new Block(game, factory, new Vector2I(x, y)));
 }