Challenge: Tic-Tac-Toe (Report a problem) Detecting mouse clicks For this step of the challenge you will complete Tile's handleMouseClick method. The handleMouseClick method has two parameters: x and y which represent the coordinates of where the user clicked the mouse. When a user clicks inside a tile, that tile's handleMouseClick method should call that tile's onClick method. To check if the mouse click is inside of the tile, you will need an if statement that checks if: - the mouse click is on, or right of, the left edge of the tile - the mouse click is on, or left of, the right edge of the tile - the mouse click is on, or below, the upper edge of the tile - the mouse click is on, or above, the lower edge of the tile

Answers

Answer 1
Answer:

Answer:

var playerTurn;

var NUM_COLS;

var NUM_ROWS;

var SYMBOLS;

var tiles = [];

var checkWin = function()

{    };

var Tile = function(x, y)

{

 this.x = x;

 this.y = y;

 this.size = width/NUM_COLS;

 this.label = "";

};

Tile.prototype.draw = function()

{

   fill(214, 247, 202);

   strokeWeight(2);

   rect(this.x, this.y, this.size, this.size, 10);

   textSize(100);

   textAlign(CENTER, CENTER);

   fill(0, 0, 0);

   text(this.label, this.x+this.size/2, this.y+this.size/2);

};

Tile.prototype.empty = function()

{

   return this.label === "";

};

Tile.prototype.onClick = function()

{

   // If the tile is not empty, exit the function

   // Put the player's symbol on the tile

   // Change the turn

};

Tile.prototype.handleMouseClick = function(x, y)

{

   // Check for mouse clicks inside the tile

};

for (var i = 0; i < NUM_COLS; i++)

{

   for (var j = 0; j < NUM_ROWS; j++)

  {

       tiles.push(new Tile(i * (width/NUM_COLS-1), j * (height/NUM_ROWS-1)));

   }

}

var drawTiles = function()

{

   for (var i in tiles)

  {

       tiles[i].draw();

   }

};

mouseReleased = function()

  {

   for (var i in tiles)

       {

       tiles[i].handleMouseClick(mouseX, mouseY);

       }

 };

draw = function()

{

   background(143, 143, 143);

   drawTiles();

};

Explanation:


Related Questions

Develop a program that asks the user to enter a capital for a U.S. state. Upon receiving the user input, the program reports whether the user input is correct. For this application, the 50 states and their capitals are stored in a two-dimensional array in order by state name. Display the current contents of the array then use a bubble sort to sort the content by capital. Next, prompt the user to enter answers for all the state capitals and then display the total correct count. The user's answer is not case-sensitive.
Is the willingness to put a customer’s needs above ones own needs and to go beyond a job description to achieve customer satisfaction
The Clean Air Act Amendments of 1990 prohibit service-related releases of all ____________. A) GasB) OzoneC) MercuryD) Refrigerants
Factory Design Pattern Assignment This assignment will give you practice in using the Factory/Abstract Factory Design Pattern. You are going to create a Terraforming program. What does terraform mean
Given an array A of n + m elements. It is know that the first n elements in A are sorted and the last m elements in A are unsorted. Suggest an algorithm (only pseudo code) to sort A in O(mlogm +n) worst case running time complexity. Justify.

Write a simple arithmetic expression translator that reads in expressions such as 25.5 + 34.2 and displays their value. Each expression has two numbers separated by an arithmetic operator. (Hint: Use a switch statement with the operator symbol (type char) as a selector to determine which arithmetic operation to perform on the two numbers. For a sentinel, enter an expression with zero for both operands.)

Answers

Answer:

Following are the program in the C++ Programming Language.

//header file

#include<iostream>

//header file

#include <bits/stdc++.h>

//namespace

using namespace std;

//set main function

int main()

{

//set float type variables

float a,s,m,d,c,b,g;

//print message and get variable from the user

cout<<" Enter The First Number : ";

cin>>c;

//print message and get variable from the user

cout<<" Enter The Second Number: ";

cin>>b;

again:

//get variable from the user for Operation

cout<<" Enter the Operation which you want : ";

char choice;

cin>>choice;

//Addition

a=c+b;

//Subtraction

s=c-b;

//Multiplication

m=c*b;

//Division

d=c/b;

//Modulus

g=fmod(c, b);

//set switch statement

//here is the solution

 switch(choice)

 {

   case '+':  

     cout<<"Addition: "<<a<<endl;

     goto again;

     break;

   case '-':

     cout<<"Subtraction: "<<s<<endl;

     goto again;

     break;

   case '*':

     cout<<"Multiplication: "<<m<<endl;

     goto again;

     break;

   case '/':

     cout<<"Division: "<<d<<endl;

     goto again;

     break;

   case '%':

     cout<<"Modulus: "<<g<<endl;

     goto again;

     break;

   default:

     cout<<"Exit";

     break;

 }

return 0;

}Explanation:

