Add Live Web Page To Scratch
Scratch is a free programming language and online community where you can create your own interactive stories, games, and animations. Scratch - Imagine, Program, Share Create.
- Add Live Web Page To Scratch Free
- Add Web Page To Favorites
- Add Live Web Page To Scratch On Facebook
- Add Live Web Page To Scratch Online
- Live Web Page In Powerpoint
Adobe Acrobat Creative Suite 5 can capture web content such as news stories or business information and turn it into a PDF file. You can convert a single web page or a whole web site. If you want to convert only a single page and are using Internet Explorer, click the Convert Web Page to. Dec 13, 2017 On top of migrating to using this as our web client, Scratch is also transitioning into using a new API backend, Scratch REST API (closed-source). As that is also currently in development and incomplete, we are set up to fall back to using existing Scratch endpoints if an API endpoint does not exist – which is where the FALLBACK comes in. Sep 19, 2011 Create a Live Web Page from Scratch in Seconds, via Email. Is almost certainly the quickest way to create a web page and get it online. Post a simple text message. Jan 02, 2020 How to Create a Simple Web Page with HTML. This wikiHow teaches you how to write a simple web page with HTML (hypertext markup language). HTML is one of the core components of the World Wide Web, making up the structure of web pages.
-->by Tom FitzMacken
For new web application development, we recommend Razor Pages. For more information, see Get started with Razor Pages.
Note
WebMatrix is no longer recommended as an integrated development environment for ASP.NET Web Pages. Use Visual Studio or Visual Studio Code.
This guidance and application gives you an overview of ASP.NET Web Pages (version 2 or later) and Razor syntax, a lightweight framework for creating dynamic websites. It also introduces WebMatrix, a tool for creating pages and sites.
Level: New to ASP.NET Web Pages.
Skills assumed: HTML, basic cascading style sheets (CSS).
What you'll learn in the first tutorial of the set:
- What ASP.NET Web Pages technology is and what it's for.
- What WebMatrix is.
- How to install everything.
- How to create a website by using WebMatrix.
Features/technologies discussed:
- Microsoft Web Platform Installer.
- WebMatrix.
- .cshtml pages
Mike Pope originally wrote this tutorial. Tom FitzMacken updated it for Microsoft WebMatrix 3.
Software versions used in the tutorial
- ASP.NET Web Pages (Razor) 2
- WebMatrix 3
What Should You Know?

