[Windows Mobile] recording and playback using OpenNETCF.Media.WaveAudio

Recording and playback using OpenNETCF.Media.WaveAudio


1 Introduction

Originally wanted to write a Snake game, you can play on Windows Mobile, but because I have to point presentation tribal gatherings, the results did not have time to write, but to become a snake wall

2. Methods

On the functions of the program, that is, when the snake Collage hit the screen, the game is over, the program flow is as follows

(1) obtain the screen resolution in order to hit the wall when the snake died, refer to rotate the screen orientation previous article [Windows Mobile], get the screen resolution and size of the work area

(2) for recording variable declarations global coordinates

(3) Menu clicking on the Start button, so Timer operation, and according to the direction of the user clicks with the updated coordinates, and determines whether a wall

(4) in the form Paint event, drawing the snake out

program

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SmartDeviceProject8
{
    public partial class Form1 : Form
    {
        const int snakeSize = 10;
        int w = Screen.PrimaryScreen.WorkingArea.Width / snakeSize;
        int h = Screen.PrimaryScreen.WorkingArea.Height / snakeSize;
        bool[,] point = new bool[Screen.PrimaryScreen.WorkingArea.Width / snakeSize, Screen.PrimaryScreen.WorkingArea.Height / snakeSize];
        string direction = "Right";  // 声明全域变量 direction,放置 snake 的行进方向

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            point[0, 0] = true;  // 设定 snake 初始位置
        }

        private void miStart_Click(object sender, EventArgs e)
        {
            this.timer1.Interval = 100;  // 设定 timer1 的触发时间为 0.1
            this.timer1.Enabled = true;  // 开启 timer1
        }

        // 表单 Paint 刷新事件
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen pen = new Pen(Color.Red, 2);  // 设定 Pen Color: Red,width: 2
            int x = 0; int y = 0;
            while (y < h)
            {
                bool skip = false;
                if (point[x, y] == true)
                {
                    g.DrawRectangle(pen, x * snakeSize, y * snakeSize, snakeSize, snakeSize);
                }
                if (x >= w-1)
                {
                    x = 0; y++; skip = true;
                }

                if (x < w-1 && skip == false)
                {
                    x++;
                }
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                int x = 0; int y = 0;
                while (y < h)
                {
                    bool skip = false;
                    if (direction == "Right")  // 当方向为 Right 时
                    { if (point[x, y] == true) { point[x, y] = false; point[x + 1, y] = true; break; } }
                    if (direction == "Left")  // 当方向为 Left 时
                    { if (point[x, y] == true) { point[x, y] = false; point[x - 1, y] = true; break; } }
                    if (direction == "Down") // 当方向为 Down 时
                    { if (point[x, y] == true) { point[x, y] = false; point[x, y + 1] = true; break; } }
                    if (direction == "Up") // 当方向为 Up 时
                    { if (point[x, y] == true) { point[x, y] = false; point[x, y - 1] = true; break; } }
                    if (x >= w-1) { x = 0; y++; skip = true; }
                    if (x < w-1 && skip == false) { x++; }
                }
                Invalidate();  // 重新绘制画面
            }
            catch
            {
                MessageBox.Show("Game Over");
            }
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            // 将使用者点选按键给direction
            direction = e.KeyData.ToString();
        }
    }
}

3. Perform results




Original: Large column  [Windows Mobile] recording and playback using OpenNETCF.Media.WaveAudio


Guess you like

Origin www.cnblogs.com/petewell/p/11465347.html