Here, we define the required header files then, we set main function.

  • set float type variables a,s,m,d,c,b,g.
  • Get input from the user for operation in the variable c,d.
  • Set character type variables in which we get input from the user for operations.
  • Then, we perform some operations.
  • Set switch statement which display the output according to the user an if user input wrong then statement breaks.

The utilization of a subset of the performance equation as a performance metric is a pitfall. To illustrate this, assume the following two processors. P1 has a clock rate of 4 GHz, average CPI of 0.9, and requires the execution of 5.0E9 instructions. P2 has a clock rate of 3 GHz, an average CPI of 0.75, and requi res the execution of 1.0E9 instructions. One usual fallacy is to consider the computer with the largest clock rate as having the largest performance. Check if this is true for P1 and P2.

Answers

Answer:

Given Data:

Clock rate of P1 = 4 GHz

Clock rate of P2 = 3 GHz

Average CPI of P1 = 0.9

Number of Instructions = 5.0E9 =  5 × 10^9

Clock rate of P2 = 3 GHz

Average CPI of P2 = 0.75

Number of Instructions = 1.0E9 = 10^9

To find: If the computer with largest clock rate has the largest performance?

Explanation:

Solution:

As given in the question, clock rate of P1 = 4 GHz which is greater than clock rate of P2 = 3 GHz

According to the performance equation:

CPU Time = instruction count * average cycles per instruction/ clock rate

CPU Time = I * CPI / clock rate

Where instruction count refers to the number of instructions.

Performance of P1:

CPU Time (P1) = 5 * 10^9 * 0.9 / (4 * 10^9)

                        = 5000000000 * 0.9 / 4000000000

                        = 4500000000 / 4000000000

                        =  1.125s

Performance of P2:

CPU Time (P2) = 10^9 * 0.75/ (3 * 10^9)

                        = 750000000 / 3000000000

                        = 0.25s

So the Performance of P2 is larger than that of P1,

                          performance (P2) > performance (P1)

                                         0.25 is better than 1.125

But clock rate of P1 was larger than P2

                             clock rate of P1 > clock rate of P2

                                                  4 GHz > 3 GHz

So this is a misconception about P1 and P2.

It is not true that computer with the largest clock rate as having the largest performance.

File Letter Counter Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program.

Answers

Answer:

The solution code is written in Python.

  1. fileName = input("Enter file name: ")
  2. target = input("Enter target character: ")
  3. with open(fileName, "r")as reader:
  4.    content = reader.read()
  5.    print(content.count(target))

Explanation:

Firstly, use input() function to prompt user for a file name. (Line 1)

Next, we use input() function again to prompt user input a target character (Line 2)

Create a reader object and user read() method to copy entire texts from to the variable content (Line 4 - 5).

At last we can get the number of times the specified character appears in the file using the Python string built-in method count() (Line 6)

A web page that allows interaction from the user​

Answers

Answer:

Its A Dynamic Web Page

Explanation:

Assign True to the variable has_dups if the string s1 has any duplicate character (that is if any character appears more than once) and False otherwise.Here is the answer I wrote:


i = []
for i in range(len([s1])):
if s1.count(s1[i]) > 1:
has_dups = True
elif s1.count(s1[i]) = 1:
has_dups = False


Here is the message I got from the system:

Solutions with your approach don't usually use: elif



Please Help me to correct it.

Answers

i dont know the language of the code
probably you have sintacs mistakes in it

has_dups = false
for i in range(len([s1])):
has_dups = has_dups || s1.count(s1[i]) > 1

Which of the following can be used to record the behavior of classes?A) Javadoc comments

B) Nouns and verbs in the problem description

C) Polymorphism

D) UML notation

Answers

Answer:

A) Javadoc comments

Explanation:

It is used for documenting the java source code in HTML and java code documentation. The difference between multi-line comment and javadoc is that ,javadoc uses extra asterisk, For example-

/**

* This is a Javadoc

*/

It is used to record the behavior of classes.There are various tags used in this like @author,{@code},@exception and many more.