WIN10 UWP Business Games

Source: Internet
Author: User
Tags creative commons attribution

This article tells you to do a business game, the game is very simple, almost no technology

The beginning of the game, you need to add a frame library, so reference my own writing library.

The first is to create a startup page, which is displayed on the Start screen.

When the display starts, is the need to load the game needs to use the resources, if you feel the need to control the progress bar, you need to use the injection method to give him the current progress, but I do not do here, so it is very simple code to start the page.

The startup page is still empty, but it doesn't matter.

Then start to write a welcome page, that is, start the game, continue, help and so on the page, temporarily do not do.

But written so much, do not need to write a code in MainPage, now it is in the MainPage
Start writing code, then the code is to add a Frame as a jump, and a menu. Of course the menu doesn't have anything yet, just need to add it here.

Look, now you have created two pages. One is the start page and one is the Welcome page.

Then start to play the main page of the game, please note that when writing, a page is a corresponding view. You can see that when you write, you don't need to go through the logic between the two pages. Of course it's impossible to control now.

You can know that the main page of the game needs to have warehouses, shops to buy things, places to buy things and factories.

Then you need to think about how the game is played.

Because this game is what I saw yesterday to buy the food the person said, I want to do one.

First, there are many items, and you can turn low-level items into advanced items through the factory.

Items include

种子小米麦面面包番薯矿石铁铜木头石矿碳煤锄头椅子桌子雕刻刀大刀弓箭

If you have any other items to think about, please let me know. But before you finish, please don't tell me quickly, you want to add those items, please tell me what you like after you know how the game is played.

Items include the current price and the market price, where the current price is constant and the market price fluctuates between 80% and 120%.

Start by saying how the game shop sells things, the store that the game uses to buy things through the market, and then buy things for someone to buy things. Shops can have a lot of, of course, now only one. The store is reputable, the number of visitors to the store is not fixed, and the store's location and store reputation. If a place is a lot of people then the people who come to the store will be a lot. If the store is reputable, there are a lot of people coming to the store.

A person who buys something tells the store what he is buying, the quantity, the price he wants to buy. The price to buy is market price, the market price always changes, need to decide whether to buy at each time.

So the store's input button now has one, the next time, that is, whether there is a person to buy things come over, whether decide to buy things from the market.

So click on the button, you can get the current how many buy things come over, after processing the market to buy things.

People who buy things come over and say what he needs to buy now, and of course the game does not immediately appear high-level people to buy bigger things. The person who comes to buy things is graded, that is, how much money he has, so according to the money he can now buy how many things.

If the store exists something he can buy, such as the store now has something

种子 2小米 10麦   10面   2

He wants to buy something

种子 1小米 2麦   3

So you can just buy, and the customer gives you a full score, because the store he wants can buy everything he wants. So the store plus credibility 1.

A person always brings credibility is this calculation, he wants the commodity price can get a few

 var s = 买东西人买东西加起来的所有价值  var a = 商店提供商品总价格 带来信誉 = 2 * a / s - 1

If you can only meet the needs of the purchase of the person half, then will not bring any credit promotion.

So at the click of the next time, it began to calculate how many people buy things, how much money they have, so the need for items this class gives the probability that he can be changed, through his money can be calculated. So the items need to be the attributes can be obtained, the name of the goods, items need how much money, the total amount of goods. Now the total amount of items can not be counted.

People who come to buy things have these attributes, all the money, the level. To buy something. The level is how much credit the store has to attract the person who buys the item, which is written here as a list

But start with a simple program and then add more versatility.

Interface

The interface of the game is very important, but I will write a simple interface. I first give the interface, can see this interface is very simple, is a list and some buttons