We're assuming that you're familiar with:
- HTML. No in-depth expertise is required. We won't explain HTML, but we also don't use anything complex. We'll provide links to HTML tutorials where we think they're useful.
- Cascading style sheets (CSS). Same as with HTML.
- Basic database ideas. If you've used a spreadsheet for data and sorted and filtered the data, that's the level of expertise we're generally assuming for this tutorial set.
We're also assuming that you're interested in learning basic programming. ASP.NET Web Pages use a programming language called C#. You don't have to have any background in programming, just an interest in it. If you've ever written any JavaScript in a web page before, you've got plenty of background.
Note that if you are familiar with programming, you might find that this tutorial set initially moves slowly while we bring new programmers up to speed. As we get past the first few tutorials, though, there will be less basic programming to explain and things will move along at a faster clip.
What Do You Need?
Here's what you'll need:
- A computer that is running Windows 8, Windows 7, Windows Server 2008, or Windows Server 2012.
- A live internet connection.
- Administrator privileges (required for the installation process).
What Is ASP.NET Web Pages?
ASP.NET Web Pages is a framework that you can use to create dynamic web pages. A simple HTML web page is static; its content is determined by the fixed HTML markup that's in the page. Dynamic pages like those you create with ASP.NET Web Pages let you create the page content on the fly, by using code.
Dynamic pages let you do all sorts of things. You can ask a user for input by using a form and then change what the page displays or how it looks. You can take information from a user, save it in a database, and then list it later. You can send email from your site. You can interact with other services on the web (for example, a mapping service) and produce pages that integrate information from those sources.
What is WebMatrix?
WebMatrix is a tool that integrates a web page editor, a database utility, a web server for testing pages, and features for publishing your website to the Internet. WebMatrix is free, and it's easy to install and easy to use. (It also works for just plain HTML pages, as well as for other technologies like PHP.)
You don't actually have to use WebMatrix to work with ASP.NET Web Pages. You can create pages by using a text editor, for example, and test pages by using a web server that you have access to. However, WebMatrix makes it all very easy, so these tutorials will use WebMatrix throughout.
About These Tutorials
This tutorial set is an introduction to how to use ASP.NET Web Pages. There are 9 tutorials total in this introductory tutorial set. It's part of a series of tutorial sets that takes you from ASP.NET Web Pages novice to creating real, professional-looking websites.
This first tutorial set concentrates on showing you the basics of how to work with ASP.NET Web Pages. When you're done, you can work with additional tutorial sets that pick up where this one ends and that explore Web Pages in more depth.
We deliberately go easy on the in-depth explanations. And whenever we show something, for this tutorial set we always choose the way that we think is easiest to understand. Later tutorial sets go into more depth and show you more efficient or more flexible approaches (also more fun). But those tutorials require you to understand the basics first.
The tutorial set you've just started covers these features of ASP.NET Web Pages:
- Introduction and getting everything installed. (That's in the tutorial you're reading.)
- The basics of ASP.NET Web Pages programming.
- Creating a database.
- Creating and processing a user input form.
- Adding, updating, and deleting data in the database.
What Will You Create?
This tutorial set and subsequent ones revolve around a website where you can list movies that you like. You'll be able to enter movies, edit them, and list them. Here are a couple of the pages you'll create in this tutorial set. The first one shows the movie listing page that you'll create:
And here's the page that lets you add new movie information to your site:
Subsequent tutorial sets build on this set and add more functionality, like uploading pictures, letting people log in, sending email, and integrating with social media.
See this App Running on Azure
Would you like to see the finished site running as a live web app? You can deploy a complete version of the app to your Azure account by simply clicking the following button.
You need an Azure account to deploy this solution to Azure. If you do not already have an account, you have the following options:
- Open an Azure account for free - You get credits you can use to try out paid Azure services, and even after they're used up you can keep the account and use free Azure services.
- Activate MSDN subscriber benefits - Your MSDN subscription gives you credits every month that you can use for paid Azure services.
Installing Everything
You can install everything by using the Web Platform Installer from Microsoft. In effect, you install the installer, and then use it to install everything else.
To use Web Pages, you have to be have at least Windows XP with SP3 installed, or Windows Server 2008 or later.
On the Web Pages page of the ASP.NET website, click Install.
You are asked to accept the license terms and privacy statement before installing WebMatrix.
Click Run to start the installation. (If you want to save the installer, click Save and then run the installer from the folder where you saved it.)
The Web Platform Installer appears, ready to install WebMatrix. Click Install.
The installation process figures out what it has to install on your computer and starts the process. Depending on what exactly has to be installed, the process can take anywhere from a few moments to several minutes. Select I Accept to accept the license terms.
Hello, WebMatrix
When it's done, the installation process can launch WebMatrix automatically. If it doesn't, in Windows, from the Start menu, launch Microsoft WebMatrix.
When you launch WebMatrix for the first time, you are given a chance to sign in to Microsoft Azure with your Microsoft account. By signing in, you will receive 10 free web apps through Azure. These free web apps provide a convenient way to test your apps. If you don't already have an Azure account, but you do have an MSDN subscription, you can activate your MSDN subscription benefits. Otherwise, you can create a free trial account in just a couple of minutes. For details, see Azure Free Trial.
You do not have to sign in right now to continue with this tutorial. If you do not sign in now, you will still have the option to sign in later. The last topic in this tutorial series covers how to deploy your website to Azure; therefore, you would need to sign in to complete that topic.
Add Live Web Page To Scratch Free
At this point, either sign in with your Microsoft account or select Not Now in the lower right corner.
To begin, you'll create a blank website and add a page. In a later tutorial in this set you'll play with one of the built-in website templates.
In the start window, click New.
Templates are prebuilt files and pages for different types of websites. To see all of the templates that are available by default, select the Template Gallery option.
In the Quick Start window, select Empty Site from the ASP.NET group and name the new site 'WebPagesMovies'.
Click Next.
If you have signed in to your Microsoft account, you will be given the opportunity to create the site on Azure. Based on the name of your site, the default name of WebPagesMovies.azurewebsites.net is suggested; however, the exclamation point indicates that this name is not available on Windows Azure. For simplicity, select Skip to bypass creating the web site on Azure right now. Later in this series, we will publish the site to Azure.
WebMatrix creates and opens the site:
At the top, there's a Quick Access Toolbar and a ribbon. At the bottom left, you see the workspace selector where you switch between tasks (Site, Files, Databases, Reports). On the right is the content pane for the editor and for reports. And across the bottom you'll occasionally see a notification bar for messages.
You'll learn more about WebMatrix and its features as you go through these tutorials.
Creating a Web Page
To become familiar with WebMatrix and ASP.NET Web Pages, you'll create a simple page.
In the workspace selector, select the Files workspace. This workspace lets you work with files and folders. The left pane shows the file structure of your site. The ribbon changes to show file-related tasks.
In the ribbon, click the arrow under New and then click New File.
WebMatrix displays a list of file types. Select CSHTML, and in the Name box, type 'HelloWorld'. A CSHTML page is an ASP.NET Web Pages page.
Click OK.
WebMatrix creates the page and opens it in the editor.
As you can see, the page contains mostly ordinary HTML markup, except for a block at the top that looks like this:
That's for adding code, as you'll see shortly.
Notice that the different parts of the page — the element names, attributes, and text, plus the block at the top — are all in different colors. This is called syntax highlighting, and it makes it easier to keep everything clear. It's one of the features that makes it easy to work with web pages in WebMatrix.
Add content for the <head>
and <body>
elements like in the following example. (If you want, you can just copy the following block and replace the entire existing page with this code.)
In the Quick Access Toolbar or in the File menu, click Save.
Testing the Page
In the Files workspace, right-click the HelloWorld.cshtml page and then click Launch in browser.
WebMatrix starts a built-in web server (IIS Express) that you can use to test pages on your computer. (Without IIS Express in WebMatrix, you'd have to publish your page to a web server somewhere before you could test it.) The page is displayed in your default browser.
Notice that when you test a page in WebMatrix, the URL in the browser is something like http://localhost:33651/HelloWorld.cshtml.
The name localhost refers to a local server, meaning that the page is served by a web server that's on your own computer. As noted, WebMatrix includes a web server program named IIS Express that runs when you launch a page.
The number after localhost (for example, localhost:33651) refers to a port number on your computer. This is the number of the 'channel' that IIS Express uses for this particular website. The port number is selected at random from the range 1024 through 65536 when you create your site, and it's different for every site that you create. (When you test your own site, the port number will almost certainly be a different number than 33561.) By using a different port for each website, IIS Express can keep straight which of your sites it's talking to.
Later when you publish your site to a public web server, you no longer see localhost in the URL. At that point, you'll see a more typical URL like http://myhostingsite/mywebsite/HelloWorld.cshtml
or whatever the page is. You'll learn more about publishing a site later in this tutorial series.
Adding Some Server-Side Code
Close the browser and go back to the page in WebMatrix.
Add a line to the code block so that it looks like the following code:
This is a little bit of Razor code. It's probably clear that it gets the current date and time and puts that value into a variable named currentDateTime
. You'll read more about Razor syntax in the next tutorial.
In the body of the page, after the <p>Hello World!</p>
element, add the following:
This code gets the value that you put into the currentDateTime
variable at the top and inserts it into the markup of the page. The @
character marks the ASP.NET Web Pages code in the page.
Run the page again (WebMatrix saves the changes for you before it runs the page). This time you see the date and time in the page.
Wait a few moments and then refresh the page in the browser. The date and time display is updated.
In the browser, look at the page source. It looks like the following markup:
Notice that the @{ }
block at the top isn't there. Also notice that the date and time display shows an actual string of characters (1/18/2012 2:49:50 PM
or whatever), not @currentDateTime
like you had in the .cshtml page. What happened here is that when you ran the page, ASP.NET processed all the code (very little in this case) that was marked with @
. The code produces output, and that output was inserted into the page.
This Is What ASP.NET Web Pages Are About
When you read that ASP.NET Web Pages produces dynamic web content, what you've seen here is the idea. The page you just created contains the same HTML markup that you've seen before. It can also contain code that can perform all sorts of tasks. In this example, it did the trivial task of getting the current date and time. As you saw, you can intersperse code with the HTML to produce output in the page. When someone requests a .cshtml page in the browser, ASP.NET processes the page while it's still in the hands of the web server. ASP.NET inserts the output of the code (if any) into the page as HTML. When the code processing is done, ASP.NET sends the resulting page to the browser. All the browser ever gets is HTML. Here's a diagram:
The idea is simple, but there are many interesting tasks that the code can perform, and there are many interesting ways in which you can dynamically add HTML content to the page. And ASP.NET .cshtml pages, like any HTML page, can also include code that runs in the browser itself (JavaScript and jQuery code). You'll explore all of these things in this tutorial set and in subsequent ones.
Coming Up Next
In the next tutorial in this series, you explore ASP.NET Web Pages programming a little more.
Additional Resources
Create an ASP.NET website from scratch. This is a tutorial that's specifically about using WebMatrix (not ASP.NET Web Pages). It goes into a little more detail about some of the additional features of WebMatrix that we won't cover in this tutorial set.
-->Build a Hosted Web App for the Microsoft Store with popular fullstack web technologies
This two-part tutorial provides a quick tour of modern fullstack web development as you build a simple memory game that works both in the browser and as a Hosted Web App for the Microsoft Store. In Part I you'll build a simple REST API service for the game's backend. By hosting the game logic in the cloud as an API service, you preserve the game state so your user can keep playing their same game instance across different devices. In Part II you'll build the front-end UI as a single-page web app with responsive layout.
We'll be using some of the most popular web technologies, including the Node.js runtime and Express for server-side development, the Bootstrap UI framework, the Pug template engine, and Swagger for building RESTful APIs. You'll also gain experience with the Azure Portal for cloud hosting and working with the Visual Studio Code editor.
Prerequisites
Add Web Page To Favorites
If you don't already have these resources on your machine, follow these download links:
Node.js - Be sure to select the option to add Node to your PATH.
Express generator- After you install Node, install Express by running
npm install express-generator -g
If you want to complete the final steps of hosting your API service and memory game app on Microsoft Azure, you'll need to create a free Azure account if you haven't already done so.
If you decide to bail on (or postpone) the Azure part, simply skip the final sections of parts I and II, which cover Azure hosting and packaging your app for the Microsoft Store. The API service and web app you build will still run locally (from http://localhost:8000
and http://localhost:3000
, respectively) on your machine.
Part I: Build a REST API backend
We'll first build a simple memory game API to power our memory game web app. We'll use Swagger to define our API and generate scaffolding code and a web UI for manual testing.
If you'd like to skip this part and move straight to Part II: Build a single-page web application, here's the finished code for Part I. Follow the README instructions to get the code up and running locally, or see 5. Host your API service on Azure and enable CORS to run it from Azure.
Game overview
Memory (also known as Concentration and Pelmanism), is a simple game consisting of a deck of card pairs. The cards are placed face-down on the table, and the player inspects the card values, two at a time, looking for matches. After each turn the cards are again placed face-down, unless a matching pair is found, in which case those two cards are cleared from the game. The game objective is to find all card pairs in the fewest amount of turns.
For instructional purposes, the game structure we'll use is very simple: it's single game, single player. However, the game logic is server-side (rather than on the client) to preserve the game state, so that you could keep playing the same game across different devices.
The data structure for a memory game consists simply of an array of JavaScript objects, each representing a single card, with indices in the array acting as card IDs. On the server, each card object has a value and a cleared flag. For example, a board of 2-matches (4 cards) might be randomly generated and serialized like this.
When the board array is passed to the client, value keys are removed from the array to prevent cheating (for example, inspecting the HTTP response body by using F12 browser tools). Here's how that same new game would look to a client calling the GET /game REST endpoint:
Speaking of endpoints, the memory game service will consist of three REST APIs.
POST /new
Initializes a new game board of the specified size (# of matches).
Parameter | Description |
---|---|
int size | Number of matching pairs to be shuffled into the game 'board'. Example: http://memorygameapisample/new?size=2 |
Response | Description |
---|---|
200 OK | New memory game of requested size is ready. |
400 BAD REQUEST | Requested size is outside of acceptable range. |
GET /game
Retrieves the current state of the memory game board.
No parameters
Response | Description |
---|---|
200 OK | Returns JSON array of card objects. Each card has a cleared property indicating whether its match has already been found. Matched cards also report their value. Example: [{'cleared':'false'},{'cleared':'false'},{'cleared':'true','value':1},{'cleared':'true','value':1}] |
PUT /guess
Specifies a card to reveal and checks for a match to the previously revealed card.
Parameter | Description |
---|---|
int card | Card ID (index in game board array) of the card to reveal. Each complete 'guess' consists of two specified cards (i.e., two calls to /guess with valid and unique card values). Example: http://memorygameapisample/guess?card=0 |
Response | Description |
---|---|
200 OK | Returns JSON with the id and value of the specified card. Example: [{'id':0,'value':1}] |
400 BAD REQUEST | Error with the specified card. See HTTP response body for further details. |
1. Spec out the API and generate code stubs
We'll use Swagger to transform the design of our memory game API into working Node.js server code. Here's how you might define our memory game APIs as Swagger metadata. We'll use this to generate server code stubs.
Create a new folder (in your local GitHub directory, for example), and download the api.json file containing our memory game API definitions. Make sure your folder name doesn't contain any spaces.
Open your favorite shell (or use Visual Studio Code's integrated terminal!) to that folder and run the following Node Package Manager (NPM) command to install the Yeoman (yo) code-scaffolding tool and Swagger generator for your global (-g) Node environment:
Now we can generate the server scaffolding code by using Swagger:
The swaggerize command will ask you several questions.
- Path (or URL) to swagger document: api.json
- Framework: express
- What would you like to call this project (YourFolderNameHere): [enter]
Answer everything else as you like; the information is mostly to supply the package.json file with your contact info so you can distribute your code as an NPM package.
Finally, install all the dependencies (listed in package.json) for your new project and Swagger UI support.
Now start VS Code and File > Open Folder.., and move to the MemoryGameAPI directory. This is the Node.js API server you just created! It uses the popular ExpressJS web application framework to structure and run your project.
2. Customize the server code and setup debugging
The server.js file in your project root acts as the 'main' function of your server. Open it in VS Code and copy the following into it. The lines modified from the generated code are commented with further explanation.
With that, it's time to run your server! Let's set up Visual Studio Code for Node debugging while we're at it. Select on the Debug panel icon (Ctrl+Shift+D) and then the gear icon (Open launch.json), and modify 'configurations' to this:
Now press F5 and open your browser to https://localhost:8000. The page should open to the Swagger UI for our memory game API, and from there you can expand the details and input fields for each of the methods. You can even try calling the APIs, although their responses will contain only mocked-up data (provided by the Swagmock module). It's time to add our game logic to make these APIs real.
3. Set up your route handlers
The Swagger file (configswagger.json) instructs our server how to handle various client HTTP requests by mapping each URL path it defines to a handler file (in handlers), and each method defined for that path (for example, GET, POST) to an operationId
(function) within that handler file.
In this layer of our program we'll add some input checking before passing the various client requests to our data model. Download (or copy and paste):
- This game.js code to your handlersgame.js file
- This guess.js code to your handlersguess.js file
- This new.js code to your handlersnew.js file
You can skim the comments in those files for more details about the changes, but in essence they check for basic input errors (for example, the client requests a new game with less than one match) and send descriptive error messages as needed. The handlers also route valid client requests through to their corresponding data files (in data) for further processing. Let's work on those next.
4. Set up your data model
It's time to swap out the placeholder the deck for a new game, identifying pairs of matched cards, and keeping track of game state. Copy and paste:
- This game.js code to your datagame.js file
- This guess.js code to your dataguess.js file
- This new.js code to your datanew.js file
For simplicity, we're storing our game board in a global variable (global.board
) on our Node server. But realistically you'd use cloud storage (like Google Cloud Datastore or Azure DocumentDB) to make this into a viable memory-game API service that concurrently supports multiple games and players.
Make sure you've saved all the changes in VS Code, fire up your server again (F5 in VS Code or npm start
from shell, and then browse to https://localhost:8000) to test out the game API.
Each time you press the Try it out! button on one of the /game, /guess, or /new operations, check the resulting Response Body and Response Code below to verify that everything's working as expected.
Try:
Creating a new
size=2
game.Guessing a couple of values.
Checking the game board as the game progresses.
If everything looks good, your API service is ready to host on Azure! If you're running into problems, try commenting out the following lines in datagame.js.
With this change, the GET /game method will return all the card values (including the ones that haven't been cleared). This is a useful debug hack to keep in place as you build the front-end for the memory game.
5. (Optional) Host your API service on Azure and enable CORS
Add Live Web Page To Scratch On Facebook
The Azure docs will walk you through:
Add Live Web Page To Scratch Online
- Setting up Git deployment for your API app, and
When registering your app, try to differentiate your App name (to avoid naming collisions with others requesting variations on the http://memorygameapi.azurewebsites.net URL).
If you've made it this far and Azure is now serving up your swagger UI, there's just one final step to the memory game backend. From Azure Portal, select your newly created App Service and then select or search for the CORS (Cross-Origin Resource Sharing) option. Under Allowed Origins, add an asterisk (*
) and click Save. This lets you make cross-origin calls to your API service from your memory-game front-end as you develop it on your local machine. Once you finalize the memory-game front-end and deploy that to Azure, you can replace this entry with the specific URL of your web app.
Going further
To make the memory game API a viable back-end service for a production app, you'll want to extend the code to support multiple players and games. For that you'll probably need to plumb in authentication (for managing player identities), a NoSQL database (for tracking games and players), and some basic unit testing for your API.
Here are some useful resources for going further:
Live Web Page In Powerpoint
Part II: Build a single-page web application
Now that you've built (or downloaded) the REST API backend from Part I, you're ready to create the single-page memory game front-end with Node, Express, and Bootstrap.
Part II of this tutorial will give you experience with:
- Node.js: to create the server hosting your game
- jQuery: a JavaScript library
- Express: for the web application framework
- Pug: (formerly Jade) for the templating engine
- Bootstrap: for the responsive layout
- Visual Studio Code: for code authoring, markdown viewing, and debugging
1. Create a Node.js application by using Express
Let's start by creating the Node.js project using Express.
Open a command prompt and navigate to the directory where you want to store your game.
Use the Express generator to create a new application called memory using the templating engine, Pug.
In the memory directory, install the dependencies listed in the package.json file. The package.json file is created in the root of your project. This file contains the modules that are required for your Node.js app.
This information ensures that your free Apple Loops will contain transient points, key and tempo references and other data within the file itself. / Archive by category Drums Archive by category DrumsClick on the links below to choose the style of drum loops that you need. All of our free Garageband drum loops are free for personal use. How to play the drums on garageband mac. Each file that we offer is a free Apple Loop which has been specially formatted to work with Garageband.You can load all of our free Garageband loops by dragging and dropping the file from your local folder directly into the loop browser within the Garageband application.Apple loops are specially formatted AIF files which contain meta data.
After running this command, you should see a folder called node_modules that contains all of the modules needed for this app.
Now, run your application.
View your application by going to https://localhost:3000/.
Change the default title of your web app by editing index.js in the memoryroutes directory. Change
Express
in the line below toMemory Game
(or another title of your choosing).To refresh the app to see your new title, stop your app by pressing Crtl + C, Y in the command prompt, and then restart it with
npm start
.
2. Add client-side game logic code
You can find the files you need for this half of the tutorial in the Start folder. If you get lost, the finished code is available in the Final folder.
Copy the scripts.js file inside of the Start folder and paste it in memorypublicjavascripts. This file contains all the game logic needed to run the game, including:
- Creating/starting a new game.
- Restoring a game stored on the server.
- Drawing the game board and cards based on user selection.
- Flipping the cards.
In script.js, let's start by modifying the
newGame()
function. This function:Jul 14, 2010 While connecting from my workplace (windows environment) to my home (mac environment), Teamviewer connects and even allows file transfer, but displays only black screen (cant see mac desktop). This baffles me and I have tried tweaking all settings but nothing works. If I connect from my workplace (windows) to a Windows at home it just works. The unique tool for remote control of distant computers TeamViewer supports many operational environments, among which are Windows Phone, iOS, Android, Linux, and, of course, Windows and Mac OS X. Using the tool, you may connect remotely to the computer based on Mac OS system from the machine, where Windows is installed, and vice versa. Can teamviewer work between mac and windows. TeamViewer is designed to let you seamlessly access a Mac remotely from all kinds of devices including Linux, Windows and OS X remote desktops, so you can enjoy uninterrupted working. Re: controlling a mac from pc. Yes, install TeamViewer on both and log into your Contacts and Computers and you should be able to control each from the other. If my post was helpful, Please throw me a Kudos. If my post fixed your issue, please mark it as. Feb 16, 2017 Teamviewer doesn't work most of the time. I had limited success using it between PC's running Windows. Between Windows and Mac. 100% failure rate after about five minutes. Perhaps the Mac is in sleep mode? I can see the login screen, but cannot input data. Why would it show the login screen? 100% failure rate. Current version of TV, paid for.
- Handles the size of the game selection from the user.
- Fetches the gameboard array from the server.
- Calls the
drawGameBoard()
function to place the game board to the screen.
Add the following code inside of
newGame()
after the// Add code from Part 2.2 here
comment.This code retrieves the value from the dropdown menu with
id='selectGameSize'
(which we will create later) and stores it in a variable (size
). We use theparseInt()
function to parse the string value from the dropdown to return an integer, so we can pass thesize
of the requested game board to the server.We use the
/new
method created in Part I of this tutorial to post the chosen size of the game board to the server. The method returns a single JSON array of cards andtrue/false
values indicating whether the cards have been matched.Next, fill in the
restoreGame()
function that restores the last game played. For simplicity's sake, the app always loads the last game played. If there is not a game stored on the server, use the drop-down menu to start a new game.Copy and paste this code into
restoreGame()
.The game will now fetch the game state from the server. For more information about the
/game
method being used in this step, see Part I of this tutorial. If you are using Azure (or another service) to host the backend API, replace the localhost address above with your production URL.Now we want to create the
drawGameBoard()
function. This function:- Detects the size of the game and applies specific CSS styles.
- Generates the cards in HTML.
- Adds the cards to the page.
Copy and paste this code into the
drawGameBoard()
function in scripts.js:Next, we need to complete the
flipCard()
function. This function handles the majority of the game logic, including getting the values of the selected cards from the server by using the/guess
method developed in Part I of the tutorial. Don't forget to replace the localhost address with your production URL if you are cloud hosting the REST API backend.In the
flipCard()
function, uncomment this code:
Tip
If you're using Visual Studio Code, select all the lines of code you wish to uncomment, and press Crtl + K, U
Here we use jQuery.ajax()
and the PUT/guess
method created in Part I.
This code executes in the following order.
- The
id
of the first card the user selected is added as the first value to the selectedCards[] array:selectedCards[0]
- The value (
id
) inselectedCards[0]
is posted to the server using the/guess
method - The server responds with the
value
of that card (an integer) - A Bootstrap glyphicon is added to the back of the card whose
id
isselectedCards[0]
- The first card's
value
(from the server) is stored in theselectedCardsValues[]
array:selectedCardsValues[0]
.
The user's second guess follows the same logic. If the cards that the user selected have the same IDs, (for example, selectedCards[0] selectedCards[1]
), the cards are a match! The CSS class .matched
is added to the matched cards (turning them green) and the cards remained flipped.
Now we need to add logic to check whether the user matched all of the cards and won the game. Inside of the flipCard()
function, add the following lines of code under the //check if the user won the game
comment.
If the number of cards flipped matches the size of the game board (for example, cardsFlipped gameBoardSize
), there are no more cards to flip and the user has won the game. We'll add some simple HTML to the div
with id='game-board'
to let the user know they won and can play again.
3. Create the user interface
Now let's see all this code in action by creating the user interface. In this tutorial, we use the templating engine Pug (formally Jade). Pug is clean, whitespace-sensitive syntax for writing HTML. Here's an example.
becomes
Replace the layout.pug file in memoryviews with the provided layout.pug file in the Start folder. Inside of layout.pug, you'll see links to:
- Bootstrap
- jQuery
- A custom CSS file
- The JavaScript file we just finished modifying
Open the file named index.pug in the directory memoryviews.This file extends the layout.pug file and will render our game. Inside of layout.pug, paste the following lines of code:
Tip
Remember: Pug is whitespace sensitive. Make sure all of your indentations are correct!
4. Use Bootstrap's grid system to create a responsive layout
Bootstrap's grid system is a fluid grid system that scales a grid as a device's viewport changes. The cards in this game use Bootstrap's predefined grid system classes for the layout, including:
.container-fluid
: specifies the fluid container for the grid.row-fluid
: specifies the fluid rows.col-xs-3
: specifies the number of columns
Bootstrap's grid system allows a grid system to collapse into one vertical column, like you would see on a navigation menu on a mobile device. However, because we want our game always to have columns, we use the predefined class .col-xs-3
, which keeps the grid horizontal at all times.
The grid system allows up to 12 columns. Since we only want 4 columns in our game, we use the class .col-xs-3
. This class specifies that we need each of our columns to span the width of 3 of the 12 available columns mentioned before. This image shows a 12-column grid and a 4-column grid, like the one used in this game.
Open scripts.js and find the
drawGameBoard()
function. In the block of code where we generate the HTML for each card, can you spot thediv
element withclass='col-xs-3'
?Inside of index.pug, let's add the predefined Bootstrap classes mentioned previously to create our fluid layout. Change index.pug to the following.
5. Add a card-flip animation with CSS Transforms
Replace the style.css file in memorypublicstylesheets with the style.css file from the Start folder.
Adding a flip motion using CSS Transforms gives the cards a realistic, 3D flipping motion. The cards in the game are created by using the following HTML structure and programmatically added to the game board (in the drawGameBoard()
function shown previously).
To start, give perspective to the parent container of the animation (
.flipContainer
). This gives the illusion of depth for its child elements: the higher the value, the farther away from the user the element will appear. Let's add the following perspective to the.flipContainer
class in style.css.Now add the following properties to the
.cards
class in style.css. The.cards
div
is the element that will actually be doing the flipping animation, showing either the front or the back of the card.The
transform-style
property establishes a 3D-rendering context, and the children of the.cards
class (.front
and.back
are members of the 3D space. Adding thetransition-duration
property specifies the number of seconds for the animation to finish.Using the
transform
property, we can rotate the card around the Y-axis. Add the following CSS tocards.flip
.The style defined in
cards.flip
is toggled on and off in theflipCard
function by using.toggleClass()
.Now when a user clicks on a card, the card is rotated 180 degrees.
6. Test and play
Congratulations! You've finished creating the web app! Let's test it.
Open a command prompt in your memory directory and enter the following command:
npm start
In your browser, go to https://localhost:3000/ and play a game!
If you encounter any errors, you can use Visual Studio Code's Node.js debugging tools by pressing F5 on your keyboard and typing
Node.js
. For more information about debugging in Visual Studio Code, check out this article.You can also compare your code to the code provided in the Final folder.
To stop the game, in the command prompt type: Ctrl + C, Y.
Going further
You can now deploy your app to Azure (or any other cloud hosting service) for testing across different device form factors, such as mobile, tablet, and desktop. (Don't forgot to test across different browsers too!) Once your app is ready for production, you can easily package it as a Hosted Web App (HWA) for the Universal Windows Platform (UWP) and distribute it from the Microsoft Store.
The basic steps for publishing to the Microsoft Store are:
- Create a Windows Developer account
- Use the app submission checklist
- Submit your app for certification
Here are some useful resources for going further: