Index page

Welcome page

生成很多不同的小人哦~我是如何实现这么stupid but interesting的程序呢?我用了ASP.NET Core

画小人的话,用了一个很stupid的辅助类, 自己写的,小人脸宽21,然后鼻子占1,剩下的眼睛,鼻子,脸,耳朵,分分看。

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks; namespace game1.Controllers
{
public class DrawingHelper
{
public static string randomEye = @"-|@!~^+'o0O⊙";
public static string randomMouth = @"_x*oO~DVv";
public static string randomHair = randomEye + randomMouth;
public static List<StringBuilder> Draw(int FaceCount)
{
int RowWidth = ;
int hairWidth = ; string leftEar = "(";
string rightEar = ")";
string leftFace = "|";
string nose = "*"; var faces = new List<StringBuilder>(); for (int t = ; t <= FaceCount; t++)
{
StringBuilder sb = new StringBuilder();
string eye = GetRandomPart(randomEye, );
string mouth = GetRandomPart(randomMouth, );
string hairStyle = GetRandomPart(randomHair, );
DrawHair(RowWidth, hairWidth, hairStyle,sb);
DrawCartoon(leftEar, rightEar, leftFace, eye, nose, mouth,sb);
sb.Append("\n");
faces.Add(sb);
}
return faces; } private static void DrawHair(int RowWidth, int hairWidth, string hairStyle,StringBuilder sb)
{
StringBuilder hair = new StringBuilder();
for (int i = ; i <= hairWidth - ; i++)
{
hair.Append(hairStyle);
}
sb.AppendLine((" " + hair + " ").PadLeft((RowWidth - hairWidth) / + hairWidth, ' '));
sb.AppendLine(("|" + hair + "|").PadLeft((RowWidth - hairWidth) / + hairWidth, ' '));
}
public static string GetRandomPart(string pwdchars, int pwdlen)
{ string tmpstr = "";
int iRandNum;
Thread.Sleep();
long tick = DateTime.Now.Ticks;
Random rnd = new Random((int)(tick & 0xffffffffL) | (int)(tick >> ));
for (int i = ; i < pwdlen; i++)
{
iRandNum = rnd.Next(pwdchars.Length);
tmpstr += pwdchars[iRandNum];
}
return tmpstr;
}
private static void DrawCartoon(string leftEar, string rightEar, string leftFace, string eye, string nose, string mouth, StringBuilder sb)
{
//Print left
PrintLeftParts(leftEar, ,sb);
PrintLeftParts(leftFace, ,sb);
PrintLeftParts(eye, ,sb);
PrintLeftParts(nose, ,sb);
//Pring right
PrintLeftParts(eye, , sb);
PrintLeftParts(leftFace, ,sb);
PrintLeftParts(rightEar, ,sb);
//Print down face
sb.AppendLine();
PrintLeftParts(leftFace, ,sb);
PrintLeftParts(mouth, ,sb,'_');
PrintLeftParts(leftFace, , sb,'_');
sb.AppendLine();
sb.AppendLine(); } static void PrintLeftParts(string organName, int leftPad, StringBuilder sb,char paddingchar = ' ')
{
for( int i=; i < leftPad; i++)
{
sb.Append(paddingchar);
}
sb.Append(organName);
}
}
}

上一个HelloWorldController,也是整个程序唯一的controller。

using game1.Models;
using Microsoft.ApplicationInsights;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Encodings.Web; // For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860 namespace game1.Controllers
{
public class HelloWorldController : Controller
{
TelemetryClient tc = new TelemetryClient();
//
// GET: /HelloWorld/ [HttpPost]
public ActionResult Index(string userName, int count)
{
FaceInfo fi = new FaceInfo();
fi.Name = userName;
fi.FaceCount = count;
return RedirectToAction("Welcome",fi);
}
[HttpGet]
public ActionResult Index()
{ return View();
}
public ActionResult About()
{ return View();
}
//
// GET: /HelloWorld/Welcome/ //public string Welcome(string name, int ID = 1)
//{
// tc.TrackEvent("welcome");
// return HtmlEncoder.Default.Encode($"Hello {name}, ID: {ID}");
//}
public ActionResult Welcome(FaceInfo fi)
{
tc.TrackEvent("Generating....");
ViewData["Message"] = "Hello " + fi.Name;
ViewData["FaceCount"] = fi.FaceCount;
List<String> faces = DrawingHelper.Draw(fi.FaceCount).Select(t => t.ToString()).ToList();
return View(faces);
}
}
}

omg~我还有一个model呢~ model好像是实现了在controller里传值。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; namespace game1.Models
{
public class FaceInfo
{
public int FaceCount { get; set; }
public string Name { get; set; }
}
}

Index.cshtml里很简单

俩输入框,一个按钮

@model game1.Models.FaceInfo
@{
ViewData["Title"] = "Index";
} <h2>--------------HELLO--------------</h2>
<hr />
@using (Html.BeginForm())
{
<p>User name:</p>
<input type="text" name="userName" />
<p>Face count:</p>
<input type="text" name="count" />
<p></p>
<input type="submit" value="Try It!"/>
}> <p>Hello to many little faces!</p>

Welcome.cshtml似乎更简单!

@{
ViewData["Title"] = "Welcome";
}
@model List<String>
<h2>Welcome to Winnie's app</h2> <p>This is my first web app.</p> @foreach(var element in Model)
{
<li>@ViewData["Message"]</li>
<pre>@Html.DisplayFor(m=>element)</pre>
}