There is a problem with the list, how to do the table, the actual I have no way, so I used the following code

                <listview grid.row= "1" itemssource= "{x:bind view.propertystorage}" Selectedite                        M= "{Binding carlopiperisaacproperty,mode=twoway}" > <FrameworkElement.Resources> <style targettype= "TextBlock" > <setter property= "HorizontalAlignment" value= "                    Center ></Setter> </Style> </FrameworkElement.Resources>                            <ListView.ItemContainerStyle> <style targettype= "ListViewItem" >                        <setter property= "horizontalcontentalignment" value= "Stretch" ></Setter>                        </Style> </ListView.ItemContainerStyle> <ListView.Header>                                <Grid> <Grid.ColumnDefinitions> <columndefinition WiDth= "30*" ></ColumnDefinition> <columndefinition width= "15*" ></columndefin                                ition> <columndefinition width= "15*" ></ColumnDefinition> <columndefinition width= "15*" ></ColumnDefinition> </grid.columndefin itions> <textblock text= "name" ></TextBlock> <textblo CK grid.column= "1" text= "price" ></TextBlock> <textblock grid.column= "2" text= "Warehouse owned"                        ;</textblock> <textblock grid.column= "3" text= "Bid Money" ></TextBlock>                        </Grid> </ListView.Header> <ListView.ItemTemplate>                                <datatemplate x:datatype= "View:property" > <Grid> <grid.columndefinitions> <columndefinition width= "30*" ></ColumnDefinition>                                    <columndefinition width= "15*" ></ColumnDefinition> <columndefinition width= "15*" ></ColumnDefinition> <columndefini                                tion width= "15*" ></ColumnDefinition> </Grid.ColumnDefinitions> <FrameworkElement.Resources> <style targettype= "TextBlock" &G                                        T <setter property= "HorizontalAlignment" value= "Center" ></Setter> </style&                                Gt </FrameworkElement.Resources> <textblock text= "{x:bind Name}" ></textblock&gt                                ; <textblock grid.column= "1" text= "{x:bind Price,mode=oneway} "></TextBlock> <textblock grid.column=" 2 "text=" {X:bi nd num,mode=oneway} "></TextBlock> <textblock grid.column=" 3 "text=" {x:bind ASHL Ilyvergeraldo,mode=oneway} "></TextBlock> </Grid> </dat Atemplate> </ListView.ItemTemplate> </ListView>

The above code so that the list does not compress the width, so you need to use Itemcontainerstyle, see the code

                 <ListView.ItemContainerStyle>                        <Style TargetType="ListViewItem">                            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>                        </Style>                    </ListView.ItemContainerStyle>

To make the list all the text is centered, do not want to write to each text, but the text outside the list is not centered, so modify the text in the list of the center can use the following code

                 <FrameworkElement.Resources>                                    <Style TargetType="TextBlock">                                        <Setter Property="HorizontalAlignment" Value="Center"></Setter>                                    </Style>                                </FrameworkElement.Resources>

This will center the text in the list, and the text outside the list will not be centered.

If you use X:bind in the list then you need to use DataType to tell the type of the binding, so what type of data is required, otherwise it will fail. So I need to define the data before I write the list, so let me tell you about the data that the game needs.

Then need to start binding, but then found that the game needs the data is very simple, temporarily I do not continue to write code, if you need code, see varietyhiggstgushed

Add icon

As you can see, there is no icon on the top of the screen and it doesn't look good, so you need to add some icons to it. Icon can be downloaded to http://www.iconfont.cn/, here to download the need to pay attention to copyright issues, but I have this in the download time to see, as if it does not need to pay.

First put the picture in the Assest folder, and then you can set it up.

            <Grid> <stackpanel orientation= "Horizontal" horizontalalign Ment= "Right" > <FrameworkElement.Resources> <style targettype= "Stackp                        Anel "> <setter property=" Margin "value=" 10,10,10,10 "></Setter> </Style> </FrameworkElement.Resources> <stackpanel orientation= "Horizontal" > <image source= "ms-appx:///assets/-day. png" height= "width="-></image&gt                        ; <textblock text= "Days" ></TextBlock> <textblock text= "{x:bind View.pinkieduchesnegerald O,mode=oneway} "></TextBlock> </StackPanel> <stackpanel Orientation = "Horizontal" > <image source= "ms-appx:///assets/warehouse. png" height= "width=" (></image)> <textblock text= "Warehouse capacity" ></TextBlock> <textblock text= "{x:                        Bind View.jwstorage.transit,mode=oneway} "/> <textblock text="/"></TextBlock>                    <textblock text= "{x:bind view.jwstorage.transitstorage,mode=oneway}" ></TextBlock> </StackPanel> <stackpanel orientation= "Horizontal" > <textb Lock text= "Money" ></TextBlock> <textblock text= "{x:bind View.jwstorage.transtorageprice,mo De=oneway} "></TextBlock> </StackPanel> </StackPanel> &lt ;/grid>

You can see the way the picture is written, the value of Source is used ms-appx , here is obtained from the resource, if you want to know how this code is to write, I have a blog win10 UWP access solution file inside to tell everyone how to write.

Note that you need to set the size of the picture, you can run the program, and then start the settings so that the interface can see the changes, but you need to save to see.

