trooped Programming Golden Dot Game

Source: Internet
Author: User

Problems and solutions in coding process

1. Functions for player input numbers

A total of 10 players, a button corresponding to a function is a bit wasteful, and the function structure is similar, so we started to be a button corresponding to a function prom ()

Define a global variable flag to complete the number of players by self-increment each time the input flag is completed. But there is a problem: the player should be in the normal order

Player1 Enter the Player2 input, and so on. If the user's input is not in order, the player's score cannot be stored sequentially, so a player input button is then taken to

An input function should be applied to ensure the correctness of the storage.

2. Input function error, start coding does not take into account the illegality of the input data, in the test found that if the input does not meet the requirements of the system will not error, so added if judgment

To check if the input is wrong, if there is an error, the function calls itself, re-enter until the input meets the required number.

function Prom0 () {  var number=prompt ("Please enter your num", "") if (number<100 && number>0) {//alert (f lag); Mynum[0]=number;//document.write (Mynum[flag]); alert ("Your number is:" +mynum[0]);} else {alert ("the number entered does not meet the requirements") Prom0 ();}}  

  

2. The player does not enter a number, the system will not error, mynum[] array at initialization does not assign the initial value, so if the player does not enter the data will be garbled, so the Send () function

To determine if there are non-conforming numbers in the mynum[], because the input function comes with the error-checking function, so the number of non-conforming in Send () is not entered by the player.

Alert the I value at this point, prompting the player to enter. The following is the code that implements the error function in the Send () function

function send ()//Calculate G value {for (var i=0;i<10;i++)//Error if (! ( mynum[i]>0&&mynum[i]<100) {alert ("Player_" +i+ "not entered, please retry") return 0;}}

  

3.10 players must first click the "Input End" button after the completion of the input, the results to the JS calculation, and then click "View Results" to see the results of the game

However, if the player clicks the "View Results" button, the game will not be able to see the results, in order to deal with this illegal operation, we set a global variable flag and its initial value

Assigned to 0, after the Send () function (triggered by the input end button), flag becomes 1, and when the "View Results" button is clicked the Trigger function Showres () will be judged if flag==1 instructions

The "Input End" button has been clicked before, this operation is correct, pop-up view results subwindow. If flag==0, this means that you have not clicked the "Input End" button before, you need to

Indicates that this operation is illegal .

function Showres () {if (flag==0) {alert ("Please click" Enter End Button ") return 0; else{$ (' #myModal '). Modal ({backdrop: "static"});}}

  

After the end of the game to restore the value of flag to 0, to ensure that the next round of normal game.

4. After the end of the game, detection of the player has not entered the function is invalid. After discovering the reason, if the player does not enter, the player corresponding to the mynum[] array is saved in the previous round of game input values

So to clear the value of mynum[] at the end of each game to ensure that the next game is done correctly, the res[] array is not processed and used to record the player's total score from the beginning of the game to the present.

function operate () {//Part code for      (var i=0;i<10;i++)      mynum[i]=0;flag=0}

  

function Showg () {alert ("G's value:" +g); for (var i=0;i<10;i++)  mynum[i]=0;flag=0}

Cooperation photos

JS code writing and testing I and Wang Tianning classmates together to complete

The program design process and the server construction please see Wang Tianning's Blog

Http://www.cnblogs.com/wangtianning1223/p/5357294.html

Code has been uploaded to coding

trooped Programming Golden Dot Game

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.