嗯虽然简单,但是宝宝也忙乎了一天~

【C# 基础应用】我的第一个App,不容易——随机生成小人网站,asp.net core的更多相关文章

  1. 微软Azure配置中心 App Configuration (一):轻松集成到Asp.Net Core

    写在前面 在日常开发中,我这边比较熟悉的配置中心有,携程Apollo,阿里Nacos(配置中心,服务治理一体) 之前文章: Asp.Net Core与携程阿波罗(Apollo)的第一次亲密接触 总体来 ...

  2. 创业成本?亲身经历告诉你做一个app要多少钱

    导语:作为一名苦逼的移动互联网创业者,被外行的朋友们问及最多的问题是“做一个网站需要多少钱?”或者“做一个APP需要多少钱?” 作为一名苦逼的移动互联网创业者,被外行的朋友们问及最多的问题是“做一个网 ...

  3. Windows + IIS 环境部署Asp.Net Core App

    环境:Windows Server 2012, IIS 8, Asp.Net Core 1.1. 不少人第一次在IIS中部署Asp.Net Core App的人都会遇到问题,会发现原来的部署方式无法运 ...

  4. ASP.NET Core 基本项目目录结构 - ASP.NET Core 基础教程 - 简单教程,简单编程

    原文:ASP.NET Core 基本项目目录结构 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 基本项目目录结构 上一章节中我们成功创建了一个名为 Hell ...

  5. 【ASP.NET Core学习】基础

    新建项目时,程序入口调用CreateDefaultBuilder(args),下面是源代码 public static IHostBuilder CreateDefaultBuilder(string ...

  6. ASP.NET Core中app.UseDeveloperExceptionPage和app.UseExceptionHandler方法有什么用

    在新建一个ASP.NET Core项目后,在项目Startup类的Configure方法中默认会添加两个方法的调用,app.UseDeveloperExceptionPage和app.UseExcep ...

  7. 学习ASP.NET Core Blazor编程系列二——第一个Blazor应用程序(下)

    学习ASP.NET Core Blazor编程系列一--综述 学习ASP.NET Core Blazor编程系列二--第一个Blazor应用程序(上) 学习ASP.NET Core Blazor编程系 ...

  8. 学习ASP.NET Core Blazor编程系列二——第一个Blazor应用程序(完)

    学习ASP.NET Core Blazor编程系列一--综述 学习ASP.NET Core Blazor编程系列二--第一个Blazor应用程序(上) 学习ASP.NET Core Blazor编程系 ...

  9. 如何一秒钟从头构建一个 ASP.NET Core 中间件

    前言 其实地上本没有路,走的人多了,也便成了路. -- 鲁迅 就像上面鲁迅说的那样,其实在我们开发中间件的过程中,微软并没有制定一些策略或者文档来约束你如何编写一个中间件程序, 但是其中却存在者一些最 ...

随机推荐

  1. Delphi 操作Flash D7~XE10都有 导入Activex控件 shockwave

    http://www.cnblogs.com/devcjq/articles/2906224.html Flash是Macromedia公司出品的,用在互联网上动态的.可互动的shockwave.它的 ...

  2. zorka源码解读之Beanshell与zorka的交互实现

    一.beanshell基础知识从应用程序中调用BeanShell创建一个BeanShell的解释器(interpreter)用eval()和source()命令可以对一个字符串求值和运行一个脚本文件使 ...

  3. Linux CentOS6.5下安装Oracle ASM

    Oracle版本:Oracle 11g 1.确定自己的Linux版本: [root@localhost ~]#uname -r 2.6.32-431.el6.x86_64 2.6.32-431.el6 ...

  4. PHP+Mysql+easyui点击左侧tree菜单对应表名右侧动态生成datagrid加载表单数据(二)

    关于tree菜单生成,参考我的另一篇博文地址tree 菜单 实现功能:点击左侧tree菜单中的table,右侧通过datagrid加载出该表对用的所有数据 难点:获取该表的所有列名,动态生成datag ...

  5. 【听说是线段树】bzoj1012 [JSOI2008]最大数maxnumber

    一眼看题目吓了一跳:这TM不就是单调队列吗,200000又怎样,大不了我二分嘛 系统提示:成功开启 手残模式 开始瞎写: #include <cstdio> ]; ]; int m,mod ...

  6. [DEMO] 互联网广告RTB机制简介

    前言: 传统的互联网广告一般都是大流量网站在页面中留出一定空位,某些推广商家通过买位的方式来展示自己的广告. 我们这里引入一个案例:假设大访问量网站为博客园,想要广告推广的公司为阿里云平台. (场景为 ...

  7. Web.xml各版本模版

    web.xml v2.3 web.xml v2.4 <?xml version="1.0" encoding="UTF-8"?> <web-a ...

  8. Moneybookers API支付方式开发 步骤

    开发文档: 支付说明手册 步骤: 1.使用商家帐号,登录到www.moneybookers.com,核对商家信息是否正确. 2.在账户-->商家工具(设置) a.API/MQI password ...

  9. 如何Recycle一个SharePoint Web Application,以及为什么

    当你发现SharePoint服务器的CPU或者内存使用率居高不下的时候,很多人都会选择iisreset来让资源使用率降下来.但是在企业环境中,这毫无疑问会使这台服务器中断服务从而影响到用户的使用,所以 ...

  10. tshark 抓包分析

    一,安装#yum install -y wireshark 二.具体使用案例 1.抓取500个包,提取访问的网址打印出来tshark -s 0 -i eth0 -n -f 'tcp dst port ...