Can see the original code is varietyhiggstgushed buy things the interface looks bad

Here you need to modify this, modify it to a good-looking

You can use Contentdialog to pop up a nice-looking interface

So how to do this interface, the simple way is to do a user control, the interface of the control is very simple, but the background needs to write some properties, this property is the current buy, buy the maximum value, corresponding to sell.

So the background code for this interface is a few properties, and the properties are updated when setting ViewModel

  Public sealed partial class Jediahpage:usercontrol {public Jediahpage () {this.        InitializeComponent ();            } public Storagemodel ViewModel {get {return _viewmodel;}                set {_viewmodel = value;                                                           Max can buy Newlansheehybrunasharon = (int) Math.floor (_viewmodel.jwstorage.transtorageprice/                _viewmodel.carlopiperisaacproperty.price);                var sresidue = _viewmodel.jwstorage.transitstorage-_viewmodel.jwstorage.transit; Newlansheehybrunasharon = Newlansheehybrunasharon > sresidue?                Sresidue:newlansheehybrunasharon;            Aimeelansheehybrunasharon = _viewmodel.carlopiperisaacproperty.num; }} public static readonly DependencyProperty Newlansheehybrunasharonnumproperty = dependencyproperty.regist ER ("Newlansheehybrunasharonnum", typeof (int), typeof (Jediahpage), new PropertyMetadata (default (int)));  public int Newlansheehybrunasharonnum {get {return (int) GetValue (newlansheehybrunasharonnumproperty);        } set {SetValue (Newlansheehybrunasharonnumproperty, value);}            } public static readonly DependencyProperty Newlansheehybrunasharonproperty = Dependencyproperty.register (        "Newlansheehybrunasharon", typeof (int), typeof (Jediahpage), new PropertyMetadata (default (int)));            public int Newlansheehybrunasharon {get {return (int) GetValue (newlansheehybrunasharonproperty);}        set {SetValue (Newlansheehybrunasharonproperty, value);}            } public static readonly DependencyProperty Aimeelansheehybrunasharonnumproperty = Dependencyproperty.register (        "Aimeelansheehybrunasharonnum", typeof (int), typeof (Jediahpage), new PropertyMetadata (default (int))); public int Aimeelansheehybrunasharonnum {get {R}Eturn (int) GetValue (aimeelansheehybrunasharonnumproperty);        } set {SetValue (Aimeelansheehybrunasharonnumproperty, value);}            } public static readonly DependencyProperty Aimeelansheehybrunasharonproperty = Dependencyproperty.register (        "Aimeelansheehybrunasharon", typeof (int), typeof (Jediahpage), new PropertyMetadata (default (int)));        Private Storagemodel _viewmodel;             public int Aimeelansheehybrunasharon {get {return (int) GetValue (aimeelansheehybrunasharonproperty);}        set {SetValue (Aimeelansheehybrunasharonproperty, value);}        } public event EventHandler Close; private void Newlansheehy (object sender, RoutedEventArgs e) {Viewmodel.lansheehybrunasharon = Newlanshe            Ehybrunasharonnum;            Viewmodel.newlansheehybrunasharon (); Close?.        Invoke (this, null); private void Aimeelansheehy (object sender, RoutedEventArgs e) {ViewModel.            Lansheehybrunasharon = Aimeelansheehybrunasharonnum;            Viewmodel.aimeelansheehybrunasharon (); Close?.        Invoke (this, null); private void Mnewbruna (object sender, RoutedEventArgs e) {newlansheehybrunasharonnum = Newlans        Heehybrunasharon; private void Maimeebruna (object sender, RoutedEventArgs e) {aimeelansheehybrunasharonnum = Aim        Eelansheehybrunasharon; } private void Closebutton_onclick (object sender, RoutedEventArgs e) {Close?.        Invoke (this, null); }    }

The

Interface code is simple

    <grid > <grid margin= "10,10,10,10" > <Grid.RowDefinitions> <rowde            Finition height= "Auto"/> <rowdefinition height= "64*"/> </Grid.RowDefinitions> <Grid> <button fontfamily= "Segoe MDL2 Assets" content= "& #xE10A;"            Horizontalalignment= "Right" click= "Closebutton_onclick" > </Button>                </Grid> <grid grid.row= "1" horizontalalignment= "center" verticalalignment= "Center" >                         <Grid> <Grid.RowDefinitions> <rowdefinition height= "64*"/>                         <rowdefinition height= "Auto"/> <rowdefinition height= "Auto"/>                    <rowdefinition height= "100*"/> </Grid.RowDefinitions>                        <Grid><textblock text= "{x:bind ViewModel.CarloPiperIsaacProperty.Name}" ></TextBlock> </grid&gt                    ; <grid grid.row= "1" > <stackpanel orientation= "Horizontal" > &L T;image source= "ms-appx:///assets/warehouse. png" height= "" width= "></Image> <textbloc K text= "Warehouse owned:" ></TextBlock> <textblock text= "{x:bind viewmodel.carlopiperisaacprope Rty.                    Num} "></TextBlock> </StackPanel> </Grid>                            <grid width= "grid.row=" 2 "> <stackpanel orientation=" Horizontal "> <textblock text= "$" ></TextBlock> <textblock text= "Buy price" &GT;&LT;/TEXTB Lock> <textblock text= "{x:bind viewmodel.carlopiperisaacproperty.ashlilyvergeraldo,conveRter={staticresource Converdoublestr}} "></TextBlock> </StackPanel>                            <stackpanel orientation= "Horizontal" horizontalalignment= "right" > <textblock text= "$" ></TextBlock> <textblock text= "Market price" >&lt ;/textblock> <textblock text= "{x:bind ViewModel.CarloPiperIsaacProperty.Price}" ></t extblock> </StackPanel> </Grid> <grid Grid. row= "3" > <Grid.RowDefinitions> <rowdefinition height= "74*"/                        > <rowdefinition height= "85*"/> </Grid.RowDefinitions>                                <Grid> <Grid.ColumnDefinitions> <columndefinition WIdth= "307*"/> <columndefinition width= "Auto"/> </g Rid. columndefinitions> <slider margin= "10,10,10,10" value=                                    "{X:bind Newlansheehybrunasharonnum,mode=twoway,converter={staticresource Resourcekey=convert}}"                            maximum= "{x:bind Newlansheehybrunasharon}" > </Slider> <stackpanel grid.column= "1" orientation= "horizontal" > <button content= "Max" C lick= "Mnewbruna" ></Button> <button content= "buy" click= "Newlansheehy" ></bu tton> </StackPanel> </Grid> <gr ID grid.row= "1" > <Grid.ColumnDefinitions> <columndef Inition width= "59*"/> <columndefinition width= "Auto"/> </grid.columnde  finitions> <slider margin= "10,10,10,10" value= "{X:bind Aimeelansheehybrunasharonnum,mode=twoway,converter={staticresource Convert}} "maximum= "{X:bind Aimeelansheehybrunasharon}" > </Slider> <stackpa Nel grid.column= "1" orientation= "horizontal" > <button content= "Max" click= "Maimeebrun                            A "></Button> <button content=" sell "click=" Aimeelansheehy "></Button>                </StackPanel> </Grid> </Grid> </Grid> </Grid> </Grid> </Grid>

You can see that you need two converters, one is to turn the string to double one is to display a double to keep the decimal after two bits, this implementation is very simple, I will not say. So the next step is to use this interface, see below for the method of use.

            var temp = new JediahPage()            {                ViewModel = View,            };            ContentDialog contentDialog = new ContentDialog()            {                Content = temp,                IsPrimaryButtonEnabled = false,                IsSecondaryButtonEnabled = false,            };            temp.Close += (s, args) => contentDialog.Hide();            await contentDialog.ShowAsync();

The main note is to write the close event before the display, then remove the default button.

Presumably this will work, and the rest of the code is not important, so don't say it. Now I send the game to the Microsoft Store and click Download.

This is the business game 1.0.75, after this release, will continue to develop, but it is not updated in this article.

Here are the related articles

    • WIN10 UWP Business Games

    • WIN10 UWP Business Games 1.1.5

    • WIN10 UWP Business Games 1.2.1

Thank

Walterlv

JAKE

Falling Books きhttps://www.pixiv.net/member_illust.php?mode=medium&illust_id=64830430

Welcome everyone to my blog, now CSDN blog post published on the no longer edit, if you want to see the latest articles, please go to my blog. This article is also sent in the blog Park backup, if you have any suggestions, please comment below the blog.


This work is licensed under the Creative Commons Attribution-NonCommercial use-Share 4.0 International license agreement in the same way. Welcome to reprint, use, republish, but be sure to keep the article Attribution Lindesi (including Link: http://blog.csdn.net/lindexi_gd), not for commercial purposes, based on the modified works of this article must be issued with the same license. If you have any questions, please contact me.

WIN10 UWP Business Games

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.