如何在控制台中显示一个变量c#(how to display a variable in console c#)
我正在尝试创建一个简单的控制台游戏,通过喂养自己照顾自己。
using System; namespace Project1 { static class Program { static void Main(string[] args) { int hunger = 100; Console.WriteLine("Enter your name: "); string name = Console.ReadLine(); Console.WriteLine("Good choice, " + name); Console.WriteLine("Press SPACE to continue"); while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Spacebar)) { // do something int h = hunger - 2; } Console.WriteLine("You are hungry," + name); Console.WriteLine("Press F to feed"); while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.F)) { // do something int food = hunger; } } } }
如何在更改之后显示当前的饥饿感? 我想显示食物水平,以便玩家知道喂食它并且不会意外地过度喂它。 任何机会都有办法回到较早的一行,所以我不需要永远地复制和粘贴这个东西吗? 谢谢。
I'm trying to create a simple console game where you take care of yourself by feeding yourself.
using System; namespace Project1 { static class Program { static void Main(string[] args) { int hunger = 100; Console.WriteLine("Enter your name: "); string name = Console.ReadLine(); Console.WriteLine("Good choice, " + name); Console.WriteLine("Press SPACE to continue"); while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Spacebar)) { // do something int h = hunger - 2; } Console.WriteLine("You are hungry," + name); Console.WriteLine("Press F to feed"); while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.F)) { // do something int food = hunger; } } } }
How can I display the current hunger after a change is made too it? I want to display the food level so the player knows to feed it and does not accidentally over feed it. By any chance is there a way to go back to a earlier line so I don't need to copy and paste the thing forever and ever? Thanks.
原文:https://stackoverflow.com/questions/31938279
更新时间:2023-09-11 19:09
最满意答案
CSS
.notification { display: flex; } .push-title { font-size: 1.15rem; } .push-active { margin-left: 20%; color: #8A8A8A; } .btn-active { margin: 0 auto; background: #FF512F; background-image: -webkit-linear-gradient(left top, #FF512F, #DD2476); background-image: -moz-linear-gradient(left top, #FF512F, #DD2476); background-image: -ms-linear-gradient(bottom right, #FF512F, #DD2476); background-image: -o-linear-gradient(bottom right, #FF512F, #DD2476); background-image: linear-gradient(bottom right, #FF512F, #DD2476); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 60px; padding: 1px 24px 1px 24px; text-decoration: none; color:white; height:30px; font-size:60px; line-height:28px; }
HTML
<div class="notification"> <div class="push-title">Push Notifications</div> <div class="push-active">Active</div> <a href="" class="btn-active">•</a> </div>
css
.notification { display: flex; } .push-title { font-size: 1.15rem; } .push-active { margin-left: 20%; color: #8A8A8A; } .btn-active { margin: 0 auto; background: #FF512F; background-image: -webkit-linear-gradient(left top, #FF512F, #DD2476); background-image: -moz-linear-gradient(left top, #FF512F, #DD2476); background-image: -ms-linear-gradient(bottom right, #FF512F, #DD2476); background-image: -o-linear-gradient(bottom right, #FF512F, #DD2476); background-image: linear-gradient(bottom right, #FF512F, #DD2476); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 60px; padding: 1px 24px 1px 24px; text-decoration: none; color:white; height:30px; font-size:60px; line-height:28px; }
HTML
<div class="notification"> <div class="push-title">Push Notifications</div> <div class="push-active">Active</div> <a href="" class="btn-active">•</a> </div>
相关问答
更多-
Unicode - 正确的做法(Unicode - the right thing to do)[2023-07-10]
最常见的方法是在输入不正确并停止时抛出有意义的错误。 有很多很好的理由这样做: 速度:如果您尝试修复错误,这通常会导致您的功能即使在正确的输入上也会变慢 简单:如果您尝试修复任何错误,您的代码可能会变得非常复杂 可维护性和正确性:只要输入与您正在使用的规范不匹配,当您停止时,更容易确保函数正常工作。 因为您只需要根据规格检查输入。 目的:任何时候你到达这样一个点,你必须考虑:我的功能的目的是什么? 为什么我想出了写它的想法? 另外:修复uft8的功能修复代码也可以在其他地方使用,因此将修复(目的,简单性,可 ... -
使用填充..这应该做的伎俩 Use Padding .. That should do the trick“山”是因为font-size高于实际按钮。 如果删除文本,你会发现山已经消失了。 要解决此问题,您只需添加overflow: hidden以确保文本不会剪切按钮。 button { letter-spacing: 2px; padding-top: .4em; padding-bottom: .8em; line-height: 0; font-weight: 800; background: black; border: 0; color: red; ...
Unicode Cookie值(Unicode Cookie Value)[2023-09-17]
从技术上讲,cookie值的内容是不透明的,可以是服务器想要的任何内容,甚至是二进制数据,只要生成的HTTP标头遵循HTTP规范的规则即可。 按照惯例,大多数服务器编码非ASCII数据,通常使用URL编码(非ASCII字节表示为“%XX”,其中XX是字节的十六进制值)。 Technically speaking, the content of the cookie value is opaque and can be anything the server wants, even binary data, ...当鼠标悬停在按钮上时,您需要在渲染时应用ScaleTransform 。 风格触发器是一种方法来做到这一点: