Exemple #1
0
        //入口函数
        static void Main(string[] args)
        {
            Console.WindowWidth  = 35 * 2;
            Console.WindowHeight = 17;
            CCommon.ColorWhite();
            Console.Clear();

            while (true)
            {
                if (CCommon.GameScene.GetState() == 1)
                {
                    CCommon.GameScene.Init();
                }
                if (CCommon.GameScene.GetState() == 2)
                {
                    CCommon.GameScene.Run();
                }
                if (CCommon.GameScene.GetState() == 3)
                {
                    CCommon.GameScene.End();
                }
                if (CCommon.GameScene.GetState() == -1)
                {
                    return;
                }
            }
        }
        public override void Run()
        {
            //打开文件
            FileStream stream = new FileStream(m_path, FileMode.Open);

            //移动指针位置
            stream.Seek(0, SeekOrigin.Begin);
            //读取文件信息
            stream.Read(m_rdata, 0, m_rdata.Length);
            //关闭文件
            stream.Close();
            CCommon.ColorWhite();
            Console.SetCursorPosition(10 * 2, 2);
            Console.Write(" 嘿!这里是蛇皮皮的排行榜哦~");
            for (int i = 0; i < 8; i++)
            {
                Console.SetCursorPosition(12 * 2, i + 4);
                Console.Write("第{0}名   \t{1}分", i + 1, ((int)m_rdata[i]) * 5);
            }
            CCommon.ColorBlack();
            Console.SetCursorPosition(15 * 2, 13);
            Console.Write("空格键返回");
            while (Console.KeyAvailable)
            {
                //按键
                char           input = new char();
                ConsoleKeyInfo c     = Console.ReadKey(true);
                input = c.KeyChar;
                if (input == ' ')
                {
                    GameState = 3;
                }
            }
            Thread.Sleep(100);
        }
        public override void Run()
        {
            //初始化画布
            go.Begin(1);
            CCommon.ColorWhite();
            //随机食物
            if (food_b)
            {
                Random r = new Random();
                foodx = r.Next(1, go.GetClientW() - 1);
                foody = r.Next(1, go.GetClientH() - 1);
            }
            if (snake.GetX() == foodx && snake.GetY() == foody)
            {
                food_b = true;
                snake.PushBody(snake.GetX(), snake.GetY());
                CCommon.Score++;
            }
            else
            {
                food_b = false;
            }
            //导入图片
            go.DrawBmp("星", foodx, foody);
            Console.SetCursorPosition(foodx * 2, foody);
            Console.Write("☆");
            go.DrawBmp("头", snake.GetX(), snake.GetY());
            for (int i = 0; i < snake.GetBodyLen(); ++i)
            {
                if (i % 2 == 0)
                {
                    go.DrawBmp("身1", snake.GetBodyX(i), snake.GetBodyY(i));
                }
                else if (i % 2 == 1)
                {
                    go.DrawBmp("身2", snake.GetBodyX(i), snake.GetBodyY(i));
                }
            }
            //绘制
            go.End();
            //修改蛇身位置
            for (int i = snake.GetBodyLen() - 1; i >= 0; --i)
            {
                snake.SetBodyX(i, snake.GetBodyX(i - 1));
                snake.SetBodyY(i, snake.GetBodyY(i - 1));
            }
            if (snake.GetBodyLen() != 0)
            {
                snake.SetBodyX(0, snake.GetX());
                snake.SetBodyY(0, snake.GetY());
            }
            switch (CCommon.Score)
            {
            case 3: speed = 150; break;

            case 5: speed = 120; break;

            case 7: speed = 90; break;

            case 9: speed = 75; break;

            case 12: speed = 60; break;

            case 20: speed = 30; break;

            case 30: speed = 15; break;
            }

            while (Console.KeyAvailable)
            {
                //按键
                char           input = new char();
                ConsoleKeyInfo c     = Console.ReadKey(true);
                input = c.KeyChar;
                switch (input)
                {
                case 'w':
                {
                    if (snake.GetDir() != 2 || snake.GetBodyLen() == 0)
                    {
                        snake.SetDir(1);
                    }
                }
                break;

                case 's':
                {
                    if (snake.GetDir() != 1 || snake.GetBodyLen() == 0)
                    {
                        snake.SetDir(2);
                    }
                }
                break;

                case 'a':
                {
                    if (snake.GetDir() != 4 || snake.GetBodyLen() == 0)
                    {
                        snake.SetDir(3);
                    }
                }
                break;

                case 'd':
                {
                    if (snake.GetDir() != 3 || snake.GetBodyLen() == 0)
                    {
                        snake.SetDir(4);
                    }
                }
                break;
                }
            }
            //自动移动
            snake.Move();
            //游戏结束
            if (snake.GetX() > go.GetClientW() - 2 ||
                snake.GetY() > go.GetClientH() - 2 ||
                snake.GetX() < 1 ||
                snake.GetY() < 1)
            {
                GameState = 3;
            }
            for (int i = 0; i < snake.GetBodyLen(); ++i)
            {
                if (snake.GetX() == snake.GetBodyX(i) && snake.GetY() == snake.GetBodyY(i))
                {
                    GameState = 3;
                }
            }
            Thread.Sleep(speed);
        }
        public override void Run()
        {
            CCommon.ColorWhite();
            //打开文件
            FileStream stream = new FileStream(m_path, FileMode.OpenOrCreate);

            //移动指针位置
            stream.Seek(0, SeekOrigin.Begin);
            //读取文件信息
            stream.Read(m_rdata, 0, m_rdata.Length);
            //关闭文件
            stream.Close();


            Console.SetCursorPosition(13 * 2, 3);
            Console.Write("游戏结束!总得分:{0}", CCommon.Score * 5);

            if (on)
            {
                if ((byte)CCommon.Score >= m_rdata[m_rdata.Length - 1])
                {
                    m_rdata[m_rdata.Length - 1] = (byte)CCommon.Score;
                    win = true;
                }

                for (int i = m_rdata.Length - 1; i > 0;)
                {
                    if (m_rdata[i] > m_rdata[i - 1])
                    {
                        byte bTmp = m_rdata[i];
                        m_rdata[i]     = m_rdata[i - 1];
                        m_rdata[i - 1] = bTmp;
                    }
                    i--;
                    if (m_rdata[i] == (byte)CCommon.Score)
                    {
                        num = i + 1;
                    }
                }
                on = false;
                //for (int i = 0; i < 8; i++)
                //{
                //    m_rdata[i] = 1;
                //}
                FileStream stream1 = new FileStream(m_path, FileMode.OpenOrCreate);
                //移动指针位置
                stream1.Seek(0, SeekOrigin.Begin);
                //读取文件信息
                stream1.Write(m_rdata, 0, 8);
                //关闭文件
                stream1.Close();
            }
            if (win)
            {
                Console.SetCursorPosition(8 * 2, 5);
                Console.Write("大兄弟厉害呀!成功登上皮皮排行榜第{0}名!", num);
            }
            else
            {
                Console.SetCursorPosition(7 * 2, 5);
                Console.Write("你是手残吗!连我蛇皮皮的排行榜都上不去!丢人!");
            }
            if (m_icon == 1)
            {
                CCommon.ColorBlack();
            }
            else
            {
                CCommon.ColorWhite();
            }
            Console.SetCursorPosition(10 * 2, 8);
            Console.Write("天生傲骨怎能服输!再来一局!");
            if (m_icon == 2)
            {
                CCommon.ColorBlack();
            }
            else
            {
                CCommon.ColorWhite();
            }
            Console.SetCursorPosition(12 * 2, 9);
            Console.Write("认怂!认怂!不玩了!");
            if (m_icon == 3)
            {
                CCommon.ColorBlack();
            }
            else
            {
                CCommon.ColorWhite();
            }
            Console.SetCursorPosition(12 * 2, 10);
            Console.Write("返回蛇皮皮的主菜单");
            while (Console.KeyAvailable)
            {
                //按键
                char           input = new char();
                ConsoleKeyInfo c     = Console.ReadKey(true);
                input = c.KeyChar;
                switch (input)
                {
                case 'w':
                {
                    if (m_icon == 2)
                    {
                        m_icon = 1;
                    }
                    else if (m_icon == 3)
                    {
                        m_icon = 2;
                    }
                }
                break;

                case 's':
                {
                    if (m_icon == 1)
                    {
                        m_icon = 2;
                    }
                    else if (m_icon == 2)
                    {
                        m_icon = 3;
                    }
                }
                break;

                case ' ':
                {
                    GameState = 3;
                }
                break;
                }
            }
            Thread.Sleep(100);
        }
