使用 C# 的 AGENT 智能手表全能应用






4.37/5 (10投票s)
为 AGENT 智能手表创建简单的应用程序。
引言
* 请观看我的 YouTube 视频,了解如何使用 C# 开发 AGENT 智能手表多合一应用程序。
在本文中,我们将看到如何为 AGENT 智能手表创建一个简单的应用程序。我之所以选择 AGENT 智能手表,是因为它支持 Windows、Android 和 iOS 手机,而且 AGENT 智能手表的 SDK 基于 .NET Micro Framework。.NET Micro Framework 可用于开发嵌入式设备应用程序。有关 AGENT 智能手表的更多详细信息,请访问其官方网站此处。
先决条件:下载并安装以下所有先决条件到您的计算机。
http://www.agentwatches.com/downloads/agentsdk.exe
- Visual Studio 2015 - 您可以从此链接下载。
- .NET Micro Framework SDK 4.3 for VS2015 project
- AGENT SDK
- Tiny Font Tool GUI
在本文中,我们将看到如何
- 创建并运行我们的第一个 AGENT 智能手表应用程序
- 创建一个简单的 AGENT 智能手表以添加自定义字体、添加图像、绘制文本和图像
- 为 AGENT 智能手表创建我的多合一应用程序
什么是 Shanu AGENT 智能手表多合一应用程序?
智能手表让我们的生活更轻松舒适。如果您问我,我们已经有了智能手机,为什么还需要智能手表,那么我的回答是,在当今忙碌的世界中,使用智能手表和智能手机同样重要。例如,假设我们正在开会,同时接到一些连续的电话。我们无法立即查看是谁打来的电话。如果这是一个非常重要和紧急的电话,那么我们就会错过它,而不知道是谁打来的。如果我们使用智能手表,那么在不打扰会议的情况下,我们可以查看是谁打来的电话,如果这是一个非常重要的电话,我们就可以接听。
为了让事情更简单方便,我使用 AGENT 智能手表制作了多合一应用程序。我的智能手表多合一应用程序有五种不同的功能。它们是:
- 简单文本动画
- 显示日期和时间
- 显示今日日程
- 显示简单游戏的动画
- 秒表
Using the Code
1) 创建并运行我们的第一个 AGENT 智能手表应用程序
请下载并安装所有必要的先决条件,以使用 C# 创建我们的第一个 AGENT 智能手表应用程序。安装完所有上述先决条件后,请执行以下操作:
点击开始 -> 程序 -> 选择 Visual Studio 2015 -> 点击 Visual Studio 2015
点击新建 -> 项目 -> 从模板中选择 Micro Framework -> 点击 Windows 应用程序。选择您的项目文件夹并为您的项目指定合适的名称 -> 点击确定。
创建 AGENT 智能手表应用程序后,我们可以在解决方案资源管理器中看到它将包含 program.cs 和 Resources.resx。program.cs 类文件是编写所有代码以创建应用程序的主文件。program.cs 将包含 Main
方法,程序将从此处开始执行。Resources.resx 用于添加图像、微型字体、字符串等资源。
默认目标框架:默认目标语言将是 .NET Micro Framework 4.3。当我们右键单击项目并点击属性时,我们可以看到目标框架将选择为 .NET Micro Framework 4.3。
默认部署:默认部署设备将选择为 AGENT 模拟器。当我们运行程序时,我们可以在 AGENT 模拟器中看到输出。
Program.cs
我将推荐这个网站,对于任何初学者来说,它都是一个非常好的地方,可以从 RougrCode 的 Matt 撰写的这个链接学习使用 C# 编写 AGENT 智能手表代码。
默认情况下,当我们创建程序时,Program.cs 将包含一些代码以显示输出“Hello World”。Program.cs 将添加默认的头文件来运行程序。在这里,我们可以看到添加的默认头文件集。
.NET Micro Framework 与我们的 .NET Framework 相比,功能非常有限。因此,我们不能使用我们正常 .NET Framework 中使用的所有引用。
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
主方法
默认情况下,当我们创建 main
方法时,它将创建一个窗口来显示默认的“hello world
”文本。
public static void Main()
{
Program myApplication = new Program();
Window mainWindow = myApplication.CreateWindow();
// Create the object that configures the GPIO pins to buttons.
GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);
// Start the application
myApplication.Run(mainWindow);
}
在 Createwindow
方法中,将添加默认代码以将文本添加到窗口并从资源文件中加载文本内容。请注意,要查看我们的资源字符串,我们可以双击解决方案资源管理器中的“Resources.resx”文件。如果需要,我们可以添加更多 string
或更改 Hello World
文本以显示不同的文本。
private Window mainWindow;
public Window CreateWindow()
{
// Create a window object and set its size to the
// size of the display.
mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth;
// Create a single text control.
Text text = new Text();
text.Font = Resources.GetFont(Resources.FontResources.small);
text.TextContent =
Resources.GetString(Resources.StringResources.String1);
text.HorizontalAlignment =
Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
text.VerticalAlignment =
Microsoft.SPOT.Presentation.VerticalAlignment.Center;
// Add the text control to the window.
mainWindow.Child = text;
// Connect the button handler to all of the buttons.
mainWindow.AddHandler
(Buttons.ButtonUpEvent, new RoutedEventHandler(OnButtonUp), false);
// Set the window visibility to visible.
mainWindow.Visibility = Visibility.Visible;
// Attach the button focus to the window.
Buttons.Focus(mainWindow);
return mainWindow;
}
在此方法中,创建主窗口后,将为 AGENT 智能手表的按钮点击事件添加 eventhandler
。
OnButtonUp 事件
:每当用户点击 AGENT 智能手表上的按钮时,都会触发此事件。AGENT 智能手表将包含五个按钮,右侧三个按钮,左侧两个按钮。
private void OnButtonUp(object sender, RoutedEventArgs evt)
{
ButtonEventArgs e = (ButtonEventArgs)evt;
// Print the button code to the Visual Studio output window.
Debug.Print(e.Button.ToString());
}
运行并测试我们的第一个程序
无需编写任何代码,我们就可以运行我们的第一个 AGENT 智能手表应用程序来显示“Hello World
”文本。
所以我们成功创建了我们的第一个 AGENT 智能手表应用程序并对其进行了测试。
2) 创建一个简单的 AGENT 智能手表以添加自定义字体、添加图像、绘制文本和图像
按照上述所有步骤创建您的 AGENT 智能手表应用程序。
我们已经看到,当我们创建 AGENT 智能手表应用程序时,它会添加默认代码来创建一个窗口并显示“Hello world
”文本。
现在,让我们看看如何在 AGENT 智能手表中绘制文本、添加图像和添加微型字体以显示不同的字体文本。
默认情况下,我们将拥有此头文件
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
我将为项目添加更多引用,以便绘制文本和图像,以及添加颜色和使用 Thread
。
using Microsoft.SPOT.Presentation.Media;
using System.Threading;
接下来,我们将删除除 main
方法之外的所有代码。在这里,我将直接在 main
方法中绘制文本和图像,而不是创建新窗口。
所以现在我的 program.cs 文件看起来像这样
using System.Diagnostics;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using System.Threading;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation.Controls;
namespace test
{
public class Program : Microsoft.SPOT.Application
{
public static void Main()
{
}
}
}
在这里,首先将为 bitmap
创建对象以 drawtext
。
static Bitmap _myFace;
在 main
方法内部,我们将绘制文本以显示我们的内容。在这里,我们可以看到,我将首先使用 maxwidth
和 maxheight
创建 bitmap
图像。
我们将从资源文件中添加字体。默认的小字体将添加到我们的资源文件中。
现在,我使用了默认字体来显示文本。使用 DrawText
,我将在我给定的所需位置绘制文本。Thread.Sleep()
用于连续显示文本。
public class Program : Microsoft.SPOT.Application
{
static Bitmap _myFace;
public static void Main()
{
_myFace = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);
_myFace.Clear();
Font fontS = Resources.GetFont(Resources.FontResources.small);
_myFace.DrawText("SHANU", fontS, Color.White, 12, 10);
_myFace.Flush();
Thread.Sleep(Timeout.Infinite);
}
}
当我们运行程序时,我们可以看到输出为
添加自定义字体
默认情况下,我们的应用程序中只有一个字体。我们还可以从资源向应用程序添加自定义字体。请注意,我们只需添加微型字体。要将普通字体转换为微型字体,有一个免费工具可从此链接下载,您可以下载并更改任何可用字体为微型字体。将字体保存到您的文件夹中,并将微型字体添加到您的资源文件中。
我已将 Tahoma 字体转换为微型字体并保存到我的文件夹中。现在让我们看看如何将微型字体添加到我们的应用程序中。
要添加自定义转换的字体,请双击我们的资源文件并点击添加现有文件。选择您新转换的 Tahoma 微型字体。点击保存以保存更改。
在您的 main
方法代码中,为字体创建新对象以添加您的新字体并绘制文本。
public static void Main()
{
_myFace = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);
_myFace.Clear();
Font fontS = Resources.GetFont(Resources.FontResources.small);
_myFace.DrawText("SHANU", fontS, Color.White, 12, 10);
Font font = Resources.GetFont(Resources.FontResources.ThahomaFont);
_myFace.DrawText("SHANU", font, Color.White, 12, 26);
_myFace.Flush();
Thread.Sleep(Timeout.Infinite);
}
当我们运行程序时,我们可以看到输出为
添加图像和绘制图像
要添加图像,请双击我们的资源文件并点击添加现有文件。选择您的图像文件并保存。我将只添加 GIF 和 JPEG 图像。
在您的 main 方法代码中,为字体创建新对象以添加您的新字体并绘制文本。首先,我将从资源文件创建位图图像,然后使用 Draw Image,将图像绘制到所需位置。请注意,最后四个点用于裁剪和显示图像。
public class Program : Microsoft.SPOT.Application
{
static Bitmap _myFace;
public static void Main()
{
_myFace = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);
_myFace.Clear();
Font fontS = Resources.GetFont(Resources.FontResources.small);
_myFace.DrawText("SHANU", fontS, Color.White, 12, 10);
Font font = Resources.GetFont(Resources.FontResources.ThahomaFont);
_myFace.DrawText("SHANU", font, Color.White, 12, 26);
Bitmap myImage = new Bitmap
(Resources.GetBytes(Resources.BinaryResources.shanu),
Bitmap.BitmapImageType.Jpeg);
_myFace.DrawImage(40, 40, myImage, 0, 0, 128, 128);
_myFace.Flush();
Thread.Sleep(Timeout.Infinite);
}
}
当我们运行程序时,我们可以看到输出为
希望现在您对如何为 AGENT 智能手表开发简单应用程序有了更清晰的认识。接下来,我们将详细了解我是如何创建我的多合一应用程序的。
3) 如何为 AGENT 智能手表创建我的多合一应用程序
正如我已经在我的“多合一应用程序”中解释过的那样,我在一个应用程序中创建了五种不同的功能。它们是
- 简单文本动画
- 显示日期和时间
- 显示今日日程
- 显示简单游戏的动画
- 秒表
我们将逐一详细了解如何使用 AGENT 智能手表应用程序开发来创建。
如上所述创建新项目,我将使用默认创建的主窗口来默认显示我的名字,并在按钮点击事件中执行所有五种不同的功能。
添加所有头文件
using System;
using System.Diagnostics;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using System.Threading;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation.Controls;
声明所有局部变量。我将使用此变量来执行五种不同的功能。
//Main bitmap to draw all text
static Bitmap _myFace;
const int HEIGHT = 128;
const int WIDTH = 128;
static int _ButtonClickNumber = 0;
static Timer _TiimeDispTimer;
//To display text Animation
static int name1Xval = 2;
static int name1Yval = 20;
static int name2Xval = Bitmap.MaxWidth;
static int name2Yval = 70;
static int name3Xval = 10;
static int name3Yval = Bitmap.MaxHeight - 10;
//Ball Draw
static int ballXval = 50;
static int ballYval = 90;
//Man Draw
static int manfaceXval = 10;
static int manfaceYval = 40;
static int leg1Xval = manfaceXval + 1;
static int leg1Yval = manfaceYval + 30;
static int leg1X1val = manfaceXval - 4;
static int leg1Y1val = manfaceYval + 54;
static int leg2Xval = manfaceXval + 1;
static int leg2Yval = manfaceYval + 30;
static int leg2X1val = manfaceXval + 4;
static int leg2Y1val = manfaceYval + 54;
static int goalXVal = 60;
static int goalYVal = 8;
Boolean cicked = false;
Boolean goals = false;
//For StopWatch
static int secounds = 0;
static int Miniutes = 0;
string secounds_str = "00";
string Miniutes_str = "00";
在 main
方法中,我们调用 Window
方法来创建 main
窗口并显示默认文本作为输出。
public static void Main()
{
Program myApplication = new Program();
_myFace = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);
Window mainWindow = myApplication.CreateWindow();
// Create the object that configures the GPIO pins to buttons.
GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);
// Start the application
myApplication.Run(mainWindow);
}
private Window mainWindow;
在 Createwindow
方法中,我将创建新窗口并添加默认文本以进行显示。
创建新的定时器,并设置定时器事件,每秒运行一次。接下来,创建一个处理程序来执行 AGENT 智能手表按钮抬起事件。
public Window CreateWindow()
{
// Create a window object and set its size to the
// size of the display.
mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth;
// Create a single text control.
Text text = new Text();
text.Font = Resources.GetFont(Resources.FontResources.small);
text.TextContent =
Resources.GetString(Resources.StringResources.Name1);
text.HorizontalAlignment =
Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
text.VerticalAlignment =
Microsoft.SPOT.Presentation.VerticalAlignment.Center;
// Add the text control to the window.
mainWindow.Child = text;
// Connect the button handler to all of the buttons.
mainWindow.AddHandler(Buttons.ButtonUpEvent,
new RoutedEventHandler(OnButtonUp), false);
// Set the window visibility to visible.
mainWindow.Visibility = Visibility.Visible;
TimeSpan startTime =
new TimeSpan(0, 0, 0, 0,
DateTime.Now.Millisecond); // start after a Second
TimeSpan SecondsAdd =
new TimeSpan(0, 0, 0, 1, 0); // Add Secounds for Update
_TiimeDispTimer =
new Timer(UpdateTime, null,
startTime, SecondsAdd); // start Timer to Display Time
// Attach the button focus to the window.
Buttons.Focus(mainWindow);
return mainWindow;
}
ButtonUp 事件:正如我所解释的,AGENT 智能手表将包含五个按钮,右侧三个,左侧两个,每个按钮都将包含一个唯一的编号。
- 右上表盘按钮 – 38
- 右中表盘按钮 – 41
- 右下表盘按钮 – 40
- 左上表盘按钮 – 37
- 左上表盘按钮 – 39
在此事件中,我将检查每个按钮抬起的唯一编号并调用所需的功能。
private void OnButtonUp(object sender, RoutedEventArgs evt)
{
ButtonEventArgs e = (ButtonEventArgs)evt;
// Print the button code to the Visual Studio output window.
Debug.Print(e.Button.ToString());
if (e.Button.ToString() == "38") //Right Top Watch Button ->
//To Display Names
{
_ButtonClickNumber = 38;
}
else if (e.Button.ToString() == "41") // right Middle Watch Button ->
// To Display Time
{
name1Xval = 6;
name2Xval = Bitmap.MaxWidth - 6;
name3Yval = Bitmap.MaxHeight - 10;
_ButtonClickNumber = 41;
showTime();
}
else if (e.Button.ToString() == "40") // Right Bottom Watch Button ->
// To Display Appointment
{
_ButtonClickNumber = 40;
showAppointment();
}
else if (e.Button.ToString() == "37") // Left Top Watch Button ->
// To Display Animation
{
_ButtonClickNumber = 37;
// To Start New Animation
cicked = false;
goals = false;
ballXval = 50;
ballYval = 90;
//Man Draw
manfaceXval = 10;
manfaceYval = 40;
leg1Xval = manfaceXval + 1;
leg1Yval = manfaceYval + 30;
leg1X1val = manfaceXval - 4;
leg1Y1val = manfaceYval + 54;
leg2Xval = manfaceXval + 1;
leg2Yval = manfaceYval + 30;
leg2X1val = manfaceXval + 4;
leg2Y1val = manfaceYval + 54;
showAnimation();
}
else if (e.Button.ToString() == "39") // Left Bottom Watch Button ->
// To Display
{
_ButtonClickNumber = 39;
secounds = 0;
Miniutes = 0;
secounds_str = "00";
Miniutes_str = "00";
spotWatch();
}
}
在我的程序中,我将使用 Timer 显示时间、文本动画和简单的足球游戏动画。在 Timer 事件中,我将检查每个按钮弹起的编号并调用函数。
public void UpdateTime(object state)
{
if (_ButtonClickNumber == 41)
{
showTime();
}
else if (_ButtonClickNumber == 38)
{
showName();
}
else if(_ButtonClickNumber == 37)
{
showAnimation();
}
else if(_ButtonClickNumber == 39)
{
spotWatch();
}
}
showName()
:在此方法中,我将显示简单的文本动画。
在此方法中,我将显示简单的文本动画。我将使用 DrawText
方法显示文本,并使用计时器将文本从左向右、从右向左和从下向上移动。
public void showName()
{
_myFace.Clear();
Font font = Resources.GetFont(Resources.FontResources.shanuName);
_myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth,
Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawText(Resources.GetString(Resources.StringResources.Name1),
font, Color.White, name1Xval, name1Yval);
if(name1Xval<= Bitmap.MaxWidth)
{
name1Xval = name1Xval + 4;
}
else
{
name1Xval = 6;
}
_myFace.DrawText(Resources.GetString(Resources.StringResources.Name2),
font, Color.White, name2Xval, name2Yval);
if (name2Xval >= 0)
{
name2Xval = name2Xval - 4;
}
else
{
name2Xval = Bitmap.MaxWidth - 6;
}
_myFace.DrawText(Resources.GetString(Resources.StringResources.Name3),
font, Color.White, name3Xval, name3Yval);
if (name3Yval >= 0)
{
name3Yval = name3Yval - 4;
}
else
{
name3Yval = Bitmap.MaxHeight-10;
}
_myFace.Flush();
}
showTime()
:在此方法中,我将显示日期
和时间
。
在此方法中,我将显示今天的日期
和时间
。在这里,我们可以看到我添加了两种不同的自定义字体来显示日期和时间。
public void showTime()
{
_myFace.Clear();
Font font = Resources.GetFont(Resources.FontResources.shanuNumber);
Font fontS = Resources.GetFont(Resources.FontResources.shanuName);
_myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth,
Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawText(DateTime.Now.ToString("yyyy-MM-dd"),
fontS, Color.White, 4, 20);
_myFace.DrawText(DateTime.Now.ToString("yyyy-MM-dd"),
fontS, Color.Black, 4, 21);
_myFace.DrawText(DateTime.Now.ToString("yyyy-MM-dd"),
fontS, Color.White, 4, 22);
_myFace.DrawText(DateTime.Now.ToString("HH:mm:ss"),
font, Color.White, 2, 70);
_myFace.DrawText(DateTime.Now.ToString("HH:mm:ss"),
font, Color.Black, 2, 71);
_myFace.DrawText(DateTime.Now.ToString("HH:mm:ss"),
font, Color.White, 2, 72);
_myFace.Flush();
}
showAppointment()
:此方法将包含用户今天的计划日程。
在此方法中,我将显示用户今天的日程。首先,我将所有今天的计划列表添加到资源字符串中,如下所示:
在此方法中,将从资源文件中使用 DrawText
方法逐一显示今天的计划。我还会检查当前时间与预约时间。如果当前时间等于预约时间,我将绘制矩形条和文本下方的线条作为提醒,以告知用户该执行当前计划了。
public void showAppointment()
{
_myFace.Clear();
Font fontB = Resources.GetFont(Resources.FontResources.NinaB);
Font fonts = Resources.GetFont(Resources.FontResources.small);
_myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth,
Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawText(" Today's Plan", fontB, Color.White, 6, 6);
//_myFace.DrawText("Todays Plan ", fontB, Color.White, 40, 6);
_myFace.DrawLine(Color.White, 1, 6, 27, 120, 27);
// to get the Current Hour
string hours = "12";
hours = (DateTime.Now.Hour % 12).ToString();
//To display First Appointment
string apt1 = Resources.GetString
(Resources.StringResources.Appointment1);
string[] apt1Chk = apt1.Split(' ');
if(apt1Chk[0]== hours)
{
_myFace.DrawRectangle(Color.White,2, 4, 36, 4, 4, 0, 0,
Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawLine(Color.White, 1, 20, 48, 70, 48);
}
_myFace.DrawText(apt1, fonts, Color.White, 14, 34);
//To display Second Appointment
string apt2 = Resources.GetString
(Resources.StringResources.Appointment2);
string[] apt2Chk = apt2.Split(' ');
if (apt2Chk[0] == hours)
{
_myFace.DrawRectangle(Color.White, 2, 4, 56, 4, 4, 0, 0,
Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawLine(Color.White, 1, 20, 64, 70, 64);
}
_myFace.DrawText(apt2, fonts, Color.White, 14, 52);
//To display Third Appointment
string apt3 = Resources.GetString
(Resources.StringResources.Appointment3);
string[] apt3Chk = apt3.Split(' ');
if (apt3Chk[0] == hours)
{
_myFace.DrawRectangle(Color.White, 2, 4, 74, 4, 4, 0, 0,
Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawLine(Color.White, 1, 20, 82, 70, 82);
}
_myFace.DrawText(apt3, fonts, Color.White, 14, 70);
//To display Fourth Appointment
string apt4 = Resources.GetString
(Resources.StringResources.Appointment4);
string[] apt4Chk = apt4.Split(' ');
if (apt4Chk[0] == hours)
{
_myFace.DrawRectangle(Color.White, 2, 4, 92, 4, 4, 0, 0,
Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawLine(Color.White, 1, 20, 102, 70, 102);
}
_myFace.DrawText(apt4, fonts, Color.White, 14, 88);
//To display Fifth Appointment
string apt5 = Resources.GetString
(Resources.StringResources.Appointment5);
string[] apt5Chk = apt5.Split(' ');
if (apt5Chk[0] == hours)
{
_myFace.DrawRectangle(Color.White, 2, 4, 112, 4, 4, 0, 0,
Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawLine(Color.White, 1, 20, 122, 70, 122);
}
_myFace.DrawText(apt5, fonts, Color.White, 14, 108);
_myFace.Flush();
}
showAnimation()
:在此方法中,我将向用户展示一个简单的足球游戏动画。
在此方法中,我将绘制简单的图形来显示简单的动画:一个球员从左向右移动,直到他到达足球,当他到达球时,他踢球并站在原地。球会慢慢移动并到达球门。一旦球到达球门,我将显示文本“进球”。这将作为例行事件发生。
public void showAnimation()
{
_myFace.Clear();
Font font = Resources.GetFont(Resources.FontResources.shanuNumber);
_myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth,
Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);
// Goal Point
_myFace.DrawRectangle(Color.White, 1, goalXVal, 0, goalXVal,
goalYVal, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);
// ball Draw
_myFace.DrawEllipse(Color.White, 6, ballXval, ballYval,
2, 2, Color.White, 0, 0, Color.White, 0, 0, 0);
_myFace.DrawEllipse(Color.White, manfaceXval, manfaceYval, 6, 6); //Face
_myFace.DrawLine(Color.White, 1, manfaceXval , manfaceYval +6,
manfaceXval , manfaceYval+30); // Body
_myFace.DrawLine(Color.White, 1, manfaceXval + 1, manfaceYval + 16,
manfaceXval - 4, manfaceYval + 22); //Hand 1
_myFace.DrawLine(Color.White, 1, manfaceXval + 1, manfaceYval + 20,
manfaceXval + 4, manfaceYval + 22); //Hand 2
_myFace.DrawLine
(Color.White, 1, leg1Xval, leg1Yval, leg1X1val, leg1Y1val); //leg 1
_myFace.DrawLine
(Color.White, 1, leg2Xval, leg2Yval, leg2X1val, leg2Y1val); //leg 2
if (manfaceXval <= ballXval - 14)
{
if(cicked==false)
{
manfaceXval = manfaceXval + 8;
leg1Xval = leg1Xval + 8;
leg1X1val = leg1X1val + 8;
leg2Xval = leg2Xval + 8;
leg2X1val = leg2X1val + 8;
}
}
if (manfaceXval >= ballXval - 14)
{
cicked = true;
}
if(cicked==true)
{
if(ballYval>= goalYVal)
{
ballXval = ballXval + 8;
ballYval = ballYval - 12;
}
else
{
goals = true;
}
}
if(goals==true)
{
_myFace.DrawText("Goal", font, Color.White, 40, 80);
ival = ival + 1;
if(ival>2)
{
cicked = false;
goals = false;
ballXval = 50;
ballYval = 90;
//Man Draw
manfaceXval = 10;
manfaceYval = 40;
leg1Xval = manfaceXval + 1;
leg1Yval = manfaceYval + 30;
leg1X1val = manfaceXval - 4;
leg1Y1val = manfaceYval + 54;
leg2Xval = manfaceXval + 1;
leg2Yval = manfaceYval + 30;
leg2X1val = manfaceXval + 4;
leg2Y1val = manfaceYval + 54;
}
}
_myFace.Flush();
}
spotWatch()
:在此方法中,我将显示一个简单的秒表
。
在此方法中,我将显示一个带有简单文本动画的简单秒表
。在这个秒表
中,我将显示计数器值,包括秒
和分钟
。
public void spotWatch()
{
_myFace.Clear();
Font font = Resources.GetFont(Resources.FontResources.shanuNumber);
Font fontS = Resources.GetFont(Resources.FontResources.shanuName);
_myFace.DrawRectangle(Color.White, 1, 0, 0, Bitmap.MaxWidth,
Bitmap.MaxHeight, 0, 0, Color.White, 0, 0, Color.White, 0, 0, 0);
Font fonts = Resources.GetFont(Resources.FontResources.small);
_myFace.DrawText("StopWatch", fontS, Color.White, 14, 6);
_myFace.DrawLine(Color.White, 1,6, 24, 120, 24);
_myFace.DrawText(Miniutes_str + " : " + secounds_str,
font, Color.White, 12, 38);
_myFace.DrawText(Miniutes_str + " : " + secounds_str,
font, Color.White, 12, 39);
_myFace.DrawText(Miniutes_str + " : " + secounds_str,
font, Color.White, 12, 40);
_myFace.DrawLine(Color.White, 1, 6, 80, 120, 80);
_myFace.DrawText(Resources.GetString(Resources.StringResources.Name1),
fontS, Color.White, name1Xval-30, 92);
if (name1Xval <= Bitmap.MaxWidth)
{
name1Xval = name1Xval + 16;
}
else
{
name1Xval = 6;
}
_myFace.Flush();
if(secounds <= 59)
{
secounds = secounds + 1;
if (secounds<=9)
{
secounds_str = "0" + secounds;
}
else
{
secounds_str = secounds.ToString();
}
}
else
{
secounds = 0;
Miniutes = Miniutes + 1;
}
if (Miniutes <= 9)
{
Miniutes_str = "0" + Miniutes;
}
else
{
Miniutes_str = Miniutes.ToString();
}
}
关注点
希望您喜欢这个,现在对开始 AGENT 智能手表应用程序开发有了更清晰的认识。玩得开心!您可以找到我的 AGENT 智能手表多合一应用程序源文件和另一个用于在 AGENT 智能手表中添加图像的源文件夹。
历史
- 2015年9月25日:初始版本