Exemple #5
0
        public override void Run()
        {
            go.Begin(0);
            go.DrawBmp(m_id, m_x, m_y);
            go.DrawBmp("开始", 14, 9);
            go.DrawBmp("排行", 14, 11);
            go.End();
            if (m_x + 5 > go.GetClientW() - 1)
            {
                m_id  = "头左";
                m_dir = -1;
            }
            else if (m_x < 1)
            {
                m_id  = "头右";
                m_dir = 1;
            }
            m_x += m_dir;
            Console.SetCursorPosition(11 * 2, 5);
            Console.Write("哦呦!这不是蛇皮皮嘛!");
            if (m_icon == 1)
            {
                CCommon.ColorBlack();
                Console.SetCursorPosition(14 * 2, 9);
                Console.Write("开始游戏");
            }
            if (m_icon == 2)
            {
                CCommon.ColorBlack();
                Console.SetCursorPosition(14 * 2, 11);
                Console.Write("皮皮排行");
            }
            CCommon.ColorWhite();
            while (Console.KeyAvailable)
            {
                //按键
                char           input = new char();
                ConsoleKeyInfo c     = Console.ReadKey(true);
                input = c.KeyChar;
                switch (input)
                {
                case 'w':
                {
                    if (m_icon == 2)
                    {
                        m_icon = 1;
                    }
                }
                break;

                case 's':
                {
                    if (m_icon == 1)
                    {
                        m_icon = 2;
                    }
                }
                break;

                case ' ':
                {
                    GameState = 3;
                }
                break;
                }
            }
            Thread.Sleep(60);
        }